/* test_ghbn.c */
#include
#include
/* extern int h_errno; */
main(int argc, char *argv[]){
struct hostent *host;
if (argc < 2){
printf("usage: test_ghbn.exe\n");
exit(1);
}
if ((host = gethostbyname(argv[1])) == NULL){
herror("gethostbyname");
}
else{
printf ("addr in hex: 0x%x \n", ntohl(*((unsigned long *)host -> h_addr_list[0])));
}
}
例:
$ ./test_ghbn.exe www.google.co.jp
addr in hex: 0xd8ef3967
$ ./test_ghbn.exe www4.google.com
gethostbyname: Unknown host
$ ./test_ghbn.exe www2.google.co.jp
gethostbyname: No address associated with name
0 件のコメント:
コメントを投稿