1setsockopt(3XNET)X/Open Networking Services Library Functionssetsockopt(3XNET)
2
3
4

NAME

6       setsockopt - set the socket options
7

SYNOPSIS

9       cc [ flag... ] file... -lxnet [ library... ]
10       #include <sys/socket.h>
11
12       int setsockopt(int socket, int level, int option_name,
13            const void*option_value, socklen_t option_len);
14
15

DESCRIPTION

17       The  setsockopt() function sets the option specified by the option_name
18       argument, at the protocol level specified by the level argument, to the
19       value pointed to by the option_value argument for the socket associated
20       with the file descriptor specified by the socket argument.
21
22
23       The level argument specifies the protocol level  at  which  the  option
24       resides.   To  set options at the socket level, specify the level argu‐
25       ment as SOL_SOCKET.  To set options at other levels, supply the  appro‐
26       priate  protocol  number  for the protocol controlling the option.  For
27       example, to indicate that an option will  be  interpreted  by  the  TCP
28       (Transport  Control Protocol), set level to the protocol number of TCP,
29       as defined in the<netinet/in.h> header, or as determined by using  get‐
30       protobyname(3XNET).
31
32
33       The  option_name  argument  specifies  a  single  option  to  set.  The
34       option_name argument and any specified options are passed uninterpreted
35       to   the   appropriate   protocol   module   for  interpretations.  The
36       <sys/socket.h> header defines the socket level options. The options are
37       as follow
38
39       SO_DEBUG         Turns  on  recording  of  debugging information.  This
40                        option enables or disables debugging in the underlying
41                        protocol  modules.   This  option  takes an int value.
42                        This is a boolean option.
43
44
45       SO_BROADCAST     Permits sending of broadcast messages, if this is sup‐
46                        ported  by  the  protocol.  This  option  takes an int
47                        value. This is a boolean option.
48
49
50       SO_REUSEADDR     Specifies that the rules used in validating  addresses
51                        supplied  to  bind(3XNET)  should allow reuse of local
52                        addresses, if this is supported by the protocol.  This
53                        option takes an int value. This is a boolean option.
54
55
56       SO_KEEPALIVE     Keeps  connections  active  by  enabling  the periodic
57                        transmission of messages, if this is supported by  the
58                        protocol.  This option takes an int value.
59
60                        If the connected socket fails to respond to these mes‐
61                        sages, the connection is broken and threads writing to
62                        that socket are notified with a SIGPIPE signal.
63
64                        This is a boolean option.
65
66
67       SO_LINGER        Lingers on a close(2) if data is present.  This option
68                        controls the action taken when unsent  messages  queue
69                        on  a  socket and close(2) is performed.  If SO_LINGER
70                        is set, the system blocks the process during  close(2)
71                        until  it  can  transmit  the  data  or until the time
72                        expires.  If SO_LINGER is not specified, and  close(2)
73                        is  issued,  the system handles the call in a way that
74                        allows the process to continue as quickly as possible.
75                        This  option  takes  a linger structure, as defined in
76                        the <sys/socket.h> header, to specify the state of the
77                        option and linger interval.
78
79
80       SO_OOBINLINE     Leaves  received out-of-band data (data marked urgent)
81                        in line. This option takes an int  value.  This  is  a
82                        boolean option.
83
84
85       SO_SNDBUF        Sets  send  buffer  size.   This  option  takes an int
86                        value.
87
88
89       SO_RCVBUF        Sets receive buffer size. This  option  takes  an  int
90                        value.
91
92
93       SO_DONTROUTE     Requests  that  outgoing  messages bypass the standard
94                        routing facilities.  The  destination  must  be  on  a
95                        directly-connected  network, and messages are directed
96                        to the appropriate network interface according to  the
97                        destination  address.  The  effect,  if  any,  of this
98                        option depends on what protocol is in use. This option
99                        takes an int value. This is a boolean option.
100
101
102       SO_MAC_EXEMPT    Sets  the  mandatory  access  control on the socket. A
103                        socket that has this option  enabled  can  communicate
104                        with  an unlabeled peer if the socket is in the global
105                        zone or has a label that dominates the  default  label
106                        of  the  peer. Otherwise, the socket must have a label
107                        that is equal to the default label  of  the  unlabeled
108                        peer. SO_MAC_EXEMPT is a boolean option that is avail‐
109                        able only when the system is configured  with  Trusted
110                        Extensions.
111
112
113       SO_ALLZONES      Bypasses  zone  boundaries  (privileged).  This option
114                        stores an int value. This is a boolean option.
115
116                        The SO_ALLZONES option can  be  used  to  bypass  zone
117                        boundaries between shared-IP zones. Normally, the sys‐
118                        tem prevents a socket from being bound to  an  address
119                        that is not assigned to the current zone. It also pre‐
120                        vents a socket that is bound  to  a  wildcard  address
121                        from  receiving traffic for other zones. However, some
122                        daemons which run in the global  zone  might  need  to
123                        send  and  receive traffic using addresses that belong
124                        to other shared-IP zones. If set before  a  socket  is
125                        bound,  SO_ALLZONES  causes  the socket to ignore zone
126                        boundaries between shared-IP  zones  and  permits  the
127                        socket  to  be  bound  to  any address assigned to the
128                        shared-IP zones. If the socket is bound to a  wildcard
129                        address,  it receives traffic intended for all shared-
130                        IP zones and behaves as if an equivalent  socket  were
131                        bound in each active shared-IP zone. Applications that
132                        use the SO_ALLZONES option to initiate connections  or
133                        send   datagram  traffic  should  specify  the  source
134                        address for outbound traffic by binding to a  specific
135                        address.  There  is no effect from setting this option
136                        in an exclusive-IP zone. Setting this option  requires
137                        the sys_net_config privilege. See zones(5).
138
139
140
141       For  boolean  options,  0  indicates  that the option is disabled and 1
142       indicates that the option is enabled.
143
144
145       Options at other protocol levels vary in format and name.
146

USAGE

148       The setsockopt() function provides  an  application  program  with  the
149       means  to control socket behavior.  An application program can use set‐
150       sockopt() to allocate buffer space, control timeouts, or permit  socket
151       data  broadcasts.   The  <sys/socket.h> header defines the socket-level
152       options available to setsockopt().
153
154
155       Options may exist at multiple protocol  levels.  The  SO_  options  are
156       always present at the uppermost socket level.
157

RETURN VALUES

159       Upon  successful  completion,  setsockopt() returns 0. Otherwise, -1 is
160       returned and errno is set to indicate the error.
161

ERRORS

163       The setsockopt() function will fail if:
164
165       EBADF          The socket argument is not a valid file descriptor.
166
167
168       EDOM           The send and receive timeout values are too big  to  fit
169                      into the timeout fields in the socket structure.
170
171
172       EFAULT         The  option_value parameter can not be accessed or writ‐
173                      ten.
174
175
176       EINVAL         The specified option is invalid at the specified  socket
177                      level or the socket has been shut down.
178
179
180       EISCONN        The socket is already connected, and a  specified option
181                      can not be set while the socket is connected.
182
183
184       ENOPROTOOPT    The option is not supported by the protocol.
185
186
187       ENOTSOCK       The socket argument does not refer to a socket.
188
189
190
191       The setsockopt() function may fail if:
192
193       ENOMEM     There was insufficient memory available for the operation to
194                  complete.
195
196
197       ENOBUFS    Insufficient  resources  are available in the system to com‐
198                  plete the call.
199
200
201       ENOSR      There were insufficient STREAMS resources available for  the
202                  operation to complete.
203
204

ATTRIBUTES

206       See attributes(5) for descriptions of the following attributes:
207
208
209
210
211       ┌─────────────────────────────┬─────────────────────────────┐
212       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
213       ├─────────────────────────────┼─────────────────────────────┤
214       │Interface Stability          │Standard                     │
215       ├─────────────────────────────┼─────────────────────────────┤
216       │MT-Level                     │MT-Safe                      │
217       └─────────────────────────────┴─────────────────────────────┘
218

SEE ALSO

220       bind(3XNET),   endprotoent(3XNET),   getsockopt(3XNET),  socket(3XNET),
221       attributes(5), standards(5)
222
223
224
225SunOS 5.11                        21 Jan 2007                setsockopt(3XNET)
Impressum