Return TypeFunction nameArguments
hzEcodeSetupHost(void)

Declared in file: hzIpServer.h
Defined in file : hzIpServer.cpp

Function Logic:

0:START 1:gethostname(buf,256) 2:Return E_NODATA 3:_hzGlobal_Hostname nTries 4:nTries<10; 5:gethostbyname pHost 6:pHost 7:h_errno==TRY_AGAIN 8:Return E_NOTFOUND 9:nTries==10 10:Return E_DNS_RETRY 11:memset SvrAddr memcpy inet_ntoa _hzGlobal_HostIP _hzGlobal_livehost 12:Return E_OK

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 ;
}