1 .\" Copyright (c) 1983, 1987, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
33 .\" $Id: getnameinfo.3,v 1.2 1999/10/07 04:46:27 itojun Exp $
42 .Nd address-to-nodename translation in protocol-independent manner
45 .Fd #include <sys/types.h>
46 .Fd #include <sys/socket.h>
47 .Fd #include <netdb.h>
49 .Fn getnameinfo "const struct sockaddr *sa" "socklen_t salen" "char *host" "size_t hostlen" "char *serv" "size_t servlen" "int flags"
54 function is defined for protocol-independent address-to-nodename translation.
55 Its functionality is a reverse conversion of
57 and implements similar functionality with
58 .Xr gethostbyaddr 3 and
60 in more sophisticated manner.
62 This function looks up an IP address and port number provided by the
63 caller in the DNS and system-specific database, and returns text
64 strings for both in buffers provided by the caller.
65 The function indicates successful completion by a zero return value;
66 a non-zero return value indicates failure.
72 structure (for IPv4) or a
74 structure (for IPv6) that holds the IP address and port number.
77 argument gives the length of the
83 The function returns the nodename associated with the IP address in
84 the buffer pointed to by the
87 The caller provides the size of this buffer via the
90 The service name associated with the port number is returned in the buffer
95 argument gives the length of this buffer.
96 The caller specifies not to return either string by providing a zero
102 Otherwise, the caller must provide buffers large enough to hold the
103 nodename and the service name, including the terminating null characters.
105 Unfortunately most systems do not provide constants that specify the
106 maximum size of either a fully-qualified domain name or a service name.
107 Therefore to aid the application in allocating buffers for these two
108 returned strings the following constants are defined in
111 #define NI_MAXHOST 1025
112 #define NI_MAXSERV 32
115 The first value is actually defined as the constant
117 in recent versions of BIND's
121 older versions of BIND define this constant to be 256
123 and the second is a guess based on the services listed in the current
124 Assigned Numbers RFC.
126 The final argument is a
128 that changes the default actions of this function.
129 By default the fully-qualified domain name (FQDN) for the host is
130 looked up in the DNS and returned.
133 is set, only the nodename portion of the FQDN is returned for local hosts.
139 is set, or if the host's name cannot be located in the DNS,
140 the numeric form of the host's address is returned instead of its name
151 is set, an error is returned if the host's name cannot be located in the DNS.
155 is set, the numeric form of the service address is returned
156 .Pq e.g., its port number
160 flags are required to support the
162 flag that many commands provide.
166 specifies that the service is a datagram service, and causes
168 to be called with a second argument of "udp" instead of its default of "tcp".
169 This is required for the few ports (512-514)
170 that have different services for UDP and TCP.
178 The implementation allows experimental numeric IPv6 address notation with
180 IPv6 link-local address will appear as string like
192 .Bl -tag -width /etc/resolv.conf -compact
194 .It Pa /etc/host.conf
195 .It Pa /etc/resolv.conf
199 The function indicates successful completion by a zero return value;
200 a non-zero return value indicates failure.
204 .Xr gethostbyaddr 3 ,
205 .Xr getservbyport 3 ,
216 .%T Basic Socket Interface Extensions for IPv6
222 The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit.
227 function is defined IEEE POSIX 1003.1g draft specification,
228 and documented in ``Basic Socket Interface Extensions for IPv6''
232 The text was shamelessly copied from RFC2553.