dns.c | dns.c | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
int main(int argc, char **argv) | int main(int argc, char **argv) | |||
{ | { | |||
int i; | int i; | |||
char host[SZ_LINE]; | char host[SZ_LINE]; | |||
struct hostent *hostent; | struct hostent *hostent; | |||
if( argc > 1 ) | if( argc > 1 ) | |||
strcpy(host, argv[1]); | strcpy(host, argv[1]); | |||
else{ | else{ | |||
fprintf(stderr, "getting host name ...\n"); | fprintf(stderr, "calling gethostname() ...\n"); | |||
gethostname(host, SZ_LINE); | if( gethostname(host, SZ_LINE) == -1 ){ | |||
fprintf(stderr, "host name is %s\n", host); | perror("gethostname"); | |||
exit(1); | ||||
} | ||||
else{ | ||||
fprintf(stderr, "host name is %s\n", host); | ||||
} | ||||
} | ||||
fprintf(stderr, "calling gethostbyname(host) ...\n"); | ||||
if( !(hostent = gethostbyname(host)) ){ | ||||
perror("gethostbyname"); | ||||
exit(1); | ||||
} | ||||
else{ | ||||
fprintf(stderr, "gethostbyname() succeeded\n"); | ||||
} | } | |||
fprintf(stderr, "getting host by name ...\n"); | fprintf(stderr, "printing ip address(es) for this host ...\n"); | |||
hostent = gethostbyname(host); | ||||
fprintf(stderr, "printing ip addresses for this host\n"); | ||||
if( hostent ){ | if( hostent ){ | |||
for(i=0; hostent->h_addr_list[i]; i++){ | for(i=0; hostent->h_addr_list[i]; i++){ | |||
fprintf(stderr, "%x\n", *(int *)hostent->h_addr_list[i]); | fprintf(stderr, "%x\n", *(int *)hostent->h_addr_list[i]); | |||
} | } | |||
} | } | |||
else{ | else{ | |||
fprintf(stderr, "ERROR: can't look up: %s\n", host); | fprintf(stderr, "ERROR: can't look up: %s\n", host); | |||
} | } | |||
return(0); | return(0); | |||
} | } | |||
End of changes. 2 change blocks. | ||||
6 lines changed or deleted | 17 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |