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