DNS Domain name resolution

Source: Internet
Author: User

1#include <netdb.h>2#include <string.h>3#include <stdio.h>4#include <arpa/inet.h>5 6 intMainintargcChar*argv[])7 {8     Charhost[]="www.baidu.com";9     structHostent *ht=NULL;Tenht=gethostbyname (host);//Note that the gethostbyname function will replace the previous content if it is used multiple times . One     intI=0; A     if(HT) -     { -printf"Get the host:%s\n", host); theprintf"name:%s\n",ht->h_name); -printf"type:%s\n", ht->h_addrtype==af_inet?"af_inet":"Af_inet6"); -printf"length:%d\n",ht->h_length); -          for(i=0;; i++) +         { -             if(ht->h_addr_list[i]!=NULL) +             { Aprintf"ip:%s\n", Inet_ntoa (* (structIN_ADDR *) ht->h_addr_list[i])); /mainly this sentence is more difficult to understand because the INET_NTOA function is dealing with (struct in_addr inaddr) at             } -             Else -             { -                  Break; -             } -         } in          for(i=0;; i++) -         { to             if(ht->h_aliases[i]!=NULL) +             {     -printf"alias%d:%s\n",i,ht->h_aliases[i]); the             } *             Else $             {Panax Notoginseng                  Break; -             } the         } +     } A         return 0; the}

Program Run Result:

1 Get The host:www.baidu.com 2 name:www.a.shifen.com 3 type:af_inet 4 Length:45 IP:115.239. 211.112 6 IP:115.239. 210.27 7 0: www.baidu.com
1 Ping www.baidu.com2PING www.a.shifen.com (115.239.210.27) About( -) bytes of data.3  -bytes from 115.239.210.27: icmp_req=1Ttl= -Time=34.9Ms4  -bytes from 115.239.210.27: icmp_req=2Ttl= -Time=34.5Ms5^C64 bytes from 115.239.210.27: icmp_req=3Ttl= -Time=33.5Ms6 7---www.a.shifen.com ping statistics---8 3Packets Transmitted,3Received0%packet loss, time 10122ms9RTT Min/avg/max/mdev =33.547/34.347/34.977/0.633Ms

DNS Domain name resolution

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.