GetHostByAddr: Populate the supplied string with the servername (hostname) at the supplied IP address. Return the DNS return code.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | GetHostByAddr | (hzString&,const char*,) |
Declared in file: hzDNS.h
Defined in file : hzDNS.cpp
Function Logic:
Function body:
hzEcode GetHostByAddr (hzString& Host)const char* cpIPAddr,
{
// Category: Internet
//
// GetHostByAddr: Populate the supplied string with the servername (hostname) at the supplied IP address. Return the DNS
// return code.
//
// Arguments: 1) Host The Hostname (at the supplied IP address)
// 2) cpIPAddr The IP address
//
// Returns: E_DNS_NOHOST If the host is unknown.
// E_DNS_NODATA If the name is valid but does not have an IP address.
// E_DNS_FAILED If a non-recoverable name server error occurred.
// E_DNS_RETRY If a temporary error occurred on an authoritative name server.
// E_OK If the hostname is found by the DNS
_hzfunc(__func__) ;
HOSTENT* pHost ; // Pointer to host from gethostbyaddr()
in_addr x ; // Internet address translated by inet_addr()
x.s_addr = inet_addr(cpIPAddr) ;
// Unix only: win xlate: pHost = gethostbyaddr(cpIPAddr, 4, AF_INET) ;
pHost = gethostbyaddr(&x, 4,AF_INET) ;
Host.Clear() ;
if (pHost)
{
Host = pHost->h_name ;
return E_OK ;
}
switch (h_errno)
{
case HOST_NOT_FOUND: return E_DNS_NOHOST ; // The host is unknown.
case NO_DATA: return E_DNS_NODATA ; // The name is valid but does not have an IP address.
case NO_RECOVERY: return E_DNS_FAILED ; // A non-recoverable name server error occurred.
case TRY_AGAIN: return E_DNS_RETRY ; // A temporary error occurred on an authoritative name server.
}
return E_DNS_FAILED ;
}