UNIX retrieves and prints a DNS host entry

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.