#include #include /* atoi */ #include /* getpid */ #include #include #include #include #include #include #include #include #ifdef GCC_SGI_BUG /* * gcc compiled from sources (up to gcc 2.95.2) returns always * 255.255.255.255 on SGI/IRIX * * this is a simple workaround */ static char *my_inet_ntoa(struct in_addr add); static char *my_inet_ntoa(struct in_addr in) { static char s[512]; u_long add; add=htonl(in.s_addr); sprintf(s, "%d.%d.%d.%d", (add & 0xff000000)>>24, (add & 0x00ff0000)>>16, (add & 0x0000ff00)>>8, (add & 0x000000ff) ); return s; } #define inet_ntoa my_inet_ntoa #endif int main(int argc, char *argv[]) { struct hostent *hp; u_long add; if (argc!=2) { fprintf( stderr,"uso: %s name\n", argv[0] ); exit(1); } if ( (hp=gethostbyname(argv[1])) == NULL) { perror("gethostbyname: can't get an address"); exit(2); } else { printf("%s\n", inet_ntoa(* (struct in_addr *)(hp->h_addr_list[0]))); } return(0); }