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