1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
.\" Copyright 2000 Sam Varshavchik <mrsam@courier-mta.com>
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
.\" References: RFC 2553
.TH getipnodebyname 3 2023-03-30 "Linux man-pages 6.05.01"
.SH NAME
getipnodebyname, getipnodebyaddr, freehostent \- get network
hostnames and addresses
.SH LIBRARY
Standard C library
.RI ( libc ", " \-lc )
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.B #include <sys/socket.h>
.B #include <netdb.h>
.PP
.BI "[[deprecated]] struct hostent *getipnodebyname(const char *" name ", int " af ,
.BI " int " flags ", int *" error_num );
.BI "[[deprecated]] struct hostent *getipnodebyaddr(const void " addr [. len ],
.BI " size_t " len ", int " af ,
.BI " int *" "error_num" );
.BI "[[deprecated]] void freehostent(struct hostent *" "ip" );
.fi
.SH DESCRIPTION
These functions are deprecated (and unavailable in glibc).
Use
.BR getaddrinfo (3)
and
.BR getnameinfo (3)
instead.
.PP
The
.BR getipnodebyname ()
and
.BR getipnodebyaddr ()
functions return the names and addresses of a network host.
These functions return a pointer to the
following structure:
.PP
.in +4n
.EX
struct hostent {
char *h_name;
char **h_aliases;
int h_addrtype;
int h_length;
char **h_addr_list;
};
.EE
.in
.PP
These functions replace the
.BR gethostbyname (3)
and
.BR gethostbyaddr (3)
functions, which could access only the IPv4 network address family.
The
.BR getipnodebyname ()
and
.BR getipnodebyaddr ()
functions can access multiple network address families.
.PP
Unlike the
.B gethostby
functions,
these functions return pointers to dynamically allocated memory.
The
.BR freehostent ()
function is used to release the dynamically allocated memory
after the caller no longer needs the
.I hostent
structure.
.SS getipnodebyname() arguments
The
.BR getipnodebyname ()
function
looks up network addresses for the host
specified by the
.I name
argument.
The
.I af
argument specifies one of the following values:
.TP
.B AF_INET
The
.I name
argument points to a dotted-quad IPv4 address or a name
of an IPv4 network host.
.TP
.B AF_INET6
The
.I name
argument points to a hexadecimal IPv6 address or a name
of an IPv6 network host.
.PP
The
.I flags
argument specifies additional options.
More than one option can be specified by bitwise OR-ing
them together.
.I flags
should be set to 0
if no options are desired.
.TP
.B AI_V4MAPPED
This flag is used with
.B AF_INET6
to request a query for IPv4 addresses instead of
IPv6 addresses; the IPv4 addresses will
be mapped to IPv6 addresses.
.TP
.B AI_ALL
This flag is used with
.B AI_V4MAPPED
to request a query for both IPv4 and IPv6 addresses.
Any IPv4 address found will be mapped to an IPv6 address.
.TP
.B AI_ADDRCONFIG
This flag is used with
.B AF_INET6
to
further request that queries for IPv6 addresses should not be made unless
the system has at least one IPv6 address assigned to a network interface,
and that queries for IPv4 addresses should not be made unless the
system has at least one IPv4 address assigned to a network interface.
This flag may be used by itself or with the
.B AI_V4MAPPED
flag.
.TP
.B AI_DEFAULT
This flag is equivalent to
.BR "(AI_ADDRCONFIG | AI_V4MAPPED)" .
.SS getipnodebyaddr() arguments
The
.BR getipnodebyaddr ()
function
looks up the name of the host whose
network address is
specified by the
.I addr
argument.
The
.I af
argument specifies one of the following values:
.TP
.B AF_INET
The
.I addr
argument points to a
.I struct in_addr
and
.I len
must be set to
.IR "sizeof(struct in_addr)" .
.TP
.B AF_INET6
The
.I addr
argument points to a
.I struct in6_addr
and
.I len
must be set to
.IR "sizeof(struct in6_addr)" .
.SH RETURN VALUE
NULL is returned if an error occurred, and
.I error_num
will contain an error code from the following list:
.TP
.B HOST_NOT_FOUND
The hostname or network address was not found.
.TP
.B NO_ADDRESS
The domain name server recognized the network address or name,
but no answer was returned.
This can happen if the network host has only IPv4 addresses and
a request has been made for IPv6 information only, or vice versa.
.TP
.B NO_RECOVERY
The domain name server returned a permanent failure response.
.TP
.B TRY_AGAIN
The domain name server returned a temporary failure response.
You might have better luck next time.
.PP
A successful query returns a pointer to a
.I hostent
structure that contains the following fields:
.TP
.I h_name
This is the official name of this network host.
.TP
.I h_aliases
This is an array of pointers to unofficial aliases for the same host.
The array is terminated by a null pointer.
.TP
.I h_addrtype
This is a copy of the
.I af
argument to
.BR getipnodebyname ()
or
.BR getipnodebyaddr ().
.I h_addrtype
will always be
.B AF_INET
if the
.I af
argument was
.BR AF_INET .
.I h_addrtype
will always be
.B AF_INET6
if the
.I af
argument was
.BR AF_INET6 .
.TP
.I h_length
This field will be set to
.I sizeof(struct in_addr)
if
.I h_addrtype
is
.BR AF_INET ,
and to
.I sizeof(struct in6_addr)
if
.I h_addrtype
is
.BR AF_INET6 .
.TP
.I h_addr_list
This is an array of one or more pointers to network address structures for the
network host.
The array is terminated by a null pointer.
.SH STANDARDS
None.
.SH HISTORY
.\" Not in POSIX.1-2001.
RFC\ 2553.
.PP
Present in glibc 2.1.91-95, but removed again.
Several UNIX-like systems support them, but all
call them deprecated.
.SH SEE ALSO
.BR getaddrinfo (3),
.BR getnameinfo (3),
.BR inet_ntop (3),
.BR inet_pton (3)
|