home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 February
/
CHIP_2_98.iso
/
misc
/
src
/
trees
/
lookup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-30
|
1KB
|
47 lines
/* lookup.c -- print basic DNS information on an Internet host */
#include <netdb.h> /* for gethostby* */
#include <sys/socket.h>
#include <netinet/in.h> /* for address structures */
#include <arpa/inet.h> /* for inet_ntoa() */
#include <stdio.h>
int main(int argc, char ** argv) {
struct hostent * answer;
struct in_addr address, ** addrptr;
char ** next;
if (argc != 2) {
fprintf(stderr, "only a single argument is supported\n");
return 1;
}
if (inet_aton(argv[1], &address))
answer = gethostbyaddr((char *) &address, sizeof(address),
AF_INET);
else
answer = gethostbyname(argv[1]);
if (!answer) {
herror("error looking up host");
return 1;
}
printf("Canonical hostname: %s\n", answer->h_name);
if (answer->h_aliases[0]) {
printf("Aliases:");
for (next = answer->h_aliases; *next; next++)
printf(" %s", *next);
printf("\n");
}
printf("Addresses:");
for (addrptr = (struct in_addr **) answer->h_addr_list;
*addrptr; addrptr++)
printf(" %s", inet_ntoa(**addrptr));
printf("\n");
return 0;
}