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

PROLOG

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

NAME

12       setsockopt - set the socket options
13

SYNOPSIS

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
20

DESCRIPTION

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

RETURN VALUE

147       Upon successful completion, setsockopt() shall return 0. Otherwise,  -1
148       shall be returned and errno set to indicate the error.
149

ERRORS

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

EXAMPLES

186       None.
187

APPLICATION USAGE

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

RATIONALE

199       None.
200

FUTURE DIRECTIONS

202       None.
203

SEE ALSO

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