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
67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
#include "IPAddress.h"
|
|
#include <cstring>
|
|
#include <sstream>
|
|
#include <netdb.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
|
|
namespace core {
|
|
|
|
IPAddress::IPAddress() {
|
|
addressLength = sizeof(addr);
|
|
}
|
|
|
|
IPAddress::IPAddress(std::string address) {
|
|
std::string url = address.substr(0, address.find(":"));
|
|
std::string s_port = address.substr(address.find(":") + 1);
|
|
std::stringstream convert(s_port);
|
|
short int port = 0;
|
|
convert >> port;
|
|
IPAddress(url, port);
|
|
}
|
|
|
|
IPAddress::IPAddress(std::string address, int port) {
|
|
memset(&addr, 0, sizeof(addr));
|
|
addr.sin_family = AF_INET;
|
|
addr.sin_port = htons(port);
|
|
struct hostent *hp = gethostbyname(address.c_str());
|
|
memcpy((void *)&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
|
|
addressLength = sizeof(addr);
|
|
}
|
|
|
|
IPAddress::~IPAddress() {
|
|
|
|
}
|
|
|
|
struct sockaddr * IPAddress::getPointer() {
|
|
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() {
|
|
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;
|
|
// 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();
|
|
}
|
|
|
|
int IPAddress::getClientPort() {
|
|
int result = -1;
|
|
return result;
|
|
}
|
|
|
|
}
|
|
|