#include /* for AF_INET */
struct hostent *gethostbyaddr(const void *addr,socklen_t len, int type);
addr 指向网络字节顺序地址的指针
返回值
The gethostbyname() and gethostbyaddr() functions return the hostent
structure or a NULL pointer if an error occurs. On error, the h_errno
variable holds an error number. When non-NULL, the return value may
point at static data, see the notes below.
struct hostent {char*h_name;/* official name of host */char**h_aliases;/* alias list */int h_addrtype;/* host address type */int h_length;/* length of address */char**h_addr_list;/* list of addresses地址列表,指向主机的多个网络地址(网络字节序32位整数). */}#define h_addr h_addr_list[0] /* for backward compatibility */linux@linux:~$ ping www.baidu.com
PING www.a.shifen.com (58.217.200.15) 56(84) bytes of data. //www.a.shifen.com就是h_addr_list列表中的一个
64 bytes from 58.217.200.15: icmp_seq=1 ttl=55 time=21.1 ms
64 bytes from 58.217.200.15: icmp_seq=2 ttl=55 time=18.8 ms
64 bytes from 58.217.200.15: icmp_seq=3 ttl=55 time=10.1 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2005ms
rtt min/avg/max/mdev = 10.123/16.686/21.130/4.739 ms