1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" SPDX-License-Identifier: BSD-4-Clause-UC
6 .\" $Id: getsockopt.2,v 1.1 1999/05/24 14:57:04 freitag Exp $
8 .\" Modified Sat Jul 24 16:19:32 1993 by Rik Faith (faith@cs.unc.edu)
9 .\" Modified Mon Apr 22 02:29:06 1996 by Martin Schulze (joey@infodrom.north.de)
10 .\" Modified Tue Aug 27 10:52:51 1996 by Andries Brouwer (aeb@cwi.nl)
11 .\" Modified Thu Jan 23 13:29:34 1997 by Andries Brouwer (aeb@cwi.nl)
12 .\" Modified Sun Mar 28 21:26:46 1999 by Andries Brouwer (aeb@cwi.nl)
13 .\" Modified 1999 by Andi Kleen <ak@muc.de>.
14 .\" Removed most stuff because it is in socket.7 now.
16 .TH getsockopt 2 (date) "Linux man-pages (unreleased)"
18 getsockopt, setsockopt \- get and set options on sockets
21 .RI ( libc ", " \-lc )
24 .B #include <sys/socket.h>
26 .BI "int getsockopt(int " sockfd ", int " level ", int " optname ,
27 .BI " void " optval "[restrict *." optlen ],
28 .BI " socklen_t *restrict " optlen );
29 .BI "int setsockopt(int " sockfd ", int " level ", int " optname ,
30 .BI " const void " optval [. optlen ],
31 .BI " socklen_t " optlen );
37 manipulate options for the socket referred to by the file descriptor
39 Options may exist at multiple
40 protocol levels; they are always present at the uppermost
43 When manipulating socket options, the level at which the
44 option resides and the name of the option must be specified.
45 To manipulate options at the sockets API level,
49 To manipulate options at any
50 other level the protocol number of the appropriate protocol
51 controlling the option is supplied.
53 to indicate that an option is to be interpreted by the
57 should be set to the protocol number of
66 are used to access option values for
70 they identify a buffer in which the value for the
71 requested option(s) are to be returned.
75 is a value-result argument, initially containing the
76 size of the buffer pointed to by
78 and modified on return to indicate the actual size of
80 If no option value is to be supplied or returned,
85 and any specified options are passed uninterpreted to the appropriate
86 protocol module for interpretation.
89 contains definitions for socket level options, described below.
91 other protocol levels vary in format and name; consult the appropriate
92 entries in section 4 of the manual.
94 Most socket-level options utilize an
100 the argument should be nonzero to enable a boolean option, or zero if the
101 option is to be disabled.
103 For a description of the available socket options see
105 and the appropriate protocol man pages.
107 On success, zero is returned for the standard options.
108 On error, \-1 is returned, and
110 is set to indicate the error.
112 Netfilter allows the programmer
113 to define custom socket options with associated handlers; for such
114 options, the return value on success is the value returned by the handler.
120 is not a valid file descriptor.
123 The address pointed to by
125 is not in a valid part of the process address space.
128 this error may also be returned if
130 is not in a valid part of the process address space.
136 In some cases this error can also occur for an invalid value in
144 The option is unknown at the level indicated.
149 does not refer to a socket.
154 SVr4, 4.4BSD (first appeared in 4.2BSD).
155 .\" SVr4 documents additional ENOMEM and ENOSR error codes, but does
157 .\" .BR SO_SNDLOWAT ", " SO_RCVLOWAT ", " SO_SNDTIMEO ", " SO_RCVTIMEO
160 Several of the socket options should be handled at lower levels of the