]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/getsockopt.2
ffix
[thirdparty/man-pages.git] / 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 1999-05-24 "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 " s ", int " level ", int " optname ,
52 .BI " void *" optval ", socklen_t *" optlen );
53 .sp
54 .BI "int setsockopt(int " s ", int " level ", int " optname ,
55 .BI " const void *" optval ", socklen_t " optlen );
56 .fi
57 .SH DESCRIPTION
58 .BR getsockopt ()
59 and
60 .BR setsockopt ()
61 manipulate the
62 .I options
63 associated with a socket.
64 Options may exist at multiple
65 protocol levels; they are always present at the uppermost
66 .B socket
67 level.
68
69 When manipulating socket options the level at which the
70 option resides and the name of the option must be specified.
71 To manipulate options at the socket level,
72 .I level
73 is specified as
74 .BR SOL_SOCKET .
75 To manipulate options at any
76 other level the protocol number of the appropriate protocol
77 controlling the option is supplied.
78 For example,
79 to indicate that an option is to be interpreted by the
80 .B TCP
81 protocol,
82 .I level
83 should be set to the protocol number of
84 .BR TCP ;
85 see
86 .BR getprotoent (3).
87
88 The parameters
89 .I optval
90 and
91 .I optlen
92 are used to access option values for
93 .BR setsockopt ().
94 For
95 .BR getsockopt ()
96 they identify a buffer in which the value for the
97 requested option(s) are to be returned.
98 For
99 .BR getsockopt (),
100 .I optlen
101 is a value-result parameter, initially containing the
102 size of the buffer pointed to by
103 .IR optval ,
104 and modified on return to indicate the actual size of
105 the value returned.
106 If no option value is to be supplied or returned,
107 .I optval
108 may be NULL.
109
110 .I Optname
111 and any specified options are passed uninterpreted to the appropriate
112 protocol module for interpretation.
113 The include file
114 .I <sys/socket.h>
115 contains definitions for socket level options, described below.
116 Options at
117 other protocol levels vary in format and name; consult the appropriate
118 entries in section 4 of the manual.
119
120 Most socket-level options utilize an
121 .I int
122 parameter for
123 .IR optval .
124 For
125 .BR setsockopt (),
126 the parameter should be non-zero to enable a boolean option, or zero if the
127 option is to be disabled.
128 .PP
129 For a description of the available socket options see
130 .BR socket (7)
131 and the appropriate protocol man pages.
132 .SH "RETURN VALUE"
133 On success, zero is returned.
134 On error, \-1 is returned, and
135 .I errno
136 is set appropriately.
137 .SH ERRORS
138 .TP 10
139 .B EBADF
140 The argument
141 .I s
142 is not a valid descriptor.
143 .TP
144 .B EFAULT
145 The address pointed to by
146 .I optval
147 is not in a valid part of the process address space.
148 For
149 .BR getsockopt (),
150 this error may also be returned if
151 .I optlen
152 is not in a valid part of the process address space.
153 .TP
154 .B EINVAL
155 .I optlen
156 invalid in
157 .BR setsockopt ().
158 .TP
159 .B ENOPROTOOPT
160 The option is unknown at the level indicated.
161 .TP
162 .B ENOTSOCK
163 The argument
164 .I s
165 is a file, not a socket.
166 .SH "CONFORMING TO"
167 SVr4, 4.4BSD (these system calls first appeared in 4.2BSD),
168 POSIX.1-2001.
169 .\" SVr4 documents additional ENOMEM and ENOSR error codes, but does
170 .\" not document the
171 .\" .BR SO_SNDLOWAT ", " SO_RCVLOWAT ", " SO_SNDTIMEO ", " SO_RCVTIMEO
172 .\" options
173 .SH NOTES
174 POSIX.1-2001 does not require the inclusion of
175 .IR <sys/types.h> ,
176 and this header file is not required on Linux.
177 However, some historical (BSD) implementations required this header
178 file, and portable applications are probably wise to include it.
179
180 The
181 .I optlen
182 argument of
183 .BR getsockopt ()
184 and
185 .BR setsockopt ()
186 is in reality an
187 .I "int [*]"
188 (and this is what 4.x BSD and libc4 and libc5 have).
189 Some POSIX confusion resulted in the present
190 .IR socklen_t ,
191 also used by glibc.
192 See also
193 .BR accept (2).
194 .SH BUGS
195 Several of the socket options should be handled at lower levels of the
196 system.
197 .SH "SEE ALSO"
198 .BR ioctl (2),
199 .BR socket (2),
200 .BR getprotoent (3),
201 .BR protocols (5),
202 .BR socket (7),
203 .BR tcp (7),
204 .BR unix (7)