OSDN Git Service

(split) LDP: Update original to v3.37.
[linuxjm/LDP_man-pages.git] / original / man2 / getsockopt.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 .\"     $Id: getsockopt.2,v 1.1 1999/05/24 14:57:04 freitag Exp $
33 .\"
34 .\" Modified Sat Jul 24 16:19:32 1993 by Rik Faith (faith@cs.unc.edu)
35 .\" Modified Mon Apr 22 02:29:06 1996 by Martin Schulze (joey@infodrom.north.de)
36 .\" Modified Tue Aug 27 10:52:51 1996 by Andries Brouwer (aeb@cwi.nl)
37 .\" Modified Thu Jan 23 13:29:34 1997 by Andries Brouwer (aeb@cwi.nl)
38 .\" Modified Sun Mar 28 21:26:46 1999 by Andries Brouwer (aeb@cwi.nl)
39 .\" Modified 1999 by Andi Kleen <ak@muc.de>.
40 .\"     Removed most stuff because it is in socket.7 now.
41 .\"
42 .TH GETSOCKOPT 2 2008-12-03 "Linux" "Linux Programmer's Manual"
43 .SH NAME
44 getsockopt, setsockopt \- get and set options on sockets
45 .SH SYNOPSIS
46 .nf
47 .BR "#include <sys/types.h>" "          /* See NOTES */"
48 .br
49 .B #include <sys/socket.h>
50 .sp
51 .BI "int getsockopt(int " sockfd ", int " level ", int " optname ,
52 .BI "               void *" optval ", socklen_t *" optlen );
53 .BI "int setsockopt(int " sockfd ", int " level ", int " optname ,
54 .BI "               const void *" optval ", socklen_t " optlen );
55 .fi
56 .SH DESCRIPTION
57 .BR getsockopt ()
58 and
59 .BR setsockopt ()
60 manipulate options for the socket referred to by the file descriptor
61 .IR sockfd .
62 Options may exist at multiple
63 protocol levels; they are always present at the uppermost
64 socket level.
65
66 When manipulating socket options, the level at which the
67 option resides and the name of the option must be specified.
68 To manipulate options at the sockets API level,
69 .I level
70 is specified as
71 .BR SOL_SOCKET .
72 To manipulate options at any
73 other level the protocol number of the appropriate protocol
74 controlling the option is supplied.
75 For example,
76 to indicate that an option is to be interpreted by the
77 .B TCP
78 protocol,
79 .I level
80 should be set to the protocol number of
81 .BR TCP ;
82 see
83 .BR getprotoent (3).
84
85 The arguments
86 .I optval
87 and
88 .I optlen
89 are used to access option values for
90 .BR setsockopt ().
91 For
92 .BR getsockopt ()
93 they identify a buffer in which the value for the
94 requested option(s) are to be returned.
95 For
96 .BR getsockopt (),
97 .I optlen
98 is a value-result argument, initially containing the
99 size of the buffer pointed to by
100 .IR optval ,
101 and modified on return to indicate the actual size of
102 the value returned.
103 If no option value is to be supplied or returned,
104 .I optval
105 may be NULL.
106
107 .I Optname
108 and any specified options are passed uninterpreted to the appropriate
109 protocol module for interpretation.
110 The include file
111 .I <sys/socket.h>
112 contains definitions for socket level options, described below.
113 Options at
114 other protocol levels vary in format and name; consult the appropriate
115 entries in section 4 of the manual.
116
117 Most socket-level options utilize an
118 .I int
119 argument for
120 .IR optval .
121 For
122 .BR setsockopt (),
123 the argument should be nonzero to enable a boolean option, or zero if the
124 option is to be disabled.
125 .PP
126 For a description of the available socket options see
127 .BR socket (7)
128 and the appropriate protocol man pages.
129 .SH "RETURN VALUE"
130 On success, zero is returned.
131 On error, \-1 is returned, and
132 .I errno
133 is set appropriately.
134 .SH ERRORS
135 .TP 10
136 .B EBADF
137 The argument
138 .I sockfd
139 is not a valid descriptor.
140 .TP
141 .B EFAULT
142 The address pointed to by
143 .I optval
144 is not in a valid part of the process address space.
145 For
146 .BR getsockopt (),
147 this error may also be returned if
148 .I optlen
149 is not in a valid part of the process address space.
150 .TP
151 .B EINVAL
152 .I optlen
153 invalid in
154 .BR setsockopt ().
155 In some cases this error can also occur for an invalid value in
156 .IR optval
157 (e.g., for the
158 .B IP_ADD_MEMBERSHIP
159 option described in
160 .BR ip (7)).
161 .TP
162 .B ENOPROTOOPT
163 The option is unknown at the level indicated.
164 .TP
165 .B ENOTSOCK
166 The argument
167 .I sockfd
168 is a file, not a socket.
169 .SH "CONFORMING TO"
170 SVr4, 4.4BSD (these system calls first appeared in 4.2BSD),
171 POSIX.1-2001.
172 .\" SVr4 documents additional ENOMEM and ENOSR error codes, but does
173 .\" not document the
174 .\" .BR SO_SNDLOWAT ", " SO_RCVLOWAT ", " SO_SNDTIMEO ", " SO_RCVTIMEO
175 .\" options
176 .SH NOTES
177 POSIX.1-2001 does not require the inclusion of
178 .IR <sys/types.h> ,
179 and this header file is not required on Linux.
180 However, some historical (BSD) implementations required this header
181 file, and portable applications are probably wise to include it.
182
183 The
184 .I optlen
185 argument of
186 .BR getsockopt ()
187 and
188 .BR setsockopt ()
189 is in reality an
190 .I "int [*]"
191 (and this is what 4.x BSD and libc4 and libc5 have).
192 Some POSIX confusion resulted in the present
193 .IR socklen_t ,
194 also used by glibc.
195 See also
196 .BR accept (2).
197 .SH BUGS
198 Several of the socket options should be handled at lower levels of the
199 system.
200 .SH "SEE ALSO"
201 .BR ioctl (2),
202 .BR socket (2),
203 .BR getprotoent (3),
204 .BR protocols (5),
205 .BR socket (7),
206 .BR tcp (7),
207 .BR unix (7)