2 gethostbyname, gethostbyaddr, herror, hstrerror - get network host entry
7 struct hostent *gethostbyname(const char *name);
9 struct hostent *gethostbyaddr(const char *addr, int len, int type);
11 void herror(const char *s);
13 const char * hstrerror(int err);
16 The gethostbyname() function returns a structure of type
17 hostent for the given host name. Here name is either a
18 host name, or an IPv4 address in standard dot notation, or
19 an IPv6 address in colon (and possibly dot) notation. (See
20 RFC 1884 for the description of IPv6 addresses.) If name
21 is an IPv4 or IPv6 address, no lookup is performed and
22 gethostbyname() simply copies name into the h_name field
23 and its struct in_addr equivalent into the h_addr_list[0]
24 field of the returned hostent structure. If name doesn't
25 end in a dot and the environment variable HOSTALIASES is
26 set, the alias file pointed to by HOSTALIASES will first
27 be searched for name. (See hostname(7) for the file for
28 mat.) The current domain and its parents are searched
29 unless name ends in a dot.
31 The gethostbyaddr() function returns a structure of type
32 hostent for the given host address addr of length len and
33 address type type. The only valid address type is cur
36 The (obsolete) herror() function prints the error message
37 associated with the current value of h_errno on stderr.
39 The (obsolete) hstrerror() function takes an error number
40 (typically h_errno) and returns the corresponding message
43 The domain name queries carried out by gethostbyname() and
44 gethostbyaddr() use a combination of any or all of the
45 name server named(8), a broken out line from /etc/hosts,
46 and the Network Information Service (NIS or YP), depending
47 upon the contents of the order line in /etc/host.conf.
48 (See resolv+(8)). The default action is to query
49 named(8), followed by /etc/hosts.
51 The hostent structure is defined in <netdb.h> as follows:
54 char *h_name; /* official name of host */
55 char **h_aliases; /* alias list */
56 int h_addrtype; /* host address type */
57 int h_length; /* length of address */
58 char **h_addr_list; /* list of addresses */
60 #define h_addr h_addr_list[0] /* for backward compatibility */
62 The members of the hostent structure are:
64 h_name The official name of the host.
67 A zero-terminated array of alternative names for
71 The type of address; always AF_INET at present.
74 The length of the address in bytes.
77 A zero-terminated array of network addresses for
78 the host in network byte order.
80 h_addr The first address in h_addr_list for backward com
84 The gethostbyname() and gethostbyaddr() functions return
85 the hostent structure or a NULL pointer if an error
86 occurs. On error, the h_errno variable holds an error
90 The variable h_errno can have the following values:
93 The specified host is unknown.
96 The requested name is valid but does not have an IP
100 A non-recoverable name server error occurred.
103 A temporary error occurred on an authoritative name
104 server. Try again later.