#include #include #include #include #include #include #include #ifndef INADDR_NONE #define INADDR_NONE 0xffffffff #endif int main(int argc, char **argv) { char hostname[256]; struct hostent *he; u_long add; if (gethostname(hostname,sizeof(hostname)) < 0) { perror("gethostname: who am I ?"); exit(1); } if ( (he=gethostbyname(hostname)) == NULL) { perror("gethostbyname: can't get an address"); exit(1); } add=htonl( ((struct in_addr *)(he->h_addr_list[0]))->s_addr ); printf("%d.%d.%d.%d\n", (add & 0xff000000)>>24, (add & 0x00ff0000)>>16, (add & 0x0000ff00)>>8, (add & 0x000000ff) ); return(0); }