From 49186547156af537500a4fbad43530588fb22ff2 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 2 Nov 2026 08:57:22 -0800 Subject: [PATCH] Implement IPAddress::getClientAddress() It was a stub that always returned "", so everything keyed on the client address saw an empty string: SPF checks in BARANTMail were run against no IP at all, Received: headers had no address, and IPAddressList black/white lists could never match. getClientAddressAndPort() also used inet_ntoa() (a static buffer shared across threads) and printed the port in network byte order. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0121tAhQVe4qbCwYgVjKQS4B --- IPAddress.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/IPAddress.cpp b/IPAddress.cpp index 9bdd989..69f81c3 100644 --- a/IPAddress.cpp +++ b/IPAddress.cpp @@ -38,15 +38,22 @@ namespace core { return (sockaddr *)&addr; } + // Was a stub that always returned "" - so everything keyed on the + // client address (SPF checks in BARANTMail, Received: headers, + // IPAddressList black/white lists) silently saw an empty string. std::string IPAddress::getClientAddress() { - std::string result; - return result; + char text[INET_ADDRSTRLEN]; + if (!inet_ntop(AF_INET, &addr.sin_addr, text, sizeof(text))) + return ""; + return text; } std::string IPAddress::getClientAddressAndPort() { std::stringstream out; - out << inet_ntoa(addr.sin_addr); - out << ":" << addr.sin_port; + // inet_ntoa() returns a static buffer shared by every thread, and + // sin_port is in network byte order. + out << getClientAddress(); + out << ":" << ntohs(addr.sin_port); return out.str(); }