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(); }