1GETSOCKOPT(3P)             POSIX Programmer's Manual            GETSOCKOPT(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       getsockopt - get the socket options
13

SYNOPSIS

15       #include <sys/socket.h>
16
17       int getsockopt(int socket, int level, int option_name,
18              void *restrict option_value, socklen_t *restrict option_len);
19
20

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

192       None.
193

APPLICATION USAGE

195       None.
196

RATIONALE

198       None.
199

FUTURE DIRECTIONS

201       None.
202

SEE ALSO

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