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 2021-03-22 "Linux" "Linux Programmer's Manual"
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 *restrict " optval ", socklen_t *restrict " optlen );
28 .BI "int setsockopt(int " sockfd ", int " level ", int " optname ,
29 .BI " const void *" optval ", socklen_t " optlen );
35 manipulate options for the socket referred to by the file descriptor
37 Options may exist at multiple
38 protocol levels; they are always present at the uppermost
41 When manipulating socket options, the level at which the
42 option resides and the name of the option must be specified.
43 To manipulate options at the sockets API level,
47 To manipulate options at any
48 other level the protocol number of the appropriate protocol
49 controlling the option is supplied.
51 to indicate that an option is to be interpreted by the
55 should be set to the protocol number of
64 are used to access option values for
68 they identify a buffer in which the value for the
69 requested option(s) are to be returned.
73 is a value-result argument, initially containing the
74 size of the buffer pointed to by
76 and modified on return to indicate the actual size of
78 If no option value is to be supplied or returned,
83 and any specified options are passed uninterpreted to the appropriate
84 protocol module for interpretation.
87 contains definitions for socket level options, described below.
89 other protocol levels vary in format and name; consult the appropriate
90 entries in section 4 of the manual.
92 Most socket-level options utilize an
98 the argument should be nonzero to enable a boolean option, or zero if the
99 option is to be disabled.
101 For a description of the available socket options see
103 and the appropriate protocol man pages.
105 On success, zero is returned for the standard options.
106 On error, \-1 is returned, and
108 is set to indicate the error.
110 Netfilter allows the programmer
111 to define custom socket options with associated handlers; for such
112 options, the return value on success is the value returned by the handler.
118 is not a valid file descriptor.
121 The address pointed to by
123 is not in a valid part of the process address space.
126 this error may also be returned if
128 is not in a valid part of the process address space.
134 In some cases this error can also occur for an invalid value in
142 The option is unknown at the level indicated.
147 does not refer to a socket.
149 POSIX.1-2001, POSIX.1-2008,
150 SVr4, 4.4BSD (these system calls first appeared in 4.2BSD).
151 .\" SVr4 documents additional ENOMEM and ENOSR error codes, but does
153 .\" .BR SO_SNDLOWAT ", " SO_RCVLOWAT ", " SO_SNDTIMEO ", " SO_RCVTIMEO
156 For background on the
161 Several of the socket options should be handled at lower levels of the