1GETIPNODEBYNAME(3) Linux Programmer's Manual GETIPNODEBYNAME(3)
2
3
4
6 getipnodebyname, getipnodebyaddr, freehostent - get network hostnames
7 and addresses
8
10 #include <sys/types.h>
11 #include <sys/socket.h>
12 #include <netdb.h>
13
14 struct hostent *getipnodebyname(const char *name, int af,
15 int flags, int *error_num);
16
17 struct hostent *getipnodebyaddr(const void *addr, size_t len,
18 int af, int *error_num);
19
20 void freehostent(struct hostent *ip);
21
23 These functions are deprecated (and unavailable in glibc). Use getad‐
24 drinfo(3) and getnameinfo(3) instead.
25
26 The getipnodebyname() and getipnodebyaddr() functions return the names
27 and addresses of a network host. These functions return a pointer to
28 the following structure:
29
30 struct hostent {
31 char *h_name;
32 char **h_aliases;
33 int h_addrtype;
34 int h_length;
35 char **h_addr_list;
36 };
37
38 These functions replace the gethostbyname(3) and gethostbyaddr(3) func‐
39 tions, which could access only the IPv4 network address family. The
40 getipnodebyname() and getipnodebyaddr() functions can access multiple
41 network address families.
42
43 Unlike the gethostby functions, these functions return pointers to dy‐
44 namically allocated memory. The freehostent() function is used to re‐
45 lease the dynamically allocated memory after the caller no longer needs
46 the hostent structure.
47
48 getipnodebyname() arguments
49 The getipnodebyname() function looks up network addresses for the host
50 specified by the name argument. The af argument specifies one of the
51 following values:
52
53 AF_INET
54 The name argument points to a dotted-quad IPv4 address or a name
55 of an IPv4 network host.
56
57 AF_INET6
58 The name argument points to a hexadecimal IPv6 address or a name
59 of an IPv6 network host.
60
61 The flags argument specifies additional options. More than one option
62 can be specified by bitwise OR-ing them together. flags should be set
63 to 0 if no options are desired.
64
65 AI_V4MAPPED
66 This flag is used with AF_INET6 to request a query for IPv4 ad‐
67 dresses instead of IPv6 addresses; the IPv4 addresses will be
68 mapped to IPv6 addresses.
69
70 AI_ALL This flag is used with AI_V4MAPPED to request a query for both
71 IPv4 and IPv6 addresses. Any IPv4 address found will be mapped
72 to an IPv6 address.
73
74 AI_ADDRCONFIG
75 This flag is used with AF_INET6 to further request that queries
76 for IPv6 addresses should not be made unless the system has at
77 least one IPv6 address assigned to a network interface, and that
78 queries for IPv4 addresses should not be made unless the system
79 has at least one IPv4 address assigned to a network interface.
80 This flag may be used by itself or with the AI_V4MAPPED flag.
81
82 AI_DEFAULT
83 This flag is equivalent to (AI_ADDRCONFIG | AI_V4MAPPED).
84
85 getipnodebyaddr() arguments
86 The getipnodebyaddr() function looks up the name of the host whose net‐
87 work address is specified by the addr argument. The af argument speci‐
88 fies one of the following values:
89
90 AF_INET
91 The addr argument points to a struct in_addr and len must be set
92 to sizeof(struct in_addr).
93
94 AF_INET6
95 The addr argument points to a struct in6_addr and len must be
96 set to sizeof(struct in6_addr).
97
99 NULL is returned if an error occurred, and error_num will contain an
100 error code from the following list:
101
102 HOST_NOT_FOUND
103 The hostname or network address was not found.
104
105 NO_ADDRESS
106 The domain name server recognized the network address or name,
107 but no answer was returned. This can happen if the network host
108 has only IPv4 addresses and a request has been made for IPv6 in‐
109 formation only, or vice versa.
110
111 NO_RECOVERY
112 The domain name server returned a permanent failure response.
113
114 TRY_AGAIN
115 The domain name server returned a temporary failure response.
116 You might have better luck next time.
117
118 A successful query returns a pointer to a hostent structure that con‐
119 tains the following fields:
120
121 h_name This is the official name of this network host.
122
123 h_aliases
124 This is an array of pointers to unofficial aliases for the same
125 host. The array is terminated by a null pointer.
126
127 h_addrtype
128 This is a copy of the af argument to getipnodebyname() or
129 getipnodebyaddr(). h_addrtype will always be AF_INET if the af
130 argument was AF_INET. h_addrtype will always be AF_INET6 if the
131 af argument was AF_INET6.
132
133 h_length
134 This field will be set to sizeof(struct in_addr) if h_addrtype
135 is AF_INET, and to sizeof(struct in6_addr) if h_addrtype is
136 AF_INET6.
137
138 h_addr_list
139 This is an array of one or more pointers to network address
140 structures for the network host. The array is terminated by a
141 null pointer.
142
144 RFC 2553.
145
147 These functions were present in glibc 2.1.91-95, but were removed
148 again. Several UNIX-like systems support them, but all call them dep‐
149 recated.
150
152 getaddrinfo(3), getnameinfo(3), inet_ntop(3), inet_pton(3)
153
155 This page is part of release 5.10 of the Linux man-pages project. A
156 description of the project, information about reporting bugs, and the
157 latest version of this page, can be found at
158 https://www.kernel.org/doc/man-pages/.
159
160
161
162Linux 2017-09-15 GETIPNODEBYNAME(3)