#include #include #include #include #include #include #include #ifndef INADDR_NONE # define INADDR_NONE (in_addr_t)-1 #endif int main(int argc, char *argv[]) { struct hostent *hp; u_long add; #if CUTRE int ip[4]; #endif if ( (argc!=2) || (INADDR_NONE == (add = inet_addr(argv[1])))) { fprintf( stderr,"uso: %s ip\n", argv[0] ); exit(1); } #if CUTRE { fprintf( stderr,"uso: %s ip\n", argv[0] ); exit(1); } add = ( (( ip[0] & 0x00ff ) << 24 ) | (( ip[1] & 0x00ff ) << 16 ) | (( ip[2] & 0x00ff ) << 8 ) | ( ip[3] & 0x00ff ) ); printf("%x\n", add); #endif if ( NULL == ( hp = gethostbyaddr((void *)&add, sizeof(add),AF_INET))) { perror("gethostbyaddr: can't get host"); exit(2); } else { puts(hp->h_name); } exit (0); }