分类:
2006-10-04 18:55:40
#include #include int main(int argc,char ** argv) { struct in_addr inaddr; /*addr in network byte order*/ unsigned int addr; /*addr in host byte order*/ if(argc != 2) { fprintf(stderr,"Usage: %s exit(0); } if(inet_aton(argv[1],&inaddr) == 0) printf("aton is error!"); addr = ntohl(inaddr.s_addr); printf("0x%x\n",addr); return 0; } |
#include #include int main(int argc,char ** argv) { struct in_addr inaddr; /*addr in network byte order*/ unsigned int addr; /*addr in host byte order*/ if(argc != 2) { fprintf(stderr,"Usage: %s exit(0); } sscanf(argv[1],"%x",&addr); inaddr.s_addr = htonl(addr); printf("%s\n",inet_ntoa(inaddr)); return 0; } |