ip address fix

This commit is contained in:
Brad Arant 2023-02-07 19:41:16 -08:00
parent a426f435ff
commit 42827ce98e

View File

@ -6,48 +6,48 @@ namespace core {
addressLength = sizeof(addr); addressLength = sizeof(addr);
} }
IPAddress::IPAddress(std::string address) { IPAddress::IPAddress(std::string address) {
std::string url = address.substr(0, address.find(":")); std::string url = address.substr(0, address.find(":"));
std::string s_port = address.substr(address.find(":") + 1); std::string s_port = address.substr(address.find(":") + 1);
std::stringstream convert(s_port); std::stringstream convert(s_port);
short int port = 0; short int port = 0;
convert >> port; convert >> port;
IPAddress(url, port); IPAddress(url, port);
} }
IPAddress::IPAddress(std::string address, int port) { IPAddress::IPAddress(std::string address, int port) {
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons(port); addr.sin_port = htons(port);
struct hostent *hp = gethostbyname(address.c_str()); struct hostent *hp = gethostbyname(address.c_str());
memcpy((void *)&addr.sin_addr, hp->h_addr_list[0], hp->h_length); memcpy((void *)&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
addressLength = sizeof(addr); addressLength = sizeof(addr);
}
IPAddress::~IPAddress() {
} }
struct sockaddr * IPAddress::getPointer() { IPAddress::~IPAddress() {
return (sockaddr *)&addr;
} }
struct sockaddr * IPAddress::getPointer() {
return (sockaddr *)&addr;
}
std::string IPAddress::getClientAddress() { std::string IPAddress::getClientAddress() {
std::string result; std::string result;
return result; return result;
} }
std::string IPAddress::getClientAddressAndPort() { std::string IPAddress::getClientAddressAndPort() {
std::stringstream out; std::stringstream out;
out << inet_ntoa(addr.sin_addr); out << inet_ntoa(addr.sin_addr);
out << ":" << addr.sin_port; out << ":" << addr.sin_port;
return out.str(); return out.str();
} }
int IPAddress::getClientPort() { int IPAddress::getClientPort() {
int result = -1; int result = -1;
return result; return result;
} }
} }