53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
#include <socket/hostent.hpp>
|
|
|
|
WORD HostEnt::hostByName(const String &hostName)
|
|
{
|
|
struct hostent *lpHostEnt;
|
|
|
|
if(0==(lpHostEnt=::gethostbyname((LPSTR)hostName)))return FALSE;
|
|
if(AddressTypeInternet!=(AddressType)lpHostEnt->h_addrtype)return FALSE;
|
|
pureName(lpHostEnt->h_name);
|
|
pureAliases(lpHostEnt->h_aliases);
|
|
pureAddressType(lpHostEnt->h_addrtype);
|
|
pureLength(lpHostEnt->h_length);
|
|
pureAddressList(lpHostEnt->h_addr_list);
|
|
return TRUE;
|
|
}
|
|
|
|
WORD HostEnt::hostByAddress(const InternetAddress &hostAddress)
|
|
{
|
|
struct hostent *lpHostEnt=0;
|
|
|
|
try{lpHostEnt=::gethostbyaddr((char*)&((in_addr&)hostAddress),sizeof(in_addr),AddressTypeInternet);}
|
|
catch(...){return FALSE;}
|
|
if(!lpHostEnt)return FALSE;
|
|
// if(0==(lpHostEnt=::gethostbyaddr((char*)&((in_addr&)hostAddress),sizeof(in_addr),AddressTypeInternet)))return FALSE;
|
|
pureName(lpHostEnt->h_name);
|
|
// pureAliases(lpHostEnt->h_aliases);
|
|
pureAddressType(lpHostEnt->h_addrtype);
|
|
pureLength(lpHostEnt->h_length);
|
|
pureAddressList(lpHostEnt->h_addr_list);
|
|
return TRUE;
|
|
}
|
|
|
|
void HostEnt::pureAliases(char **lpPureAliases)
|
|
{
|
|
mAliasNames.remove();
|
|
if(!lpPureAliases)return;
|
|
while(*(lpPureAliases))
|
|
{
|
|
mAliasNames.insert(&String(*lpPureAliases));
|
|
lpPureAliases++;
|
|
}
|
|
}
|
|
|
|
void HostEnt::pureAddressList(char **lpPureAddressList)
|
|
{
|
|
struct in_addr *lpInAddr;
|
|
mAddressList.remove();
|
|
while(0!=(lpInAddr=(struct in_addr*)*lpPureAddressList++))
|
|
mAddressList.insert(&InternetAddress(*lpInAddr));
|
|
}
|
|
|
|
|