1SETSOCKOPT(3P) POSIX Programmer's Manual SETSOCKOPT(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 setsockopt — set the socket options
13
15 #include <sys/socket.h>
16
17 int setsockopt(int socket, int level, int option_name,
18 const void *option_value, socklen_t option_len);
19
21 The setsockopt() function shall set the option specified by the
22 option_name argument, at the protocol level specified by the level
23 argument, to the value pointed to by the option_value argument for the
24 socket associated with the file descriptor specified by the socket
25 argument.
26
27 The level argument specifies the protocol level at which the option
28 resides. To set options at the socket level, specify the level argument
29 as SOL_SOCKET. To set options at other levels, supply the appropriate
30 level identifier for the protocol controlling the option. For example,
31 to indicate that an option is interpreted by the TCP (Transport Control
32 Protocol), set level to IPPROTO_TCP as defined in the <netinet/in.h>
33 header.
34
35 The option_name argument specifies a single option to set. It can be
36 one of the socket-level options defined in <sys_socket.h> and described
37 in Section 2.10.16, Use of Options. If option_name is equal to SO_RCV‐
38 TIMEO or SO_SNDTIMEO and the implementation supports setting the
39 option, it is unspecified whether the struct timeval pointed to by
40 option_value is stored as provided by this function or is rounded up to
41 align with the resolution of the clock being used. If setsockopt() is
42 called with option_name equal to SO_ACCEPTCONN, SO_ERROR, or SO_TYPE,
43 the behavior is unspecified.
44
46 Upon successful completion, setsockopt() shall return 0. Otherwise, -1
47 shall be returned and errno set to indicate the error.
48
50 The setsockopt() function shall fail if:
51
52 EBADF The socket argument is not a valid file descriptor.
53
54 EDOM The send and receive timeout values are too big to fit into the
55 timeout fields in the socket structure.
56
57 EINVAL The specified option is invalid at the specified socket level or
58 the socket has been shut down.
59
60 EISCONN
61 The socket is already connected, and a specified option cannot
62 be set while the socket is connected.
63
64 ENOPROTOOPT
65 The option is not supported by the protocol.
66
67 ENOTSOCK
68 The socket argument does not refer to a socket.
69
70 The setsockopt() function may fail if:
71
72 ENOMEM There was insufficient memory available for the operation to
73 complete.
74
75 ENOBUFS
76 Insufficient resources are available in the system to complete
77 the call.
78
79 The following sections are informative.
80
82 None.
83
85 The setsockopt() function provides an application program with the
86 means to control socket behavior. An application program can use set‐
87 sockopt() to allocate buffer space, control timeouts, or permit socket
88 data broadcasts. The <sys/socket.h> header defines the socket-level
89 options available to setsockopt().
90
91 Options may exist at multiple protocol levels. The SO_ options are
92 always present at the uppermost socket level.
93
95 None.
96
98 None.
99
101 Section 2.10, Sockets, bind(), endprotoent(), getsockopt(), socket()
102
103 The Base Definitions volume of POSIX.1‐2017, <netinet_in.h>,
104 <sys_socket.h>
105
107 Portions of this text are reprinted and reproduced in electronic form
108 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
109 table Operating System Interface (POSIX), The Open Group Base Specifi‐
110 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
111 Electrical and Electronics Engineers, Inc and The Open Group. In the
112 event of any discrepancy between this version and the original IEEE and
113 The Open Group Standard, the original IEEE and The Open Group Standard
114 is the referee document. The original Standard can be obtained online
115 at http://www.opengroup.org/unix/online.html .
116
117 Any typographical or formatting errors that appear in this page are
118 most likely to have been introduced during the conversion of the source
119 files to man page format. To report such errors, see https://www.ker‐
120 nel.org/doc/man-pages/reporting_bugs.html .
121
122
123
124IEEE/The Open Group 2017 SETSOCKOPT(3P)