]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/socket.7
socket.7: Put SO_PEEK_OFF in correct alphabetical order
[thirdparty/man-pages.git] / man7 / socket.7
1 '\" t
2 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
3 .\" and copyright (c) 1999 Matthew Wilcox.
4 .\"
5 .\" %%%LICENSE_START(VERBATIM_ONE_PARA)
6 .\" Permission is granted to distribute possibly modified copies
7 .\" of this page provided the header is included verbatim,
8 .\" and in case of nontrivial modification author and date
9 .\" of the modification is added to the header.
10 .\" %%%LICENSE_END
11 .\"
12 .\" 2002-10-30, Michael Kerrisk, <mtk.manpages@gmail.com>
13 .\" Added description of SO_ACCEPTCONN
14 .\" 2004-05-20, aeb, added SO_RCVTIMEO/SO_SNDTIMEO text.
15 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
16 .\" Added notes on capability requirements
17 .\" A few small grammar fixes
18 .\" 2010-06-13 Jan Engelhardt <jengelh@medozas.de>
19 .\" Documented SO_DOMAIN and SO_PROTOCOL.
20 .\" FIXME
21 .\" The following are not yet documented:
22 .\" SO_PEERNAME (2.4?)
23 .\" get only
24 .\" Seems to do something similar to getpeernam(), but then
25 .\" why is it necessary / how does it differ?
26 .\" SO_TIMESTAMPNS (2.6.22)
27 .\" Documentation/networking/timestamping.txt
28 .\" commit 92f37fd2ee805aa77925c1e64fd56088b46094fc
29 .\" Author: Eric Dumazet <dada1@cosmosbay.com>
30 .\" SO_TIMESTAMPING (2.6.30)
31 .\" Documentation/networking/timestamping.txt
32 .\" commit cb9eff097831007afb30d64373f29d99825d0068
33 .\" Author: Patrick Ohly <patrick.ohly@intel.com>
34 .\" SO_RXQ_OVFL (2.6.33)
35 .\" commit 3b885787ea4112eaa80945999ea0901bf742707f
36 .\" Author: Neil Horman <nhorman@tuxdriver.com>
37 .\" SO_WIFI_STATUS (3.3)
38 .\" commit 6e3e939f3b1bf8534b32ad09ff199d88800835a0
39 .\" Author: Johannes Berg <johannes.berg@intel.com>
40 .\" Also: SCM_WIFI_STATUS
41 .\" SO_NOFCS (3.4)
42 .\" commit 3bdc0eba0b8b47797f4a76e377dd8360f317450f
43 .\" Author: Ben Greear <greearb@candelatech.com>
44 .\"
45 .TH SOCKET 7 2013-04-17 Linux "Linux Programmer's Manual"
46 .SH NAME
47 socket \- Linux socket interface
48 .SH SYNOPSIS
49 .B #include <sys/socket.h>
50 .sp
51 .IB sockfd " = socket(int " socket_family ", int " socket_type ", int " protocol );
52 .SH DESCRIPTION
53 This manual page describes the Linux networking socket layer user
54 interface.
55 The BSD compatible sockets
56 are the uniform interface
57 between the user process and the network protocol stacks in the kernel.
58 The protocol modules are grouped into
59 .I protocol families
60 like
61 .BR AF_INET ", " AF_IPX ", " AF_PACKET
62 and
63 .I socket types
64 like
65 .B SOCK_STREAM
66 or
67 .BR SOCK_DGRAM .
68 See
69 .BR socket (2)
70 for more information on families and types.
71 .SS Socket-layer functions
72 These functions are used by the user process to send or receive packets
73 and to do other socket operations.
74 For more information see their respective manual pages.
75
76 .BR socket (2)
77 creates a socket,
78 .BR connect (2)
79 connects a socket to a remote socket address,
80 the
81 .BR bind (2)
82 function binds a socket to a local socket address,
83 .BR listen (2)
84 tells the socket that new connections shall be accepted, and
85 .BR accept (2)
86 is used to get a new socket with a new incoming connection.
87 .BR socketpair (2)
88 returns two connected anonymous sockets (implemented only for a few
89 local families like
90 .BR AF_UNIX )
91 .PP
92 .BR send (2),
93 .BR sendto (2),
94 and
95 .BR sendmsg (2)
96 send data over a socket, and
97 .BR recv (2),
98 .BR recvfrom (2),
99 .BR recvmsg (2)
100 receive data from a socket.
101 .BR poll (2)
102 and
103 .BR select (2)
104 wait for arriving data or a readiness to send data.
105 In addition, the standard I/O operations like
106 .BR write (2),
107 .BR writev (2),
108 .BR sendfile (2),
109 .BR read (2),
110 and
111 .BR readv (2)
112 can be used to read and write data.
113 .PP
114 .BR getsockname (2)
115 returns the local socket address and
116 .BR getpeername (2)
117 returns the remote socket address.
118 .BR getsockopt (2)
119 and
120 .BR setsockopt (2)
121 are used to set or get socket layer or protocol options.
122 .BR ioctl (2)
123 can be used to set or read some other options.
124 .PP
125 .BR close (2)
126 is used to close a socket.
127 .BR shutdown (2)
128 closes parts of a full-duplex socket connection.
129 .PP
130 Seeking, or calling
131 .BR pread (2)
132 or
133 .BR pwrite (2)
134 with a nonzero position is not supported on sockets.
135 .PP
136 It is possible to do nonblocking I/O on sockets by setting the
137 .B O_NONBLOCK
138 flag on a socket file descriptor using
139 .BR fcntl (2).
140 Then all operations that would block will (usually)
141 return with
142 .B EAGAIN
143 (operation should be retried later);
144 .BR connect (2)
145 will return
146 .B EINPROGRESS
147 error.
148 The user can then wait for various events via
149 .BR poll (2)
150 or
151 .BR select (2).
152 .TS
153 tab(:) allbox;
154 c s s
155 l l l.
156 I/O events
157 Event:Poll flag:Occurrence
158 Read:POLLIN:T{
159 New data arrived.
160 T}
161 Read:POLLIN:T{
162 A connection setup has been completed
163 (for connection-oriented sockets)
164 T}
165 Read:POLLHUP:T{
166 A disconnection request has been initiated by the other end.
167 T}
168 Read:POLLHUP:T{
169 A connection is broken (only for connection-oriented protocols).
170 When the socket is written
171 .B SIGPIPE
172 is also sent.
173 T}
174 Write:POLLOUT:T{
175 Socket has enough send buffer space for writing new data.
176 T}
177 Read/Write:T{
178 POLLIN|
179 .br
180 POLLOUT
181 T}:T{
182 An outgoing
183 .BR connect (2)
184 finished.
185 T}
186 Read/Write:POLLERR:An asynchronous error occurred.
187 Read/Write:POLLHUP:The other end has shut down one direction.
188 Exception:POLLPRI:T{
189 Urgent data arrived.
190 .B SIGURG
191 is sent then.
192 T}
193 .\" FIXME . The following is not true currently:
194 .\" It is no I/O event when the connection
195 .\" is broken from the local end using
196 .\" .BR shutdown (2)
197 .\" or
198 .\" .BR close (2).
199 .TE
200 .PP
201 An alternative to
202 .BR poll (2)
203 and
204 .BR select (2)
205 is to let the kernel inform the application about events
206 via a
207 .B SIGIO
208 signal.
209 For that the
210 .B O_ASYNC
211 flag must be set on a socket file descriptor via
212 .BR fcntl (2)
213 and a valid signal handler for
214 .B SIGIO
215 must be installed via
216 .BR sigaction (2).
217 See the
218 .I Signals
219 discussion below.
220 .SS Socket address structures
221 Each socket domain has its own format for socket addresses,
222 with a domain-specific address structure.
223 Each of these structures begins with an
224 integer "family" field (typed as
225 .IR sa_family_t )
226 that indicates the type of the address structure.
227 This allows
228 the various system calls (e.g.,
229 .BR connect (2),
230 .BR bind (2),
231 .BR accept (2),
232 .BR getsockname (2),
233 .BR getpeername (2)),
234 which are generic to all socket domains,
235 to determine the domain of a particular socket address.
236
237 To allow any type of socket address to be passed to
238 interfaces in the sockets API,
239 the type
240 .IR "struct sockaddr"
241 is defined.
242 The purpose of this type is purely to allow casting of
243 domain-specific socket address types to a "generic" type,
244 so as to avoid compiler warnings about type mismatches in
245 calls to the sockets API.
246
247 In addition, the sockets API provides the data type
248 .IR "struct sockaddr_storage".
249 This type
250 is suitable to accommodate all supported domain-specific socket
251 address structures; it is large enough and is aligned properly.
252 (In particular, it is large enough to hold
253 IPv6 socket addresses.)
254 The structure includes the following field, which can be used to identify
255 the type of socket address actually stored in the structure:
256
257 .in +4n
258 .nf
259 sa_family_t ss_family;
260 .fi
261 .in
262
263 The
264 .I sockaddr_storage
265 structure is useful in programs that must handle socket addresses
266 in a generic way
267 (e.g., programs that must deal with both IPv4 and IPv6 socket addresses).
268 .SS Socket options
269 These socket options can be set by using
270 .BR setsockopt (2)
271 and read with
272 .BR getsockopt (2)
273 with the socket level set to
274 .B SOL_SOCKET
275 for all sockets:
276 .\" FIXME
277 .\" In the list below, the text used to describe argument types
278 .\" for each socket option should be more consistent
279 .\"
280 .\" SO_ACCEPTCONN is in POSIX.1-2001, and its origin is explained in
281 .\" W R Stevens, UNPv1
282 .TP
283 .B SO_ACCEPTCONN
284 Returns a value indicating whether or not this socket has been marked
285 to accept connections with
286 .BR listen (2).
287 The value 0 indicates that this is not a listening socket,
288 the value 1 indicates that this is a listening socket.
289 This socket option is read-only.
290 .TP
291 .B SO_BINDTODEVICE
292 Bind this socket to a particular device like \(lqeth0\(rq,
293 as specified in the passed interface name.
294 If the
295 name is an empty string or the option length is zero, the socket device
296 binding is removed.
297 The passed option is a variable-length null-terminated
298 interface name string with the maximum size of
299 .BR IFNAMSIZ .
300 If a socket is bound to an interface,
301 only packets received from that particular interface are processed by the
302 socket.
303 Note that this works only for some socket types, particularly
304 .B AF_INET
305 sockets.
306 It is not supported for packet sockets (use normal
307 .BR bind (2)
308 there).
309
310 Before Linux 3.8,
311 this socket option could be set, but could not retrieved with
312 .BR getsockopt (2).
313 Since Linux 3.8, it is readable.
314 The
315 .I optlen
316 argument should contain the buffer size available
317 to receive the device name and is recommended to be
318 .BR IFNAMSZ
319 bytes.
320 The real device name length is reported back in the
321 .I optlen
322 argument.
323 .TP
324 .B SO_BROADCAST
325 Set or get the broadcast flag.
326 When enabled, datagram sockets are allowed to send
327 packets to a broadcast address.
328 This option has no effect on stream-oriented sockets.
329 .TP
330 .B SO_BSDCOMPAT
331 Enable BSD bug-to-bug compatibility.
332 This is used by the UDP protocol module in Linux 2.0 and 2.2.
333 If enabled ICMP errors received for a UDP socket will not be passed
334 to the user program.
335 In later kernel versions, support for this option has been phased out:
336 Linux 2.4 silently ignores it, and Linux 2.6 generates a kernel warning
337 (printk()) if a program uses this option.
338 Linux 2.0 also enabled BSD bug-to-bug compatibility
339 options (random header changing, skipping of the broadcast flag) for raw
340 sockets with this option, but that was removed in Linux 2.2.
341 .TP
342 .B SO_DEBUG
343 Enable socket debugging.
344 Only allowed for processes with the
345 .B CAP_NET_ADMIN
346 capability or an effective user ID of 0.
347 .TP
348 .BR SO_DOMAIN " (since Linux 2.6.32)"
349 Retrieves the socket domain as an integer, returning a value such as
350 .BR AF_INET6 .
351 See
352 .BR socket (2)
353 for details.
354 This socket option is read-only.
355 .TP
356 .B SO_ERROR
357 Get and clear the pending socket error.
358 This socket option is read-only.
359 Expects an integer.
360 .TP
361 .B SO_DONTROUTE
362 Don't send via a gateway, send only to directly connected hosts.
363 The same effect can be achieved by setting the
364 .B MSG_DONTROUTE
365 flag on a socket
366 .BR send (2)
367 operation.
368 Expects an integer boolean flag.
369 .TP
370 .B SO_KEEPALIVE
371 Enable sending of keep-alive messages on connection-oriented sockets.
372 Expects an integer boolean flag.
373 .TP
374 .B SO_LINGER
375 Sets or gets the
376 .B SO_LINGER
377 option.
378 The argument is a
379 .I linger
380 structure.
381 .sp
382 .in +4n
383 .nf
384 struct linger {
385 int l_onoff; /* linger active */
386 int l_linger; /* how many seconds to linger for */
387 };
388 .fi
389 .in
390 .IP
391 When enabled, a
392 .BR close (2)
393 or
394 .BR shutdown (2)
395 will not return until all queued messages for the socket have been
396 successfully sent or the linger timeout has been reached.
397 Otherwise,
398 the call returns immediately and the closing is done in the background.
399 When the socket is closed as part of
400 .BR exit (2),
401 it always lingers in the background.
402 .TP
403 .BR SO_MARK " (since Linux 2.6.25)"
404 .\" commit 4a19ec5800fc3bb64e2d87c4d9fdd9e636086fe0
405 .\" and 914a9ab386a288d0f22252fc268ecbc048cdcbd5
406 Set the mark for each packet sent through this socket
407 (similar to the netfilter MARK target but socket-based).
408 Changing the mark can be used for mark-based
409 routing without netfilter or for packet filtering.
410 Setting this option requires the
411 .B CAP_NET_ADMIN
412 capability.
413 .TP
414 .B SO_OOBINLINE
415 If this option is enabled,
416 out-of-band data is directly placed into the receive data stream.
417 Otherwise out-of-band data is passed only when the
418 .B MSG_OOB
419 flag is set during receiving.
420 .\" don't document it because it can do too much harm.
421 .\".B SO_NO_CHECK
422 .TP
423 .B SO_PASSCRED
424 Enable or disable the receiving of the
425 .B SCM_CREDENTIALS
426 control message.
427 For more information see
428 .BR unix (7).
429 .\" FIXME Document SO_PASSSEC, added in 2.6.18; there is some info
430 .\" in the 2.6.18 ChangeLog
431 .TP
432 .BR SO_PEEK_OFF " (since Linux 3.4)"
433 .\" commit ef64a54f6e558155b4f149bb10666b9e914b6c54
434 This option, which is currently supported only for
435 .BR unix (7)
436 sockets, sets the value of the "peek offset" for the
437 .BR recv(2)
438 system call when used with
439 .BR MSG_PEEK
440 flag.
441
442 When this option is set to a negative value
443 (it is set to \-1 for all new sockets),
444 traditional behavior is provided:
445 .BR recv(2)
446 with the
447 .BR MSG_PEEK
448 flag will peek data from the front of the queue.
449
450 When the option is set to a value greater than or equal to zero,
451 then the next peek at data queued in the socket will occur at
452 the byte offset specified by the option value.
453 At the same time, the "peek offset" will be
454 incremented by the number of bytes that were peeked from the queue,
455 so that a subsequent peek will return the next data in the queue.i
456
457 If data is removed from the front of the queue via a call to
458 .BR recv (2)
459 (or similar) without the
460 .BR MSG_PEEK
461 flag, the "peek offset" will be decreased by the number of bytes removed.
462 In other words, receiving data without the
463 .B MSG_PEEK
464 flag will cause the "peek offset" to be adjusted to maintain
465 the correct relative position in the queued data,
466 so that a subsequent peek will retrieve the data that would have been
467 retrieved had the data not been removed.
468
469 For datagram sockets, if the "peek offset" points to the middle of a packet,
470 the data returned will be marked with the
471 .BR MSG_TRUNC
472 flag.
473
474 The following example serves to illustrate the use of
475 .BR SO_PEEK_OFF .
476 Suppose a stream socket has the following queued input data:
477
478 aabbccddeeff
479
480 .IP
481 The following sequence of
482 .BR recv (2)
483 calls would have the effect noted in the comments:
484
485 .in +4n
486 .nf
487 int ov = 4; // Set peek offset to 4
488 setsockopt(fd, SOL_SOCKET, SO_PEEK_OFF, &ov, sizeof(ov));
489
490 recv(fd, buf, 2, MSG_PEEK); // Peeks "cc"; offset set to 6
491 recv(fd, buf, 2, MSG_PEEK); // Peeks "dd"; offset set to 8
492 recv(fd, buf, 2, 0); // Reads "aa"; offset set to 6
493 recv(fd, buf, 2, MSG_PEEK); // Peeks "ee"; offset set to 8
494 .fi
495 .in
496 .TP
497 .B SO_PEERCRED
498 Return the credentials of the foreign process connected to this socket.
499 This is possible only for connected
500 .B AF_UNIX
501 stream sockets and
502 .B AF_UNIX
503 stream and datagram socket pairs created using
504 .BR socketpair (2);
505 see
506 .BR unix (7).
507 The returned credentials are those that were in effect at the time
508 of the call to
509 .BR connect (2)
510 or
511 .BR socketpair (2).
512 The argument is a
513 .I ucred
514 structure; define the
515 .B GNU_SOURCE
516 feature test macro to obtain the definition of that structure from
517 .IR <sys/socket.h> .
518 This socket option is read-only.
519 .TP
520 .B SO_PRIORITY
521 Set the protocol-defined priority for all packets to be sent on
522 this socket.
523 Linux uses this value to order the networking queues:
524 packets with a higher priority may be processed first depending
525 on the selected device queueing discipline.
526 For
527 .BR ip (7),
528 this also sets the IP type-of-service (TOS) field for outgoing packets.
529 Setting a priority outside the range 0 to 6 requires the
530 .B CAP_NET_ADMIN
531 capability.
532 .TP
533 .BR SO_PROTOCOL " (since Linux 2.6.32)"
534 Retrieves the socket protocol as an integer, returning a value such as
535 .BR IPPROTO_SCTP .
536 See
537 .BR socket (2)
538 for details.
539 This socket option is read-only.
540 .TP
541 .B SO_RCVBUF
542 Sets or gets the maximum socket receive buffer in bytes.
543 The kernel doubles this value (to allow space for bookkeeping overhead)
544 when it is set using
545 .\" Most (all?) other implementations do not do this -- MTK, Dec 05
546 .BR setsockopt (2),
547 and this doubled value is returned by
548 .BR getsockopt (2).
549 .\" The following thread on LMKL is quite informative:
550 .\" getsockopt/setsockopt with SO_RCVBUF and SO_SNDBUF "non-standard" behaviour
551 .\" 17 July 2012
552 .\" http://thread.gmane.org/gmane.linux.kernel/1328935
553 The default value is set by the
554 .I /proc/sys/net/core/rmem_default
555 file, and the maximum allowed value is set by the
556 .I /proc/sys/net/core/rmem_max
557 file.
558 The minimum (doubled) value for this option is 256.
559 .TP
560 .BR SO_RCVBUFFORCE " (since Linux 2.6.14)"
561 Using this socket option, a privileged
562 .RB ( CAP_NET_ADMIN )
563 process can perform the same task as
564 .BR SO_RCVBUF ,
565 but the
566 .I rmem_max
567 limit can be overridden.
568 .TP
569 .BR SO_RCVLOWAT " and " SO_SNDLOWAT
570 Specify the minimum number of bytes in the buffer until the socket layer
571 will pass the data to the protocol
572 .RB ( SO_SNDLOWAT )
573 or the user on receiving
574 .RB ( SO_RCVLOWAT ).
575 These two values are initialized to 1.
576 .B SO_SNDLOWAT
577 is not changeable on Linux
578 .RB ( setsockopt (2)
579 fails with the error
580 .BR ENOPROTOOPT ).
581 .B SO_RCVLOWAT
582 is changeable
583 only since Linux 2.4.
584 The
585 .BR select (2)
586 and
587 .BR poll (2)
588 system calls currently do not respect the
589 .B SO_RCVLOWAT
590 setting on Linux,
591 and mark a socket readable when even a single byte of data is available.
592 A subsequent read from the socket will block until
593 .B SO_RCVLOWAT
594 bytes are available.
595 .\" See http://marc.theaimsgroup.com/?l=linux-kernel&m=111049368106984&w=2
596 .\" Tested on kernel 2.6.14 -- mtk, 30 Nov 05
597 .TP
598 .BR SO_RCVTIMEO " and " SO_SNDTIMEO
599 .\" Not implemented in 2.0.
600 .\" Implemented in 2.1.11 for getsockopt: always return a zero struct.
601 .\" Implemented in 2.3.41 for setsockopt, and actually used.
602 Specify the receiving or sending timeouts until reporting an error.
603 The argument is a
604 .IR "struct timeval" .
605 If an input or output function blocks for this period of time, and
606 data has been sent or received, the return value of that function
607 will be the amount of data transferred; if no data has been transferred
608 and the timeout has been reached then \-1 is returned with
609 .I errno
610 set to
611 .BR EAGAIN
612 or
613 .BR EWOULDBLOCK ,
614 .\" in fact to EAGAIN
615 or
616 .B EINPROGRESS
617 (for
618 .BR connect (2))
619 just as if the socket was specified to be nonblocking.
620 If the timeout is set to zero (the default)
621 then the operation will never timeout.
622 Timeouts only have effect for system calls that perform socket I/O (e.g.,
623 .BR read (2),
624 .BR recvmsg (2),
625 .BR send (2),
626 .BR sendmsg (2));
627 timeouts have no effect for
628 .BR select (2),
629 .BR poll (2),
630 .BR epoll_wait (2),
631 and so on.
632 .TP
633 .B SO_REUSEADDR
634 Indicates that the rules used in validating addresses supplied in a
635 .BR bind (2)
636 call should allow reuse of local addresses.
637 For
638 .B AF_INET
639 sockets this
640 means that a socket may bind, except when there
641 is an active listening socket bound to the address.
642 When the listening socket is bound to
643 .B INADDR_ANY
644 with a specific port then it is not possible
645 to bind to this port for any local address.
646 Argument is an integer boolean flag.
647 .TP
648 .B SO_SNDBUF
649 Sets or gets the maximum socket send buffer in bytes.
650 The kernel doubles this value (to allow space for bookkeeping overhead)
651 when it is set using
652 .\" Most (all?) other implementations do not do this -- MTK, Dec 05
653 .\" See also the comment to SO_RCVBUF (17 Jul 2012 LKML mail)
654 .BR setsockopt (2),
655 and this doubled value is returned by
656 .BR getsockopt (2).
657 The default value is set by the
658 .I /proc/sys/net/core/wmem_default
659 file and the maximum allowed value is set by the
660 .I /proc/sys/net/core/wmem_max
661 file.
662 The minimum (doubled) value for this option is 2048.
663 .TP
664 .BR SO_SNDBUFFORCE " (since Linux 2.6.14)"
665 Using this socket option, a privileged
666 .RB ( CAP_NET_ADMIN )
667 process can perform the same task as
668 .BR SO_SNDBUF ,
669 but the
670 .I wmem_max
671 limit can be overridden.
672 .TP
673 .B SO_TIMESTAMP
674 Enable or disable the receiving of the
675 .B SO_TIMESTAMP
676 control message.
677 The timestamp control message is sent with level
678 .B SOL_SOCKET
679 and the
680 .I cmsg_data
681 field is a
682 .I "struct timeval"
683 indicating the
684 reception time of the last packet passed to the user in this call.
685 See
686 .BR cmsg (3)
687 for details on control messages.
688 .TP
689 .B SO_TYPE
690 Gets the socket type as an integer (e.g.,
691 .BR SOCK_STREAM ).
692 This socket option is read-only.
693 .SS Signals
694 When writing onto a connection-oriented socket that has been shut down
695 (by the local or the remote end)
696 .B SIGPIPE
697 is sent to the writing process and
698 .B EPIPE
699 is returned.
700 The signal is not sent when the write call
701 specified the
702 .B MSG_NOSIGNAL
703 flag.
704 .PP
705 When requested with the
706 .B FIOSETOWN
707 .BR fcntl (2)
708 or
709 .B SIOCSPGRP
710 .BR ioctl (2),
711 .B SIGIO
712 is sent when an I/O event occurs.
713 It is possible to use
714 .BR poll (2)
715 or
716 .BR select (2)
717 in the signal handler to find out which socket the event occurred on.
718 An alternative (in Linux 2.2) is to set a real-time signal using the
719 .B F_SETSIG
720 .BR fcntl (2);
721 the handler of the real time signal will be called with
722 the file descriptor in the
723 .I si_fd
724 field of its
725 .IR siginfo_t .
726 See
727 .BR fcntl (2)
728 for more information.
729 .PP
730 Under some circumstances (e.g., multiple processes accessing a
731 single socket), the condition that caused the
732 .B SIGIO
733 may have already disappeared when the process reacts to the signal.
734 If this happens, the process should wait again because Linux
735 will resend the signal later.
736 .\" .SS Ancillary messages
737 .SS /proc interfaces
738 The core socket networking parameters can be accessed
739 via files in the directory
740 .IR /proc/sys/net/core/ .
741 .TP
742 .I rmem_default
743 contains the default setting in bytes of the socket receive buffer.
744 .TP
745 .I rmem_max
746 contains the maximum socket receive buffer size in bytes which a user may
747 set by using the
748 .B SO_RCVBUF
749 socket option.
750 .TP
751 .I wmem_default
752 contains the default setting in bytes of the socket send buffer.
753 .TP
754 .I wmem_max
755 contains the maximum socket send buffer size in bytes which a user may
756 set by using the
757 .B SO_SNDBUF
758 socket option.
759 .TP
760 .IR message_cost " and " message_burst
761 configure the token bucket filter used to load limit warning messages
762 caused by external network events.
763 .TP
764 .I netdev_max_backlog
765 Maximum number of packets in the global input queue.
766 .TP
767 .I optmem_max
768 Maximum length of ancillary data and user control data like the iovecs
769 per socket.
770 .\" netdev_fastroute is not documented because it is experimental
771 .SS Ioctls
772 These operations can be accessed using
773 .BR ioctl (2):
774
775 .in +4n
776 .nf
777 .IB error " = ioctl(" ip_socket ", " ioctl_type ", " &value_result ");"
778 .fi
779 .in
780 .TP
781 .B SIOCGSTAMP
782 Return a
783 .I struct timeval
784 with the receive timestamp of the last packet passed to the user.
785 This is useful for accurate round trip time measurements.
786 See
787 .BR setitimer (2)
788 for a description of
789 .IR "struct timeval" .
790 .\"
791 This ioctl should be used only if the socket option
792 .B SO_TIMESTAMP
793 is not set on the socket.
794 Otherwise, it returns the timestamp of the
795 last packet that was received while
796 .B SO_TIMESTAMP
797 was not set, or it fails if no such packet has been received,
798 (i.e.,
799 .BR ioctl (2)
800 returns \-1 with
801 .I errno
802 set to
803 .BR ENOENT ).
804 .TP
805 .B SIOCSPGRP
806 Set the process or process group to send
807 .B SIGIO
808 or
809 .B SIGURG
810 signals
811 to when an
812 asynchronous I/O operation has finished or urgent data is available.
813 The argument is a pointer to a
814 .IR pid_t .
815 If the argument is positive, send the signals to that process.
816 If the
817 argument is negative, send the signals to the process group with the ID
818 of the absolute value of the argument.
819 The process may only choose itself or its own process group to receive
820 signals unless it has the
821 .B CAP_KILL
822 capability or an effective UID of 0.
823 .TP
824 .B FIOASYNC
825 Change the
826 .B O_ASYNC
827 flag to enable or disable asynchronous I/O mode of the socket.
828 Asynchronous I/O mode means that the
829 .B SIGIO
830 signal or the signal set with
831 .B F_SETSIG
832 is raised when a new I/O event occurs.
833 .IP
834 Argument is an integer boolean flag.
835 (This operation is synonymous with the use of
836 .BR fcntl (2)
837 to set the
838 .B O_ASYNC
839 flag.)
840 .\"
841 .TP
842 .B SIOCGPGRP
843 Get the current process or process group that receives
844 .B SIGIO
845 or
846 .B SIGURG
847 signals,
848 or 0
849 when none is set.
850 .PP
851 Valid
852 .BR fcntl (2)
853 operations:
854 .TP
855 .B FIOGETOWN
856 The same as the
857 .B SIOCGPGRP
858 .BR ioctl (2).
859 .TP
860 .B FIOSETOWN
861 The same as the
862 .B SIOCSPGRP
863 .BR ioctl (2).
864 .SH VERSIONS
865 .B SO_BINDTODEVICE
866 was introduced in Linux 2.0.30.
867 .B SO_PASSCRED
868 is new in Linux 2.2.
869 The
870 .I /proc
871 interfaces was introduced in Linux 2.2.
872 .B SO_RCVTIMEO
873 and
874 .B SO_SNDTIMEO
875 are supported since Linux 2.3.41.
876 Earlier, timeouts were fixed to
877 a protocol-specific setting, and could not be read or written.
878 .SH NOTES
879 Linux assumes that half of the send/receive buffer is used for internal
880 kernel structures; thus the values in the corresponding
881 .I /proc
882 files are twice what can be observed on the wire.
883
884 Linux will only allow port reuse with the
885 .B SO_REUSEADDR
886 option
887 when this option was set both in the previous program that performed a
888 .BR bind (2)
889 to the port and in the program that wants to reuse the port.
890 This differs from some implementations (e.g., FreeBSD)
891 where only the later program needs to set the
892 .B SO_REUSEADDR
893 option.
894 Typically this difference is invisible, since, for example, a server
895 program is designed to always set this option.
896 .SH BUGS
897 The
898 .B CONFIG_FILTER
899 socket options
900 .B SO_ATTACH_FILTER
901 and
902 .B SO_DETACH_FILTER
903 .\" FIXME Document SO_ATTACH_FILTER and SO_DETACH_FILTER
904 are not documented.
905 The suggested interface to use them is via the libpcap
906 library.
907 .\" .SH AUTHORS
908 .\" This man page was written by Andi Kleen.
909 .SH SEE ALSO
910 .BR getsockopt (2),
911 .BR connect (2),
912 .BR setsockopt (2),
913 .BR socket (2),
914 .BR capabilities (7),
915 .BR ddp (7),
916 .BR ip (7),
917 .BR packet (7),
918 .BR tcp (7),
919 .BR udp (7),
920 .BR unix (7)