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