1 .\" $NetBSD: getsockname.2,v 1.24 2012/07/09 21:22:21 jdf Exp $
3 .\" Copyright (c) 1983, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)getsockname.2 8.1 (Berkeley) 6/4/93
43 .Fn getsockname "int s" "struct sockaddr * restrict name" "socklen_t * restrict namelen"
46 returns the locally bound address information for a specified socket.
48 Common uses of this function are as follows:
53 is called with a port number of 0 (indicating the kernel should pick
56 is used to retrieve the kernel-assigned port number.
60 on a wildcard IP address,
62 is used to retrieve the local IP address for the connection.
64 When a function wishes to know the address family of a socket,
70 takes three parameters:
73 Contains the file descriptor for the socket to be looked up.
78 structure which will hold the resulting address information.
79 Normal use requires one to use a structure
80 specific to the protocol family in use, such as
84 (IPv6), cast to a (struct sockaddr *).
86 For greater portability (such as newer protocol families) the new
87 structure sockaddr_storage exists.
89 is large enough to hold any of the other sockaddr_* variants.
90 On return, it should be cast to the correct sockaddr type,
91 according to the current protocol family.
94 indicates the amount of space pointed to by
99 is set to the actual size of the returned address information.
101 If the address of the destination socket for a given socket connection is
104 function should be used instead.
108 does not point to enough space to hold the entire socket address, the
109 result will be truncated to
117 is set to the actual size of the socket address returned in
121 is set, and a value of \-1 is returned.
123 The call succeeds unless:
128 is not a valid descriptor.
132 is a file, not a socket.
134 The socket has been shut down.
136 Insufficient resources were available in the system to perform the operation.
138 The socket is not connected.
142 parameter points to memory not in a valid part of the process address space.
150 function call appeared in
153 Names bound to sockets in the
155 domain are inaccessible;
157 returns a zero length name.