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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
.\" Copyright 2000 Sam Varshavchik <mrsam@courier-mta.com>
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" References: RFC 2553
.TH GETIPNODEBYNAME 3 2007-11-15 "Linux" "Linux Programmer's Manual"
.SH NAME
getipnodebyname, getipnodebyaddr, freehostent \- get network
host names and addresses
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.B #include <sys/socket.h>
.B #include <netdb.h>
.sp
.BI "struct hostent *getipnodebyname(const char *" "name" ,
.BI " int " "af" ", int " "flags" ,
.BI " int *" "error_num" );
.sp
.BI "struct hostent *getipnodebyaddr(const void *" "addr" ,
.BI " size_t " "len" ", int " "af" ,
.BI " int *" "error_num" );
.sp
.BI "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.
.LP
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:
.sp
.nf
struct hostent {
char *h_name;
char **h_aliases;
int h_addrtype;
int h_length;
char **h_addr_list;
};
.fi
.PP
These functions replace the
.BR gethostbyname (3)
and
.BR gethostbyaddr (3)
functions, which could only access 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 parameters
The
.BR getipnodebyname ()
function
looks up network addresses for the host
specified by the
.I name
parameter.
The
.I af
parameter specifies one of the following values:
.TP
.B AF_INET
The
.I name
parameter points to a dotted-quad IPv4 address or a name
of an IPv4 network host.
.TP
.B AF_INET6
The
.I name
parameter points to a hexadecimal IPv6 address or a name
of an IPv6 network host.
.PP
The
.I flags
parameter specifies additional options.
More than one option can be specified by logically 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 parameters
The
.BR getipnodebyaddr ()
function
looks up the name of the host whose
network address is
specified by the
.I addr
parameter.
The
.I af
parameter specifies one of the following values:
.TP
.B AF_INET
The
.I addr
parameter 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
parameter points to a
.I struct in6_addr
and
.I len
must be set to
.IR "sizeof(struct in6_addr)" .
.SH "RETURN VALUE"
A null pointer 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 host name 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
parameter to
.BR getipnodebyname ()
or
.BR getipnodebyaddr ().
.I h_addrtype
will always be
.B AF_INET
if the
.I af
parameter was
.BR AF_INET .
.I h_addrtype
will always be
.B AF_INET6
if the
.I af
parameter 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 "CONFORMING TO"
RFC\ 2553.
.\" Not in POSIX.1-2001.
.SH NOTES
These functions were present in glibc 2.1.91-95, but were
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)
|