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