#include <stdio.h> #include <stdlib.h> #include <netdb.h> #include <arpa/inet.h>int main (int argc,char *argv[]) {char **pp; /* pointer to a string */struct in_addr addr; /* the structure that stores the IP address */struct hostent * HOSTP;&NBSP;/* Address Structure *//* If the parameter is less than 2, the error */if (argc!=2) {fprintf (stderr, "usage: %s <domain name or dotted-decimal>\n ", argv[0]); exit (0); /* Normal Exit program */}/* if the run parameter is a dotted decimal IP address, it retrieves the address structure based on it; Retrieve address structure based on domain name */if (Inet_aton (argv[1],&addr)!=0) hostp = gethostbyaddr ((const char *) & Addr ,sizeof (addr), af_inet), Elsehostp = gethostbyname (argv[1]);/* Print official domain name */printf ("official Hostname: %s\n ", hostp->h_name);/* alias of the print domain name */for (pp = hostp->h_aliases;*pp!=null;pp++) {printf ("alias: %s\n", *pp);} /* The IP address of the print domain, decimal point form */for (pp = hostp->h_addr_list;*pp!=null;pp++) {addr.s_addr= (struct in_addr *) *pp)->s_addr;printf ("address: %s\n", Inet_ntoa (addr));} /* Program exits normally */exit (0);}
There's a problem with that, when I call two times in a row./hostinfo.o google.com, the IP results returned two times are different. What is this for?
UNIX retrieves and prints a DNS host entry