1GETIPNODEBYNAME(3) BSD Library Functions Manual GETIPNODEBYNAME(3)
2
4 getipnodebyname, getipnodebyaddr — get network host entry
5 freehostent — free network host entry
6
8 #include <netdb.h>
9
10 struct hostent *
11 getipnodebyname(const char *name, int af, int flags, int *error);
12
13 struct hostent *
14 getipnodebyaddr(const void *addr, size_t len, int af, int *error);
15
16 void
17 freehostent(struct hostent *he);
18
20 Getipnodebyname(), and getipnodebyaddr() each return a pointer to a
21 hostent structure (see below) describing an internet host referenced by
22 name or by address, as the function names indicate. This structure con‐
23 tains either the information obtained from the name server, or broken-out
24 fields from a line in /etc/hosts. If the local name server is not run‐
25 ning, these routines do a lookup in /etc/hosts.
26
27 struct hostent {
28 char *h_name; /* official name of host */
29 char **h_aliases; /* alias list */
30 int h_addrtype; /* host address type */
31 int h_length; /* length of address */
32 char **h_addr_list; /* list of addresses from name server */
33 };
34
35 #define h_addr h_addr_list[0] /* address, for backward compatibility */
36
37 The members of this structure are:
38
39 h_name Official name of the host.
40
41 h_aliases A zero-terminated array of alternate names for the host.
42
43 h_addrtype The type of address being returned.
44
45 h_length The length, in bytes, of the address.
46
47 h_addr_list A zero-terminated array of network addresses for the host.
48 Host addresses are returned in network byte order.
49
50 h_addr The first address in h_addr_list; this is for backward com‐
51 patibility.
52
53 This structure should be freed after use by calling freehostent().
54
55 When using the nameserver, getiphostbyaddr() will search for the named
56 host in each parent domain given in the “search” directive of
57 resolv.conf(5) unless the name contains a dot (“.”). If the name con‐
58 tains no dot, and if the environment variable HOSTALIASES contains the
59 name of an alias file, the alias file will first be searched for an alias
60 matching the input name. See hostname(7) for the domain search procedure
61 and the alias file format.
62
63 Getiphostbyaddr() can be told to look for IPv4 addresses, IPv6 addresses
64 or both IPv4 and IPv6. If IPv4 addresses only are to be looked up then
65 af should be set to AF_INET, otherwise it should be set to AF_INET6.
66
67 There are three flags that can be set
68
69 AI_V4MAPPED Return IPv4 addresses if no IPv6 addresses are found.
70 This flag is ignored unless af is AF_INET6.
71
72 AI_ALL Return IPv4 addresses as well IPv6 addresses if
73 AI_V4MAPPED is set. This flag is ignored unless af is
74 AF_INET6.
75
76 AI_ADDRCONFIG Only return addresses of a given type if the system has an
77 active interface with that type.
78