1 .\" $FreeBSD: src/lib/libc/net/getipnodebyname.3,v 1.2.2.3 2001/08/17 15:42:38 ru Exp $
2 .\" $KAME: getipnodebyname.3,v 1.6 2000/08/09 21:16:17 itojun Exp $
4 .\" Copyright (c) 1983, 1987, 1991, 1993
5 .\" The Regents of the University of California. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by the University of
18 .\" California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\" may be used to endorse or promote products derived from this software
21 .\" without specific prior written permission.
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
45 .Nd nodename-to-address and address-to-nodename translation
50 .Fd #include <sys/types.h>
51 .Fd #include <sys/socket.h>
52 .Fd #include <netdb.h>
53 .Ft "struct hostent *"
54 .Fn getipnodebyname "const char *name" "int af" "int flags" "int *error_num"
55 .Ft "struct hostent *"
56 .Fn getipnodebyaddr "const void *src" "size_t len" "int af" "int *error_num"
58 .Fn freehostent "struct hostent *ptr"
64 functions are very similar to
69 The functions cover all the functionalities provided by the older ones,
70 and provide better interface to programmers.
71 The functions require additional arguments,
75 for specifying address family and operation mode.
76 The additional arguments allow programmer to get address for a nodename,
77 for specific address family
82 The functions also require an additional pointer argument,
84 to return the appropriate error code,
85 to support thread safe error code returns.
87 The type and usage of the return value,
96 argument can be either a node name or a numeric address
98 (i.e., a dotted-decimal IPv4 address or an IPv6 hex address).
101 argument specifies the address family, either
107 argument specifies the types of addresses that are searched for,
108 and the types of addresses that are returned.
109 We note that a special flags value of
112 should handle most applications.
113 That is, porting simple applications to use IPv6 replaces the call
115 hptr = gethostbyname(name);
120 hptr = getipnodebyname(name, AF_INET6, AI_DEFAULT, &error_num);
123 Applications desiring finer control over the types of addresses
124 searched for and returned, can specify other combinations of the
132 implies a strict interpretation of the
143 then the caller wants only IPv4 addresses.
147 If successful, the IPv4 addresses are returned and the
151 structure will be 4, else the function returns a
161 then the caller wants only IPv6 addresses.
165 If successful, the IPv6 addresses are returned and the
169 structure will be 16, else the function returns a
174 Other constants can be logically-ORed into the
176 argument, to modify the behavior of the function.
181 flag is specified along with an
185 then the caller will accept IPv4-mapped IPv6 addresses.
188 records are found then a query is made for
190 records and any found are returned as IPv4-mapped IPv6 addresses
195 flag is ignored unless
202 flag is exact same as the
204 flag only if the kernel supports IPv4-mapped IPv6 address.
208 flag is used in conjunction with the
210 flag, and only used with the IPv6 address family.
213 is logically or'd with
215 flag then the caller wants all addresses: IPv6 and IPv4-mapped IPv6.
216 A query is first made for
218 records and if successful, the
219 IPv6 addresses are returned. Another query is then made for
221 records and any found are returned as IPv4-mapped IPv6 addresses.
223 will be 16. Only if both queries fail does the function
226 pointer. This flag is ignored unless af equals
237 flag specifies that a query for
240 should occur only if the node has at least one IPv6 source
241 address configured and a query for
243 records should occur only if the node has at least one IPv4 source address
246 For example, if the node has no IPv6 source addresses configured,
249 equals AF_INET6, and the node name being looked up has both
257 specified, the function returns a
266 records are returned as IPv4-mapped IPv6 addresses;
269 The special flags value of
273 #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
278 function must allow the
280 argument to be either a node name or a literal address string
281 (i.e., a dotted-decimal IPv4 address or an IPv6 hex address).
282 This saves applications from having to call
284 to handle literal address strings.
287 argument is a literal address string,
290 argument is always ignored.
292 There are four scenarios based on the type of literal address string
296 The two simple cases are when
298 is a dotted-decimal IPv4 address and
304 is an IPv6 hex address and
309 returned hostent structure are:
311 points to a copy of the
330 is a pointer to the 4-byte or 16-byte binary address,
339 is a dotted-decimal IPv4 address and
346 an IPv4-mapped IPv6 address is returned:
348 points to an IPv6 hex address containing the IPv4-mapped IPv6 address,
359 is a pointer to the 16-byte binary address, and
367 is an IPv6 hex address and
371 The function's return value is a
373 pointer and the value pointed to by
379 takes almost the same argument as
380 .Xr gethostbyaddr 3 ,
381 but adds a pointer to return an error number.
382 Additionally it takes care of IPv4-mapped IPv6 addresses,
383 and IPv4-compatible IPv6 addresses.
388 dynamically allocate the structure to be returned to the caller.
390 reclaims memory region allocated and returned by
393 .Fn getipnodebyaddr .
396 .Bl -tag -width /etc/resolv.conf -compact
398 .It Pa /etc/host.conf
399 .It Pa /etc/resolv.conf
409 The integer values pointed to by
411 may then be checked to see whether this is a temporary failure
412 or an invalid or unknown host.
413 The meanings of each error code are described in
414 .Xr gethostbyname 3 .
417 .Xr gethostbyaddr 3 ,
418 .Xr gethostbyname 3 ,
429 .%T Basic Socket Interface Extensions for IPv6
435 The implementation first appeared in KAME advanced networking kit.
442 .Dq Basic Socket Interface Extensions for IPv6
449 do not handle scoped IPv6 address properly.
450 If you use these functions,
451 your program will not be able to handle scoped IPv6 addresses.
452 For IPv6 address manipulation,
458 The current implementation is not thread-safe.
460 The text was shamelessly copied from RFC2553.