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

NAME

6       getsockopt - get the socket options
7

SYNOPSIS

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

DESCRIPTION

16       The getsockopt() function manipulates options associated with a socket.
17
18       The getsockopt() function shall retrieve the value for the option spec‐
19       ified by the option_name argument  for  the  socket  specified  by  the
20       socket  argument.  If  the  size  of  the  option value is greater than
21       option_len,  the  value  stored  in  the  object  pointed  to  by   the
22       option_value  argument  shall  be  silently  truncated.  Otherwise, the
23       object pointed to by the option_len argument shall be modified to indi‐
24       cate the actual length of the value.
25
26       The  level  argument  specifies  the protocol level at which the option
27       resides. To retrieve options at the socket  level,  specify  the  level
28       argument as SOL_SOCKET. To retrieve options at other levels, supply the
29       appropriate level identifier for the protocol controlling  the  option.
30       For  example,  to  indicate  that  an  option is interpreted by the TCP
31       (Transmission Control Protocol), set level to IPPROTO_TCP as defined in
32       the <netinet/in.h> header.
33
34       The  socket  in  use may require the process to have appropriate privi‐
35       leges to use the getsockopt() function.
36
37       The option_name argument specifies a single option to be retrieved.  It
38       can be one of the following values defined in <sys/socket.h>:
39
40       SO_DEBUG
41              Reports  whether  debugging  information is being recorded. This
42              option shall store an int value. This is a Boolean option.
43
44       SO_ACCEPTCONN
45              Reports whether socket listening is enabled. This  option  shall
46              store an int value. This is a Boolean option.
47
48       SO_BROADCAST
49              Reports whether transmission of broadcast messages is supported,
50              if this is supported by the protocol. This option shall store an
51              int value. This is a Boolean option.
52
53       SO_REUSEADDR
54              Reports  whether the rules used in validating addresses supplied
55              to bind() should allow reuse of local addresses, if this is sup‐
56              ported  by  the protocol.  This option shall store an int value.
57              This is a Boolean option.
58
59       SO_KEEPALIVE
60              Reports whether connections are kept active with periodic trans‐
61              mission of messages, if this is supported by the protocol.
62
63       If the connected socket fails to respond to these messages, the connec‐
64       tion shall be broken and threads writing to that socket shall be  noti‐
65       fied  with a SIGPIPE signal. This option shall store an int value. This
66       is a Boolean option.
67
68       SO_LINGER
69              Reports whether  the  socket  lingers  on  close()  if  data  is
70              present.   If  SO_LINGER  is  set, the system blocks the process
71              during close() until it can transmit the data or until  the  end
72              of  the  interval  indicated  by  the l_linger member, whichever
73              comes first. If SO_LINGER  is  not  specified,  and  close()  is
74              issued,  the  system  handles  the call in a way that allows the
75              process to continue as quickly as possible.  This  option  shall
76              store a linger structure.
77
78       SO_OOBINLINE
79              Reports  whether  the  socket  leaves  received out-of-band data
80              (data marked urgent) inline. This  option  shall  store  an  int
81              value. This is a Boolean option.
82
83       SO_SNDBUF
84              Reports send buffer size information. This option shall store an
85              int value.
86
87       SO_RCVBUF
88              Reports receive buffer size information. This option shall store
89              an int value.
90
91       SO_ERROR
92              Reports  information  about  error  status  and  clears it. This
93              option shall store an int value.
94
95       SO_TYPE
96              Reports the socket type. This option shall store an  int  value.
97              Socket types are described in Socket Types .
98
99       SO_DONTROUTE
100              Reports  whether  outgoing  messages bypass the standard routing
101              facilities.  The destination shall be  on  a  directly-connected
102              network,  and  messages  are directed to the appropriate network
103              interface according to the destination address. The  effect,  if
104              any,  of  this  option  depends on what protocol is in use. This
105              option shall store an int value. This is a Boolean option.
106
107       SO_RCVLOWAT
108              Reports the minimum number of bytes to process for socket  input
109              operations.    The  default  value  for  SO_RCVLOWAT  is  1.  If
110              SO_RCVLOWAT is set to a larger  value,  blocking  receive  calls
111              normally  wait  until  they have received the smaller of the low
112              water mark value or the requested amount. (They may return  less
113              than  the low water mark if an error occurs, a signal is caught,
114              or the type of data next in the receive queue is different  from
115              that returned; for example, out-of-band data.) This option shall
116              store an int value. Note that not all implementations allow this
117              option to be retrieved.
118
119       SO_RCVTIMEO
120              Reports  the  timeout  value  for  input operations. This option
121              shall store a timeval structure with the number of  seconds  and
122              microseconds  specifying  the  limit  on how long to wait for an
123              input operation to complete. If a receive operation has  blocked
124              for  this  much time without receiving additional data, it shall
125              return with a partial count or errno set to [EAGAIN] or [EWOULD‐
126              BLOCK]  if  no data was received. The default for this option is
127              zero, which indicates that a receive operation  shall  not  time
128              out.  Note  that not all implementations allow this option to be
129              retrieved.
130
131       SO_SNDLOWAT
132              Reports the minimum number of bytes to process for socket output
133              operations.   Non-blocking  output  operations  shall process no
134              data if flow control does not allow the smaller of the send  low
135              water  mark  value  or  the entire request to be processed. This
136              option shall store an int value. Note that not  all  implementa‐
137              tions allow this option to be retrieved.
138
139       SO_SNDTIMEO
140              Reports  the timeout value specifying the amount of time that an
141              output function blocks because flow control prevents  data  from
142              being  sent.  If  a send operation has blocked for this time, it
143              shall return with a partial count or with errno set to  [EAGAIN]
144              or  [EWOULDBLOCK]  if  no  data  was  sent. The default for this
145              option is zero, which indicates that a send operation shall  not
146              time  out. The option shall store a timeval structure. Note that
147              not all implementations allow this option to be retrieved.
148
149
150       For Boolean options, a zero value indicates that the option is disabled
151       and a non-zero value indicates that the option is enabled.
152

RETURN VALUE

154       Upon  successful completion, getsockopt() shall return 0; otherwise, -1
155       shall be returned and errno set to indicate the error.
156

ERRORS

158       The getsockopt() function shall fail if:
159
160       EBADF  The socket argument is not a valid file descriptor.
161
162       EINVAL The specified option is invalid at the specified socket level.
163
164       ENOPROTOOPT
165
166              The option is not supported by the protocol.
167
168       ENOTSOCK
169              The socket argument does not refer to a socket.
170
171
172       The getsockopt() function may fail if:
173
174       EACCES The calling process does not have the appropriate privileges.
175
176       EINVAL The socket has been shut down.
177
178       ENOBUFS
179              Insufficient resources are available in the system  to  complete
180              the function.
181
182
183       The following sections are informative.
184

EXAMPLES

186       None.
187

APPLICATION USAGE

189       None.
190

RATIONALE

192       None.
193

FUTURE DIRECTIONS

195       None.
196

SEE ALSO

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