1SETSOCKOPT(P)              POSIX Programmer's Manual             SETSOCKOPT(P)
2
3
4

NAME

6       setsockopt - set the socket options
7

SYNOPSIS

9       #include <sys/socket.h>
10
11       int setsockopt(int socket, int level, int option_name,
12              const void *option_value, socklen_t option_len);
13
14

DESCRIPTION

16       The  setsockopt()  function  shall  set  the  option  specified  by the
17       option_name argument, at the protocol  level  specified  by  the  level
18       argument,  to the value pointed to by the option_value argument for the
19       socket associated with the file  descriptor  specified  by  the  socket
20       argument.
21
22       The  level  argument  specifies  the protocol level at which the option
23       resides. To set options at the socket level, specify the level argument
24       as  SOL_SOCKET.  To set options at other levels, supply the appropriate
25       level identifier for the protocol controlling the option. For  example,
26       to indicate that an option is interpreted by the TCP (Transport Control
27       Protocol), set level to IPPROTO_TCP as defined  in  the  <netinet/in.h>
28       header.
29
30       The  option_name  argument  specifies  a  single  option  to  set.  The
31       option_name argument and any specified options are passed uninterpreted
32       to   the   appropriate   protocol   module  for  interpretations.   The
33       <sys/socket.h> header defines the socket-level  options.   The  options
34       are as follows:
35
36       SO_DEBUG
37              Turns on recording of debugging information. This option enables
38              or disables debugging in the underlying protocol  modules.  This
39              option takes an int value. This is a Boolean option.
40
41       SO_BROADCAST
42              Permits  sending  of broadcast messages, if this is supported by
43              the protocol. This option takes an int value. This is a  Boolean
44              option.
45
46       SO_REUSEADDR
47              Specifies  that  the rules used in validating addresses supplied
48              to bind() should allow reuse of local addresses, if this is sup‐
49              ported by the protocol.  This option takes an int value. This is
50              a Boolean option.
51
52       SO_KEEPALIVE
53              Keeps connections active by enabling the  periodic  transmission
54              of  messages,  if this is supported by the protocol. This option
55              takes an int value.
56
57       If the connected socket fails to respond to these messages, the connec‐
58       tion  is  broken and threads writing to that socket are notified with a
59       SIGPIPE signal. This is a Boolean option.
60
61       SO_LINGER
62              Lingers on a close() if data is present.  This  option  controls
63              the  action  taken  when  unsent  messages queue on a socket and
64              close() is performed.  If SO_LINGER is  set,  the  system  shall
65              block  the process during close() until it can transmit the data
66              or until the time expires. If SO_LINGER is  not  specified,  and
67              close()  is  issued,  the  system handles the call in a way that
68              allows the process to continue  as  quickly  as  possible.  This
69              option   takes   a   linger   structure,   as   defined  in  the
70              <sys/socket.h> header, to specify the state of  the  option  and
71              linger interval.
72
73       SO_OOBINLINE
74              Leaves  received  out-of-band  data (data marked urgent) inline.
75              This option takes an int value. This is a Boolean option.
76
77       SO_SNDBUF
78              Sets send buffer size. This option takes an int value.
79
80       SO_RCVBUF
81              Sets receive buffer size. This option takes an int value.
82
83       SO_DONTROUTE
84              Requests that outgoing  messages  bypass  the  standard  routing
85              facilities.   The  destination  shall be on a directly-connected
86              network, and messages are directed to  the  appropriate  network
87              interface  according  to the destination address. The effect, if
88              any, of this option depends on what protocol  is  in  use.  This
89              option takes an int value. This is a Boolean option.
90
91       SO_RCVLOWAT
92              Sets  the  minimum  number  of bytes to process for socket input
93              operations.   The  default  value  for  SO_RCVLOWAT  is  1.   If
94              SO_RCVLOWAT  is  set  to  a larger value, blocking receive calls
95              normally wait until they have received the smaller  of  the  low
96              water  mark value or the requested amount. (They may return less
97              than the low water mark if an error occurs, a signal is  caught,
98              or  the type of data next in the receive queue is different from
99              that returned; for example, out-of-band data.) This option takes
100              an  int  value.   Note  that  not all implementations allow this
101              option to be set.
102
103       SO_RCVTIMEO
104              Sets the timeout value that specifies the maximum amount of time
105              an input function waits until it completes. It accepts a timeval
106              structure with the number of seconds and microseconds specifying
107              the  limit  on  how  long to wait for an input operation to com‐
108              plete. If a receive operation has blocked  for  this  much  time
109              without  receiving  additional data, it shall return with a par‐
110              tial count or errno set to [EAGAIN] or [EWOULDBLOCK] if no  data
111              is  received.  The  default for this option is zero, which indi‐
112              cates that a receive operation shall not time out.  This  option
113              takes  a  timeval  structure.  Note that not all implementations
114              allow this option to be set.
115
116       SO_SNDLOWAT
117              Sets the minimum number of bytes to process  for  socket  output
118              operations.   Non-blocking  output  operations  shall process no
119              data if flow control does not allow the smaller of the send  low
120              water  mark  value  or  the entire request to be processed. This
121              option takes an int value. Note  that  not  all  implementations
122              allow this option to be set.
123
124       SO_SNDTIMEO
125              Sets  the  timeout  value  specifying the amount of time that an
126              output function blocks because flow control prevents  data  from
127              being  sent.  If  a send operation has blocked for this time, it
128              shall return with a partial count or with errno set to  [EAGAIN]
129              or [EWOULDBLOCK] if no data is sent. The default for this option
130              is zero, which indicates that a send operation  shall  not  time
131              out.  This  option stores a timeval structure. Note that not all
132              implementations allow this option to be set.
133
134
135       For Boolean options, 0 indicates that the  option  is  disabled  and  1
136       indicates that the option is enabled.
137
138       Options at other protocol levels vary in format and name.
139

RETURN VALUE

141       Upon  successful completion, setsockopt() shall return 0. Otherwise, -1
142       shall be returned and errno set to indicate the error.
143

ERRORS

145       The setsockopt() function shall fail if:
146
147       EBADF  The socket argument is not a valid file descriptor.
148
149       EDOM   The send and receive timeout values are too big to fit into  the
150              timeout fields in the socket structure.
151
152       EINVAL The specified option is invalid at the specified socket level or
153              the socket has been shut down.
154
155       EISCONN
156              The socket is already connected, and a specified  option  cannot
157              be set while the socket is connected.
158
159       ENOPROTOOPT
160
161              The option is not supported by the protocol.
162
163       ENOTSOCK
164              The socket argument does not refer to a socket.
165
166
167       The setsockopt() function may fail if:
168
169       ENOMEM There  was  insufficient  memory  available for the operation to
170              complete.
171
172       ENOBUFS
173              Insufficient resources are available in the system  to  complete
174              the call.
175
176
177       The following sections are informative.
178

EXAMPLES

180       None.
181

APPLICATION USAGE

183       The  setsockopt()  function  provides  an  application program with the
184       means to control socket behavior. An application program can  use  set‐
185       sockopt()  to allocate buffer space, control timeouts, or permit socket
186       data broadcasts. The <sys/socket.h>  header  defines  the  socket-level
187       options available to setsockopt().
188
189       Options  may  exist  at  multiple  protocol levels. The SO_ options are
190       always present at the uppermost socket level.
191

RATIONALE

193       None.
194

FUTURE DIRECTIONS

196       None.
197

SEE ALSO

199       Sockets , bind() , endprotoent() , getsockopt() , socket() ,  the  Base
200       Definitions    volume    of    IEEE Std 1003.1-2001,    <netinet/in.h>,
201       <sys/socket.h>
202
204       Portions of this text are reprinted and reproduced in  electronic  form
205       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
206       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
207       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
208       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
209       event of any discrepancy between this version and the original IEEE and
210       The Open Group Standard, the original IEEE and The Open Group  Standard
211       is  the  referee document. The original Standard can be obtained online
212       at http://www.opengroup.org/unix/online.html .
213
214
215
216IEEE/The Open Group                  2003                        SETSOCKOPT(P)
Impressum