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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0121tAhQVe4qbCwYgVjKQS4B
This commit is contained in:
barantandClaude Opus 5.5 authored and brad Arant committed 2026-11-02 11:56:49 -08:00
1 parent 4bfede1342
commit 4918654715
1 file changed
+11 -4
+11 -4
View File
@@ -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();
}