/*----------------------------------------------------------------------*\ | test.c | | | | | \*----------------------------------------------------------------------*/ /*-------------------------------< RCS >--------------------------------*/ /*-------------------------< Creation Rules >---------------------------*/ /*-------------------------< Include Files >---------------------------*/ #include #include #include #include #include #include #include /*---------------------------< Definitions >----------------------------*/ /*--------------------------< Declarations >----------------------------*/ /*------------------------< Global Variables >--------------------------*/ /*-------------------------< Local Variables >--------------------------*/ /*----------------------------------------------------------------------*/ int main(int argc, char* argv[]) { char *p,*pHost; int herr=0,n=0; struct hostent *pHe; struct hostent he; struct hostent *rhe; struct in_addr sSrvAddr; struct sockaddr_in *sa; char szSrvAddr[128],pBuffer[4096]; if(argc<2) { printf("Use: %s \n",argv[0]); exit(0); } pHost=argv[1]; if ((pHe=gethostbyname(pHost)) == NULL) { /* get the host info */ perror("gethostbyname"); printf("error determing server name; defined as: %s\n",pHost); exit(-1); } sSrvAddr=*((struct in_addr *)pHe->h_addr); p=inet_ntoa(sSrvAddr); strncpy(szSrvAddr,p,sizeof(szSrvAddr)); printf("gethostbyname: %s=%s\n",pHost,szSrvAddr); n=gethostbyname_r(pHost, &he, pBuffer,4096,&rhe,&herr); if(n!=1) { printf("Error getting address\n"); printf("nss_status: %d herr: %d\n",n,herr); } else { printf("gethostbyname: %s=%st\n",pHost,pBuffer); } return 0; } /* end main() */ /*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/