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