ServerCore/IPAddress.cpp
2019-02-22 19:48:25 -08:00

51 lines
1.2 KiB
C++

#include "IPAddress.h"
namespace core {
IPAddress::IPAddress() {
addressLength = sizeof(struct sockaddr_in);
pointer = (sockaddr *)&address;
}
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, short int port) {
struct sockaddr_in addr;
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);
}
IPAddress::~IPAddress() {
}
std::string IPAddress::getClientAddress() {
std::string result;
return result;
}
std::string IPAddress::getClientAddressAndPort() {
std::stringstream out;
out << inet_ntoa(address.sin_addr);
out << ":" << address.sin_port;
return out.str();
}
int IPAddress::getClientPort() {
int result = -1;
return result;
}
}