OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / original / man2 / getsockname.2
1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" 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 .\"     @(#)getsockname.2       6.4 (Berkeley) 3/10/91
33 .\"
34 .\" Modified Sat Jul 24 16:30:29 1993 by Rik Faith <faith@cs.unc.edu>
35 .\" Modified Tue Oct 22 00:22:35 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
36 .\" Modified Sun Mar 28 21:26:46 1999 by Andries Brouwer <aeb@cwi.nl>
37 .\"
38 .TH GETSOCKNAME 2 2008-12-03 "Linux" "Linux Programmer's Manual"
39 .SH NAME
40 getsockname \- get socket name
41 .SH SYNOPSIS
42 .nf
43 .B #include <sys/socket.h>
44 .sp
45 .BI "int getsockname(int " sockfd ", struct sockaddr *" addr \
46 ", socklen_t *" addrlen );
47 .fi
48 .SH DESCRIPTION
49 .BR getsockname ()
50 returns the current address to which the socket
51 .I sockfd
52 is bound, in the buffer pointed to by
53 .IR addr .
54 The
55 .I addrlen
56 argument should be initialized to indicate
57 the amount of space (in bytes) pointed to by
58 .IR addr .
59 On return it contains the actual size of the socket address.
60
61 The returned address is truncated if the buffer provided is too small;
62 in this case,
63 .I addrlen
64 will return a value greater than was supplied to the call.
65 .SH "RETURN VALUE"
66 On success, zero is returned.
67 On error, \-1 is returned, and
68 .I errno
69 is set appropriately.
70 .SH ERRORS
71 .TP
72 .B EBADF
73 The argument
74 .I sockfd
75 is not a valid descriptor.
76 .TP
77 .B EFAULT
78 The
79 .I addr
80 argument points to memory not in a valid part of the
81 process address space.
82 .TP
83 .B EINVAL
84 .I addrlen
85 is invalid (e.g., is negative).
86 .TP
87 .B ENOBUFS
88 Insufficient resources were available in the system
89 to perform the operation.
90 .TP
91 .B ENOTSOCK
92 The argument
93 .I sockfd
94 is a file, not a socket.
95 .SH "CONFORMING TO"
96 SVr4, 4.4BSD (the
97 .BR getsockname ()
98 function call appeared in 4.2BSD), POSIX.1-2001.
99 .\" SVr4 documents additional ENOMEM
100 .\" and ENOSR error codes.
101 .SH NOTES
102 The third argument of
103 .BR getsockname ()
104 is in reality an \fIint *\fP
105 (and this is what 4.x BSD and libc4 and libc5 have).
106 Some POSIX confusion resulted in the present \fIsocklen_t\fP,
107 also used by glibc.
108 See also
109 .BR accept (2).
110 .SH "SEE ALSO"
111 .BR bind (2),
112 .BR socket (2),
113 .BR getifaddrs (3),
114 .BR ip (7),
115 .BR socket (7),
116 .BR unix (7)