1 .\" $OpenBSD: getsockname.2,v 1.30 2015/09/10 17:55:21 schwarze Exp $
2 .\" $NetBSD: getsockname.2,v 1.6 1995/10/12 15:41:00 jtc Exp $
4 .\" Copyright (c) 1983, 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. Neither the name of the University nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" @(#)getsockname.2 8.1 (Berkeley) 6/4/93
33 .Dd $Mdocdate: September 10 2015 $
42 .Fn getsockname "int s" "struct sockaddr *name" "socklen_t *namelen"
45 returns the locally bound address information for a specified socket.
47 Common uses of this function are as follows:
52 is called with a port number of 0 (indicating the kernel should pick
55 is used to retrieve the kernel-assigned port number.
59 on a wildcard IP address,
61 is used to retrieve the local IP address for the connection.
63 When a function wishes to know the address family of a socket,
69 takes three parameters:
72 contains the file descriptor for the socket to be looked up.
77 structure which will hold the resulting address information.
78 Normal use requires one to use a structure
79 specific to the protocol family in use, such as
83 (IPv6), cast to a (struct sockaddr *).
85 For greater portability (such as newer protocol families) the new
86 structure sockaddr_storage exists.
88 is large enough to hold any of the other sockaddr_* variants.
89 On return, it should be cast to the correct sockaddr type,
90 according to the current protocol family.
93 indicates the amount of space pointed to by
98 is set to the actual size of the returned address information.
100 If the address of the destination socket for a given socket connection is
103 function should be used instead.
107 does not point to enough space to hold the entire socket address, the
108 result will be truncated to
116 is set to the actual size of the socket address returned in
120 is set, and a value of \-1 is returned.
126 is set to one of the following:
131 is not a valid descriptor.
135 is a file, not a socket.
137 Insufficient resources were available in the system
138 to perform the operation.
144 parameter points to memory not in a valid part of the
145 process address space.
147 The socket has been shut down.
163 function call appeared in