|
|
@ -50,23 +50,20 @@ plNetAddress::plNetAddress() |
|
|
|
Clear(); |
|
|
|
Clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plNetAddress::plNetAddress(uint32_t addr, uint16_t port) |
|
|
|
plNetAddress::plNetAddress(uint32_t addr, int port) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
Clear(); |
|
|
|
Clear(); |
|
|
|
SetHost(addr); |
|
|
|
SetHost(addr); |
|
|
|
SetPort(port); |
|
|
|
SetPort(port); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plNetAddress::plNetAddress(const char * addr, uint16_t port) |
|
|
|
plNetAddress::plNetAddress(const char * addr, int port) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
Clear(); |
|
|
|
Clear(); |
|
|
|
SetHost(addr); |
|
|
|
SetHost(addr); |
|
|
|
SetPort(port); |
|
|
|
SetPort(port); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool plNetAddress::SetAnyAddr() |
|
|
|
bool plNetAddress::SetAnyAddr() |
|
|
|
{ |
|
|
|
{ |
|
|
|
fAddr.sin_family = AF_INET; |
|
|
|
fAddr.sin_family = AF_INET; |
|
|
@ -74,7 +71,6 @@ bool plNetAddress::SetAnyAddr() |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool plNetAddress::SetAnyPort() |
|
|
|
bool plNetAddress::SetAnyPort() |
|
|
|
{ |
|
|
|
{ |
|
|
|
fAddr.sin_family = AF_INET; |
|
|
|
fAddr.sin_family = AF_INET; |
|
|
@ -82,15 +78,13 @@ bool plNetAddress::SetAnyPort() |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool plNetAddress::SetPort(uint16_t port) |
|
|
|
bool plNetAddress::SetPort(int port) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
fAddr.sin_family = AF_INET; |
|
|
|
fAddr.sin_family = AF_INET; |
|
|
|
fAddr.sin_port = htons(port); |
|
|
|
fAddr.sin_port = htons(port); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void plNetAddress::Clear() |
|
|
|
void plNetAddress::Clear() |
|
|
|
{ |
|
|
|
{ |
|
|
|
memset(&fAddr,0,sizeof(fAddr)); |
|
|
|
memset(&fAddr,0,sizeof(fAddr)); |
|
|
@ -98,16 +92,14 @@ void plNetAddress::Clear() |
|
|
|
fAddr.sin_addr.s_addr = INADDR_ANY; |
|
|
|
fAddr.sin_addr.s_addr = INADDR_ANY; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t plNetAddress::GetPort() const |
|
|
|
int plNetAddress::GetPort() const |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
return ntohs(fAddr.sin_port); |
|
|
|
return ntohs(fAddr.sin_port); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plString plNetAddress::GetHostString() const |
|
|
|
std::string plNetAddress::GetHostString() const
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
return std::string(pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr)); |
|
|
|
return pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t plNetAddress::GetHost() const |
|
|
|
uint32_t plNetAddress::GetHost() const |
|
|
@ -115,16 +107,13 @@ uint32_t plNetAddress::GetHost() const |
|
|
|
return fAddr.sin_addr.s_addr; |
|
|
|
return fAddr.sin_addr.s_addr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plString plNetAddress::GetHostWithPort() const |
|
|
|
std::string plNetAddress::GetHostWithPort() const
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
static const int buf_len = 1024; |
|
|
|
plStringStream ss; |
|
|
|
char buf[buf_len]; |
|
|
|
ss << pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr) << ":" << GetPort(); |
|
|
|
sprintf(buf,"%s:%d",pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr),GetPort()); |
|
|
|
return ss.GetString(); |
|
|
|
return std::string(buf); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool plNetAddress::SetHost(const char* hostname) |
|
|
|
bool plNetAddress::SetHost(const char* hostname) |
|
|
|
{ |
|
|
|
{ |
|
|
|
fAddr.sin_addr.s_addr = pnNetCommon::GetBinAddr(hostname); |
|
|
|
fAddr.sin_addr.s_addr = pnNetCommon::GetBinAddr(hostname); |
|
|
@ -139,13 +128,14 @@ bool plNetAddress::SetHost(uint32_t addr) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string plNetAddress::AsString() const |
|
|
|
plString plNetAddress::AsString() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
char buf[100] = ""; |
|
|
|
plStringStream ss; |
|
|
|
sprintf(buf,"IP:%s:%d",pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr),GetPort()); |
|
|
|
ss << "IP:" << pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr); |
|
|
|
return std::string(buf); |
|
|
|
ss << ":" << GetPort(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ss.GetString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void plNetAddress::Read(hsStream * s) |
|
|
|
void plNetAddress::Read(hsStream * s) |
|
|
|
{ |
|
|
|
{ |
|
|
|