1.\" Copyright (c) 1983, 1987, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 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. 19.\" 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 30.\" SUCH DAMAGE. 31.\" 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 $ 34.\" $FreeBSD$ 35.\" 36.Dd May 25, 1995 37.Dt GETNAMEINFO 3 38.Os KAME 39.\" 40.Sh NAME 41.Nm getnameinfo 42.Nd address-to-nodename translation in protocol-independent manner 43.\" 44.Sh SYNOPSIS 45.Fd #include <sys/types.h> 46.Fd #include <sys/socket.h> 47.Fd #include <netdb.h> 48.Ft int 49.Fn getnameinfo "const struct sockaddr *sa" "socklen_t salen" "char *host" "size_t hostlen" "char *serv" "size_t servlen" "int flags" 50.\" 51.Sh DESCRIPTION 52The 53.Fn getnameinfo 54function is defined for protocol-independent address-to-nodename translation. 55Its functionality is a reverse conversion of 56.Xr getaddrinfo 3 , 57and implements similar functionality with 58.Xr gethostbyaddr 3 and 59.Xr getservbyport 3 60in more sophisticated manner. 61.Pp 62This function looks up an IP address and port number provided by the 63caller in the DNS and system-specific database, and returns text 64strings for both in buffers provided by the caller. 65The function indicates successful completion by a zero return value; 66a non-zero return value indicates failure. 67.Pp 68The first argument, 69.Fa sa , 70points to either a 71.Fa sockaddr_in 72structure (for IPv4) or a 73.Fa sockaddr_in6 74structure (for IPv6) that holds the IP address and port number. 75The 76.Fa salen 77argument gives the length of the 78.Fa sockaddr_in 79or 80.Fa sockaddr_in6 81structure. 82.Pp 83The function returns the nodename associated with the IP address in 84the buffer pointed to by the 85.Fa host 86argument. 87The caller provides the size of this buffer via the 88.Fa hostlen 89argument. 90The service name associated with the port number is returned in the buffer 91pointed to by 92.Fa serv , 93and the 94.Fa servlen 95argument gives the length of this buffer. 96The caller specifies not to return either string by providing a zero 97value for the 98.Fa hostlen 99or 100.Fa servlen 101arguments. 102Otherwise, the caller must provide buffers large enough to hold the 103nodename and the service name, including the terminating null characters. 104.Pp 105Unfortunately most systems do not provide constants that specify the 106maximum size of either a fully-qualified domain name or a service name. 107Therefore to aid the application in allocating buffers for these two 108returned strings the following constants are defined in 109.Li <netdb.h> : 110.Bd -literal -offset 111#define NI_MAXHOST 1025 112#define NI_MAXSERV 32 113.Ed 114.Pp 115The first value is actually defined as the constant 116.Dv MAXDNAME 117in recent versions of BIND's 118.Li <arpa/nameser.h> 119header 120.Po 121older versions of BIND define this constant to be 256 122.Pc 123and the second is a guess based on the services listed in the current 124Assigned Numbers RFC. 125.Pp 126The final argument is a 127.Fa flag 128that changes the default actions of this function. 129By default the fully-qualified domain name (FQDN) for the host is 130looked up in the DNS and returned. 131If the flag bit 132.Dv NI_NOFQDN 133is set, only the nodename portion of the FQDN is returned for local hosts. 134.Pp 135If the 136.Fa flag 137bit 138.Dv NI_NUMERICHOST 139is set, or if the host's name cannot be located in the DNS, 140the numeric form of the host's address is returned instead of its name 141.Po 142e.g., by calling 143.Fn inet_ntop 144instead of 145.Fn getnodebyaddr 146.Pc . 147If the 148.Fa flag 149bit 150.Dv NI_NAMEREQD 151is set, an error is returned if the host's name cannot be located in the DNS. 152.Pp 153If the flag bit 154.Dv NI_NUMERICSERV 155is set, the numeric form of the service address is returned 156.Pq e.g., its port number 157instead of its name. 158The two 159.Dv NI_NUMERICxxx 160flags are required to support the 161.Li "-n" 162flag that many commands provide. 163.Pp 164A fifth flag bit, 165.Dv NI_DGRAM , 166specifies that the service is a datagram service, and causes 167.Fn getservbyport 168to be called with a second argument of "udp" instead of its default of "tcp". 169This is required for the few ports (512-514) 170that have different services for UDP and TCP. 171.Pp 172These 173.Dv NI_xxx 174flags are defined in 175.Li <netdb.h> . 176.\" 177.Sh EXTENSION 178The implementation allows experimental numeric IPv6 address notation with 179scope identifier. 180IPv6 link-local address will appear as string like 181.Dq Li fe80::1@ne0 , 182if 183.Dv NI_WITHSCOPEID 184bit is enabled in 185.Ar flags 186argument. 187Refer to 188.Xr getaddrinfo 3 189for the notation. 190.\" 191.Sh FILES 192.Bl -tag -width /etc/resolv.conf -compact 193.It Pa /etc/hosts 194.It Pa /etc/host.conf 195.It Pa /etc/resolv.conf 196.El 197.\" 198.Sh DIAGNOSTICS 199The function indicates successful completion by a zero return value; 200a non-zero return value indicates failure. 201.\" 202.Sh SEE ALSO 203.Xr getaddrinfo 3 , 204.Xr gethostbyaddr 3 , 205.Xr getservbyport 3 , 206.Xr hosts 5 , 207.Xr services 5 , 208.Xr hostname 7 , 209.Xr named 8 210.Pp 211.Rs 212.%A R. Gilligan 213.%A S. Thomson 214.%A J. Bound 215.%A W. Stevens 216.%T Basic Socket Interface Extensions for IPv6 217.%R RFC2553 218.%D March 1999 219.Re 220.\" 221.Sh HISTORY 222The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit. 223.\" 224.Sh STANDARDS 225The 226.Fn getaddrinfo 227function is defined IEEE POSIX 1003.1g draft specification, 228and documented in ``Basic Socket Interface Extensions for IPv6'' 229.Pq RFC2533 . 230.\" 231.Sh BUGS 232The text was shamelessly copied from RFC2553. 233