Merge commit 'c5bab7026b8e0ac44b25ee08507ea360f177d844' into merges
[unleashed.git] / share / man / man3xnet / getnameinfo.3xnet
blob27a6630a1f839197e5fa32254b83f5c016b3ab9c
1 '\" te
2 .\" Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved.
3 .\" Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
4 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
7 .\"  This notice shall appear on any product containing this material.
8 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
9 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
10 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
11 .TH GETNAMEINFO 3XNET "Nov 1, 2003"
12 .SH NAME
13 getnameinfo \- get name information
14 .SH SYNOPSIS
15 .LP
16 .nf
17 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... [ \fIlibrary\fR ... ]
18 #include <sys/socket.h>
19 #include <netdb.h>
21 \fBint\fR \fBgetnameinfo\fR(\fBconst struct sockaddr *restrict\fR \fIsa\fR, \fBsocklen_t\fR \fIsalen\fR,
22      \fBchar *restrict\fR \fInode\fR, \fBsocklen_t\fR \fInodelen\fR, \fBchar *restrict\fR \fIservice\fR,
23      \fBsocklen_t\fR \fIservicelen\fR, \fBunsigned\fR \fIflags\fR);
24 .fi
26 .SH DESCRIPTION
27 .LP
28 The \fBgetnameinfo()\fR function translates a socket address to a node name and
29 service location, all of which are defined as in \fBgetaddrinfo\fR(3XNET).
30 .sp
31 .LP
32 The \fIsa\fR argument points to a socket address structure to be translated. If
33 the socket address structure contains an IPv4-mapped IPv6 address or an
34 IPv4-compatible IPv6 address, the implementation extracts the embedded IPv4
35 address and lookup the node name for that IPv4 address.
36 .sp
37 .LP
38 If the \fInode\fR argument is non-\fINULL\fR and the nodelen argument is
39 non-zero, then the \fInode\fR argument points to a buffer able to contain up to
40 \fInodelen\fR characters that receives the node name as a null-terminated
41 string. If the \fInode\fR argument is \fINULL\fR or the \fInodelen\fR argument
42 is zero, the node name is not returned. If the node's name cannot be located,
43 the numeric form of the node's address is returned instead of its name.
44 .sp
45 .LP
46 If the \fIservice\fR argument is non-\fINULL\fR and the \fIservicelen\fR
47 argument is non-zero, then the \fIservice\fR argument points to a buffer able
48 to contain up to \fIservicelen\fR bytes that receives the service name as a
49 null-terminated string. If the \fIservice\fR argument is \fINULL\fR or the
50 \fIservicelen\fR argument is zero, the service name is not returned. If the
51 service's name cannot be located, the numeric form of the service address (for
52 example, its port number) is returned instead of its name.
53 .sp
54 .LP
55 The \fIflags\fR argument is a flag that changes the default actions of the
56 function. By default the fully-qualified domain name (FQDN) for the host is
57 returned, but:
58 .RS +4
59 .TP
60 .ie t \(bu
61 .el o
62 If the flag bit \fBNI_NOFQDN\fR is set, only the node name portion of the FQDN
63 is returned for local hosts.
64 .RE
65 .RS +4
66 .TP
67 .ie t \(bu
68 .el o
69 If the flag bit \fBNI_NUMERICHOST\fR is set, the numeric form of the host's
70 address is returned instead of its name, under all circumstances.
71 .RE
72 .RS +4
73 .TP
74 .ie t \(bu
75 .el o
76 If the flag bit \fBNI_NAMEREQD\fR is set, an error is returned if the host's
77 name cannot be located.
78 .RE
79 .RS +4
80 .TP
81 .ie t \(bu
82 .el o
83 If the flag bit \fBNI_NUMERICSERV\fR is set, the numeric form of the service
84 address is returned (for example, its port number) instead of its name, under
85 all circumstances.
86 .RE
87 .RS +4
88 .TP
89 .ie t \(bu
90 .el o
91 If the flag bit \fBNI_DGRAM\fR is set, this indicates that the service is a
92 datagram service (\fBSOCK_DGRAM\fR). The default behavior assumes that the
93 service is a stream service (\fBSOCK_STREAM\fR).
94 .RE
95 .SH RETURN VALUES
96 .LP
97 A 0 return value for \fBgetnameinfo()\fR indicates successful completion; a
98 non-zero return value indicates failure. The possible values for the failures
99 are listed in the ERRORS section.
102 Upon successful completion, \fBgetnameinfo()\fR returns the node and service
103 names, if requested, in the buffers provided. The returned names are always
104 null-terminated strings.
105 .SH ERRORS
107 The \fBgetnameinfo()\fR function will fail if:
109 .ne 2
111 \fB\fBEAI_AGAIN\fR\fR
113 .RS 16n
114 The name could not be resolved at this time. Future attempts might succeed.
118 .ne 2
120 \fB\fBEAI_BADFLAGS\fR\fR
122 .RS 16n
123 The \fIflags\fR argument had an invalid value.
127 .ne 2
129 \fB\fBEAI_FAIL\fR\fR
131 .RS 16n
132 A non-recoverable error occurred.
136 .ne 2
138 \fB\fBEAI_FAMILY\fR\fR
140 .RS 16n
141 The address family was not recognized or the address length was invalid for the
142 specified family.
146 .ne 2
148 \fB\fBEAI_MEMORY\fR\fR
150 .RS 16n
151 There was a memory allocation failure.
155 .ne 2
157 \fB\fBEAI_NONAME\fR\fR
159 .RS 16n
160 The name does not resolve for the supplied parameters.       \fBNI_NAMEREQD\fR
161 is set and the host's name cannot be located, or both \fInodename\fR and
162 \fIservname\fR were \fINULL\fR.
166 .ne 2
168 \fB\fBEAI_SYSTEM\fR\fR
170 .RS 16n
171 A system error occurred. The error code can be found in \fBerrno\fR.
174 .SH USAGE
176 If the returned values are to be used as part of any further name resolution
177 (for example, passed to \fBgetaddrinfo()\fR), applications should provide
178 buffers large enough to store any result possible on the system.
181 Given the IPv4-mapped IPv6 address "::ffff:1.2.3.4", the implementation
182 performs a lookup as if the socket address structure contains the IPv4 address
183 "1.2.3.4".
184 .SH ATTRIBUTES
186 See \fBattributes\fR(5) for descriptions of the following attributes:
191 box;
192 c | c
193 l | l .
194 ATTRIBUTE TYPE  ATTRIBUTE VALUE
196 Interface Stability     Standard
198 MT-Level        MT-Safe
201 .SH SEE ALSO
203 \fBsockaddr\fR(3SOCKET),
204 \fBgai_strerror\fR(3XNET), \fBgetaddrinfo\fR(3XNET),
205 \fBgetservbyname\fR(3XNET), \fBsocket\fR(3XNET), \fBattributes\fR(5),
206 \fBstandards\fR(5)
207 .SH NOTES
209 The IPv6 unspecified address ("::") and the IPv6 loopback address ("::1") are
210 not IPv4-compatible addresses. If the address is the IPv6 unspecified address
211 ("::"), a lookup is not performed, and the \fBEAI_NONAME\fR error is returned.
214 The two \fBNI_NUMERIC\fR\fIxxx\fR flags are required to support the \fB-n\fR
215 flag that many commands provide.
218 The \fBNI_DGRAM\fR flag is required for the few \fBAF_INET\fR and
219 \fBAF_INET6\fR port numbers (for example, [512,514]) that represent different
220 services for UDP and TCP.