| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | SetupHost | (void) |
Declared in file: hzIpServer.h
Defined in file : hzIpServer.cpp
Function Logic:
Function body:
hzEcode SetupHost (void)
{
_hzfunc("SetupHost") ;
struct hostent* pHost ;
struct sockaddr_in SvrAddr ;
uint32_t nTries ;
char buf [256];
if (gethostname(buf, 256))
{
hzerr(E_NODATA, "System call 'gethostname' failed. Cannot establish hostname") ;
return E_NODATA ;
}
_hzGlobal_Hostname = buf ;
for (nTries = 0; nTries < 10;nTries++)
{
pHost = gethostbyname(*_hzGlobal_Hostname) ;
if (pHost)
break ;
if (h_errno == TRY_AGAIN)
continue ;
hzerr(E_NOTFOUND, "Could not lookup the hostname") ;
return E_NOTFOUND ;
}
if (nTries == 10)
{
hzerr(E_DNS_RETRY, "Could not lookup the hostname") ;
return E_DNS_RETRY ;
}
memset(&SvrAddr, 0,sizeof(SvrAddr)) ;
SvrAddr.sin_family = AF_INET ;
memcpy(&SvrAddr.sin_addr, pHost->h_addr, pHost->h_length) ;
_hzGlobal_HostIP = inet_ntoa(SvrAddr.sin_addr) ;
_hzGlobal_livehost = _hzGlobal_HostIP ;
return E_OK ;
}