1 # SOME DESCRIPTIVE TITLE
2 # Copyright (C) YEAR Free Software Foundation, Inc.
3 # This file is distributed under the same license as the PACKAGE package.
4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
9 "Project-Id-Version: PACKAGE VERSION\n"
10 "POT-Creation-Date: 2013-09-28 04:06+0900\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <LL@li.org>\n"
16 "Content-Type: text/plain; charset=CHARSET\n"
17 "Content-Transfer-Encoding: 8bit\n"
20 #: build/C/man2/accept.2:41
26 #: build/C/man2/accept.2:41
32 #: build/C/man2/accept.2:41 build/C/man2/bind.2:68 build/C/man2/connect.2:67 build/C/man2/getsockname.2:40 build/C/man2/getsockopt.2:44 build/C/man2/listen.2:45 build/C/man2/recv.2:41 build/C/man2/recvmmsg.2:31 build/C/man2/select.2:38 build/C/man2/select_tut.2:32 build/C/man2/send.2:40 build/C/man2/sendmmsg.2:28 build/C/man3/sockatmark.3:25 build/C/man2/socket.2:43 build/C/man7/socket.7:45 build/C/man2/socketcall.2:25 build/C/man2/socketpair.2:42
38 #: build/C/man2/accept.2:41 build/C/man2/bind.2:68 build/C/man3/bindresvport.3:30 build/C/man2/connect.2:67 build/C/man3/getifaddrs.3:36 build/C/man2/getsockname.2:40 build/C/man2/getsockopt.2:44 build/C/man3/if_nameindex.3:26 build/C/man3/if_nametoindex.3:25 build/C/man2/listen.2:45 build/C/man2/recv.2:41 build/C/man2/recvmmsg.2:31 build/C/man2/select.2:38 build/C/man2/select_tut.2:32 build/C/man2/send.2:40 build/C/man2/sendmmsg.2:28 build/C/man3/sockatmark.3:25 build/C/man2/socket.2:43 build/C/man7/socket.7:45 build/C/man2/socketcall.2:25 build/C/man2/socketpair.2:42
40 msgid "Linux Programmer's Manual"
44 #: build/C/man2/accept.2:42 build/C/man2/bind.2:69 build/C/man3/bindresvport.3:31 build/C/man2/connect.2:68 build/C/man3/getifaddrs.3:37 build/C/man2/getsockname.2:41 build/C/man2/getsockopt.2:45 build/C/man3/if_nameindex.3:27 build/C/man3/if_nametoindex.3:26 build/C/man2/listen.2:46 build/C/man2/recv.2:42 build/C/man2/recvmmsg.2:32 build/C/man2/select.2:39 build/C/man2/select_tut.2:33 build/C/man2/send.2:41 build/C/man2/sendmmsg.2:29 build/C/man3/sockatmark.3:26 build/C/man2/socket.2:44 build/C/man7/socket.7:46 build/C/man2/socketcall.2:26 build/C/man2/socketpair.2:43
50 #: build/C/man2/accept.2:44
51 msgid "accept, accept4 - accept a connection on a socket"
55 #: build/C/man2/accept.2:44 build/C/man2/bind.2:71 build/C/man3/bindresvport.3:33 build/C/man2/connect.2:70 build/C/man3/getifaddrs.3:39 build/C/man2/getsockname.2:43 build/C/man2/getsockopt.2:47 build/C/man3/if_nameindex.3:29 build/C/man3/if_nametoindex.3:29 build/C/man2/listen.2:48 build/C/man2/recv.2:44 build/C/man2/recvmmsg.2:34 build/C/man2/select.2:42 build/C/man2/select_tut.2:36 build/C/man2/send.2:43 build/C/man2/sendmmsg.2:31 build/C/man3/sockatmark.3:28 build/C/man2/socket.2:46 build/C/man7/socket.7:48 build/C/man2/socketcall.2:28 build/C/man2/socketpair.2:45
61 #: build/C/man2/accept.2:48 build/C/man2/bind.2:75
64 "B<#include E<lt>sys/types.hE<gt>> /* See NOTES */\n"
65 "B<#include E<lt>sys/socket.hE<gt>>\n"
69 #: build/C/man2/accept.2:50
72 "B<int accept(int >I<sockfd>B<, struct sockaddr *>I<addr>B<, socklen_t "
77 #: build/C/man2/accept.2:53
80 "B<#define _GNU_SOURCE> /* See feature_test_macros(7) */\n"
81 "B<#include E<lt>sys/socket.hE<gt>>\n"
85 #: build/C/man2/accept.2:56
88 "B<int accept4(int >I<sockfd>B<, struct sockaddr *>I<addr>B<,>\n"
89 "B< socklen_t *>I<addrlen>B<, int >I<flags>B<);>\n"
93 #: build/C/man2/accept.2:57 build/C/man2/bind.2:79 build/C/man3/bindresvport.3:40 build/C/man2/connect.2:79 build/C/man3/getifaddrs.3:48 build/C/man2/getsockname.2:50 build/C/man2/getsockopt.2:58 build/C/man3/if_nameindex.3:36 build/C/man3/if_nametoindex.3:37 build/C/man2/listen.2:56 build/C/man2/recv.2:59 build/C/man2/recvmmsg.2:44 build/C/man2/select.2:81 build/C/man2/select_tut.2:75 build/C/man2/send.2:58 build/C/man2/sendmmsg.2:40 build/C/man3/sockatmark.3:42 build/C/man2/socket.2:52 build/C/man7/socket.7:52 build/C/man2/socketcall.2:30 build/C/man2/socketpair.2:52
99 #: build/C/man2/accept.2:72
101 "The B<accept>() system call is used with connection-based socket types "
102 "(B<SOCK_STREAM>, B<SOCK_SEQPACKET>). It extracts the first connection "
103 "request on the queue of pending connections for the listening socket, "
104 "I<sockfd>, creates a new connected socket, and returns a new file descriptor "
105 "referring to that socket. The newly created socket is not in the listening "
106 "state. The original socket I<sockfd> is unaffected by this call."
110 #: build/C/man2/accept.2:81
112 "The argument I<sockfd> is a socket that has been created with B<socket>(2), "
113 "bound to a local address with B<bind>(2), and is listening for connections "
114 "after a B<listen>(2)."
118 #: build/C/man2/accept.2:99
120 "The argument I<addr> is a pointer to a I<sockaddr> structure. This "
121 "structure is filled in with the address of the peer socket, as known to the "
122 "communications layer. The exact format of the address returned I<addr> is "
123 "determined by the socket's address family (see B<socket>(2) and the "
124 "respective protocol man pages). When I<addr> is NULL, nothing is filled in; "
125 "in this case, I<addrlen> is not used, and should also be NULL."
129 #: build/C/man2/accept.2:107
131 "The I<addrlen> argument is a value-result argument: the caller must "
132 "initialize it to contain the size (in bytes) of the structure pointed to by "
133 "I<addr>; on return it will contain the actual size of the peer address."
137 #: build/C/man2/accept.2:112 build/C/man2/getsockname.2:67
139 "The returned address is truncated if the buffer provided is too small; in "
140 "this case, I<addrlen> will return a value greater than was supplied to the "
145 #: build/C/man2/accept.2:125
147 "If no pending connections are present on the queue, and the socket is not "
148 "marked as nonblocking, B<accept>() blocks the caller until a connection is "
149 "present. If the socket is marked nonblocking and no pending connections are "
150 "present on the queue, B<accept>() fails with the error B<EAGAIN> or "
155 #: build/C/man2/accept.2:139
157 "In order to be notified of incoming connections on a socket, you can use "
158 "B<select>(2) or B<poll>(2). A readable event will be delivered when a new "
159 "connection is attempted and you may then call B<accept>() to get a socket "
160 "for that connection. Alternatively, you can set the socket to deliver "
161 "B<SIGIO> when activity occurs on a socket; see B<socket>(7) for details."
165 #: build/C/man2/accept.2:152
167 "For certain protocols which require an explicit confirmation, such as "
168 "DECNet, B<accept>() can be thought of as merely dequeuing the next "
169 "connection request and not implying confirmation. Confirmation can be "
170 "implied by a normal read or write on the new file descriptor, and rejection "
171 "can be implied by closing the new socket. Currently only DECNet has these "
172 "semantics on Linux."
176 #: build/C/man2/accept.2:162
178 "If I<flags> is 0, then B<accept4>() is the same as B<accept>(). The "
179 "following values can be bitwise ORed in I<flags> to obtain different "
184 #: build/C/man2/accept.2:162 build/C/man2/socket.2:164
186 msgid "B<SOCK_NONBLOCK>"
190 #: build/C/man2/accept.2:170 build/C/man2/socket.2:172
192 "Set the B<O_NONBLOCK> file status flag on the new open file description. "
193 "Using this flag saves extra calls to B<fcntl>(2) to achieve the same "
198 #: build/C/man2/accept.2:170 build/C/man2/socket.2:172
200 msgid "B<SOCK_CLOEXEC>"
204 #: build/C/man2/accept.2:180 build/C/man2/socket.2:182
206 "Set the close-on-exec (B<FD_CLOEXEC>) flag on the new file descriptor. See "
207 "the description of the B<O_CLOEXEC> flag in B<open>(2) for reasons why this "
212 #: build/C/man2/accept.2:180 build/C/man2/bind.2:152 build/C/man3/bindresvport.3:67 build/C/man2/connect.2:127 build/C/man3/getifaddrs.3:142 build/C/man2/getsockname.2:67 build/C/man2/getsockopt.2:131 build/C/man3/if_nameindex.3:71 build/C/man3/if_nametoindex.3:54 build/C/man2/listen.2:82 build/C/man2/recv.2:388 build/C/man2/recvmmsg.2:149 build/C/man2/select.2:289 build/C/man2/select_tut.2:485 build/C/man2/send.2:275 build/C/man2/sendmmsg.2:119 build/C/man3/sockatmark.3:51 build/C/man2/socket.2:314 build/C/man2/socketpair.2:69
218 #: build/C/man2/accept.2:187
220 "On success, these system calls return a nonnegative integer that is a "
221 "descriptor for the accepted socket. On error, -1 is returned, and I<errno> "
222 "is set appropriately."
226 #: build/C/man2/accept.2:187
228 msgid "Error handling"
232 #: build/C/man2/accept.2:214
234 "Linux B<accept>() (and B<accept4>()) passes already-pending network errors "
235 "on the new socket as an error code from B<accept>(). This behavior differs "
236 "from other BSD socket implementations. For reliable operation the "
237 "application should detect the network errors defined for the protocol after "
238 "B<accept>() and treat them like B<EAGAIN> by retrying. In the case of "
239 "TCP/IP, these are B<ENETDOWN>, B<EPROTO>, B<ENOPROTOOPT>, B<EHOSTDOWN>, "
240 "B<ENONET>, B<EHOSTUNREACH>, B<EOPNOTSUPP>, and B<ENETUNREACH>."
244 #: build/C/man2/accept.2:214 build/C/man2/bind.2:157 build/C/man3/bindresvport.3:72 build/C/man2/connect.2:132 build/C/man3/getifaddrs.3:149 build/C/man2/getsockname.2:72 build/C/man2/getsockopt.2:136 build/C/man3/if_nameindex.3:78 build/C/man3/if_nametoindex.3:69 build/C/man2/listen.2:87 build/C/man2/recv.2:396 build/C/man2/recvmmsg.2:157 build/C/man2/select.2:306 build/C/man2/send.2:280 build/C/man2/sendmmsg.2:133 build/C/man3/sockatmark.3:58 build/C/man2/socket.2:319 build/C/man2/socketpair.2:74
250 #: build/C/man2/accept.2:215 build/C/man2/recv.2:401 build/C/man2/send.2:296
252 msgid "B<EAGAIN> or B<EWOULDBLOCK>"
255 #. Actually EAGAIN on Linux
257 #: build/C/man2/accept.2:223
259 "The socket is marked nonblocking and no connections are present to be "
260 "accepted. POSIX.1-2001 allows either error to be returned for this case, "
261 "and does not require these constants to have the same value, so a portable "
262 "application should check for both possibilities."
266 #: build/C/man2/accept.2:223 build/C/man2/bind.2:165 build/C/man2/connect.2:169 build/C/man2/getsockname.2:73 build/C/man2/getsockopt.2:137 build/C/man2/listen.2:91 build/C/man2/recv.2:410 build/C/man2/select.2:307 build/C/man2/send.2:304 build/C/man3/sockatmark.3:59
272 #: build/C/man2/accept.2:226
273 msgid "The descriptor is invalid."
277 #: build/C/man2/accept.2:226
279 msgid "B<ECONNABORTED>"
283 #: build/C/man2/accept.2:229
284 msgid "A connection has been aborted."
288 #: build/C/man2/accept.2:229 build/C/man2/bind.2:191 build/C/man2/connect.2:175 build/C/man2/getsockname.2:78 build/C/man2/getsockopt.2:142 build/C/man2/recv.2:419 build/C/man2/send.2:313 build/C/man2/socketpair.2:78
294 #: build/C/man2/accept.2:234
295 msgid "The I<addr> argument is not in a writable part of the user address space."
299 #: build/C/man2/accept.2:234 build/C/man2/connect.2:203 build/C/man2/recv.2:423 build/C/man2/select.2:312 build/C/man2/send.2:316
305 #: build/C/man2/accept.2:239
307 "The system call was interrupted by a signal that was caught before a valid "
308 "connection arrived; see B<signal>(7)."
312 #: build/C/man2/accept.2:239 build/C/man2/accept.2:244 build/C/man2/bind.2:169 build/C/man2/bind.2:195 build/C/man2/getsockname.2:84 build/C/man2/getsockopt.2:152 build/C/man2/recv.2:428 build/C/man2/recvmmsg.2:161 build/C/man2/select.2:316 build/C/man2/send.2:320 build/C/man3/sockatmark.3:63 build/C/man2/socket.2:327 build/C/man2/socket.2:330
318 #: build/C/man2/accept.2:244
320 "Socket is not listening for connections, or I<addrlen> is invalid (e.g., is "
325 #: build/C/man2/accept.2:249
326 msgid "(B<accept4>()) invalid value in I<flags>."
330 #: build/C/man2/accept.2:249 build/C/man2/socket.2:335 build/C/man2/socketpair.2:83
336 #: build/C/man2/accept.2:252
337 msgid "The per-process limit of open file descriptors has been reached."
341 #: build/C/man2/accept.2:252 build/C/man2/socket.2:338 build/C/man2/socketpair.2:86
347 #: build/C/man2/accept.2:255 build/C/man2/socket.2:341 build/C/man2/socketpair.2:89
348 msgid "The system limit on the total number of open files has been reached."
352 #: build/C/man2/accept.2:255
354 msgid "B<ENOBUFS>, B<ENOMEM>"
358 #: build/C/man2/accept.2:260
360 "Not enough free memory. This often means that the memory allocation is "
361 "limited by the socket buffer limits, not by the system memory."
365 #: build/C/man2/accept.2:260 build/C/man2/bind.2:174 build/C/man2/connect.2:215 build/C/man2/getsockname.2:92 build/C/man2/getsockopt.2:166 build/C/man2/listen.2:96 build/C/man2/recv.2:443 build/C/man2/send.2:349
371 #: build/C/man2/accept.2:263
372 msgid "The descriptor references a file, not a socket."
376 #: build/C/man2/accept.2:263 build/C/man2/listen.2:101 build/C/man2/send.2:354 build/C/man2/socketpair.2:89
378 msgid "B<EOPNOTSUPP>"
382 #: build/C/man2/accept.2:267
383 msgid "The referenced socket is not of type B<SOCK_STREAM>."
387 #: build/C/man2/accept.2:267
393 #: build/C/man2/accept.2:270
394 msgid "Protocol error."
398 #: build/C/man2/accept.2:274
399 msgid "In addition, Linux B<accept>() may fail if:"
403 #: build/C/man2/accept.2:274
409 #: build/C/man2/accept.2:277
410 msgid "Firewall rules forbid connection."
414 #: build/C/man2/accept.2:289
416 "In addition, network errors for the new socket and as defined for the "
417 "protocol may be returned. Various Linux kernels can return other errors "
418 "such as B<ENOSR>, B<ESOCKTNOSUPPORT>, B<EPROTONOSUPPORT>, B<ETIMEDOUT>. The "
419 "value B<ERESTARTSYS> may be seen during a trace."
423 #: build/C/man2/accept.2:289 build/C/man3/getifaddrs.3:162 build/C/man3/if_nameindex.3:97 build/C/man2/recvmmsg.2:165 build/C/man2/select.2:325 build/C/man2/sendmmsg.2:145 build/C/man3/sockatmark.3:70 build/C/man7/socket.7:868
429 #: build/C/man2/accept.2:294
431 "The B<accept4>() system call is available starting with Linux 2.6.28; "
432 "support in glibc is available starting with version 2.10."
436 #: build/C/man2/accept.2:294 build/C/man2/bind.2:222 build/C/man3/bindresvport.3:104 build/C/man2/connect.2:225 build/C/man3/getifaddrs.3:170 build/C/man2/getsockname.2:97 build/C/man2/getsockopt.2:171 build/C/man3/if_nameindex.3:104 build/C/man3/if_nametoindex.3:85 build/C/man2/listen.2:106 build/C/man2/recv.2:448 build/C/man2/recvmmsg.2:170 build/C/man2/select.2:331 build/C/man2/send.2:368 build/C/man2/sendmmsg.2:150 build/C/man3/sockatmark.3:73 build/C/man2/socket.2:352 build/C/man2/socketcall.2:42 build/C/man2/socketpair.2:95
438 msgid "CONFORMING TO"
441 #. The BSD man page documents five possible error returns
442 #. (EBADF, ENOTSOCK, EOPNOTSUPP, EWOULDBLOCK, EFAULT).
443 #. POSIX.1-2001 documents errors
444 #. EAGAIN, EBADF, ECONNABORTED, EINTR, EINVAL, EMFILE,
445 #. ENFILE, ENOBUFS, ENOMEM, ENOTSOCK, EOPNOTSUPP, EPROTO, EWOULDBLOCK.
446 #. In addition, SUSv2 documents EFAULT and ENOSR.
448 #: build/C/man2/accept.2:306
450 "B<accept>(): POSIX.1-2001, SVr4, 4.4BSD, (B<accept>() first appeared in "
455 #: build/C/man2/accept.2:309
456 msgid "B<accept4>() is a nonstandard Linux extension."
459 #. Some testing seems to show that Tru64 5.1 and HP-UX 11 also
460 #. do not inherit file status flags -- MTK Jun 05
462 #: build/C/man2/accept.2:324
464 "On Linux, the new socket returned by B<accept>() does I<not> inherit file "
465 "status flags such as B<O_NONBLOCK> and B<O_ASYNC> from the listening "
466 "socket. This behavior differs from the canonical BSD sockets "
467 "implementation. Portable programs should not rely on inheritance or "
468 "noninheritance of file status flags and always explicitly set all required "
469 "flags on the socket returned from B<accept>()."
473 #: build/C/man2/accept.2:324 build/C/man2/bind.2:234 build/C/man3/bindresvport.3:107 build/C/man2/connect.2:241 build/C/man3/getifaddrs.3:190 build/C/man2/getsockname.2:103 build/C/man2/getsockopt.2:178 build/C/man2/listen.2:111 build/C/man2/recv.2:458 build/C/man2/select.2:346 build/C/man2/select_tut.2:503 build/C/man2/send.2:382 build/C/man2/sendmmsg.2:153 build/C/man3/sockatmark.3:75 build/C/man2/socket.2:366 build/C/man7/socket.7:882 build/C/man2/socketcall.2:45 build/C/man2/socketpair.2:103
479 #: build/C/man2/accept.2:330 build/C/man2/bind.2:240 build/C/man2/connect.2:247 build/C/man2/getsockopt.2:184 build/C/man2/listen.2:137 build/C/man2/socket.2:372 build/C/man2/socketpair.2:124
481 "POSIX.1-2001 does not require the inclusion of I<E<lt>sys/types.hE<gt>>, and "
482 "this header file is not required on Linux. However, some historical (BSD) "
483 "implementations required this header file, and portable applications are "
484 "probably wise to include it."
488 #: build/C/man2/accept.2:351
490 "There may not always be a connection waiting after a B<SIGIO> is delivered "
491 "or B<select>(2) or B<poll>(2) return a readability event because the "
492 "connection might have been removed by an asynchronous network error or "
493 "another thread before B<accept>() is called. If this happens then the call "
494 "will block waiting for the next connection to arrive. To ensure that "
495 "B<accept>() never blocks, the passed socket I<sockfd> needs to have the "
496 "B<O_NONBLOCK> flag set (see B<socket>(7))."
500 #: build/C/man2/accept.2:351
502 msgid "The socklen_t type"
506 #: build/C/man2/accept.2:361
508 "The third argument of B<accept>() was originally declared as an I<int *> "
509 "(and is that under libc4 and libc5 and on many other systems like 4.x BSD, "
510 "SunOS 4, SGI); a POSIX.1g draft standard wanted to change it into a I<size_t "
511 "*>, and that is what it is for SunOS 5. Later POSIX drafts have I<socklen_t "
512 "*>, and so do the Single UNIX Specification and glibc2. Quoting Linus "
516 #. .I fails: only italicizes a single line
518 #: build/C/man2/accept.2:378
520 "\"_Any_ sane library _must_ have \"socklen_t\" be the same size as int. "
521 "Anything else breaks any BSD socket layer stuff. POSIX initially I<did> "
522 "make it a size_t, and I (and hopefully others, but obviously not too many) "
523 "complained to them very loudly indeed. Making it a size_t is completely "
524 "broken, exactly because size_t very seldom is the same size as \"int\" on "
525 "64-bit architectures, for example. And it I<has> to be the same size as "
526 "\"int\" because that's what the BSD socket interface is. Anyway, the POSIX "
527 "people eventually got a clue, and created \"socklen_t\". They shouldn't "
528 "have touched it in the first place, but once they did they felt it had to "
529 "have a named type for some unfathomable reason (probably somebody didn't "
530 "like losing face over having done the original stupid thing, so they "
531 "silently just renamed their blunder).\""
535 #: build/C/man2/accept.2:378 build/C/man2/bind.2:254 build/C/man2/connect.2:258 build/C/man3/getifaddrs.3:207 build/C/man3/if_nameindex.3:108 build/C/man2/listen.2:166 build/C/man2/recv.2:493 build/C/man2/recvmmsg.2:173 build/C/man2/select.2:537 build/C/man2/select_tut.2:529 build/C/man2/send.2:419 build/C/man2/sendmmsg.2:168 build/C/man3/sockatmark.3:99 build/C/man2/socket.2:385
541 #: build/C/man2/accept.2:381 build/C/man2/listen.2:169
542 msgid "See B<bind>(2)."
546 #: build/C/man2/accept.2:381 build/C/man2/bind.2:319 build/C/man3/bindresvport.3:113 build/C/man2/connect.2:263 build/C/man3/getifaddrs.3:290 build/C/man2/getsockname.2:114 build/C/man2/getsockopt.2:202 build/C/man3/if_nameindex.3:146 build/C/man3/if_nametoindex.3:89 build/C/man2/listen.2:169 build/C/man2/recv.2:498 build/C/man2/recvmmsg.2:268 build/C/man2/select.2:574 build/C/man2/select_tut.2:819 build/C/man2/send.2:424 build/C/man2/sendmmsg.2:236 build/C/man3/sockatmark.3:134 build/C/man2/socket.2:390 build/C/man7/socket.7:913 build/C/man2/socketcall.2:53 build/C/man2/socketpair.2:124
552 #: build/C/man2/accept.2:388
554 "B<bind>(2), B<connect>(2), B<listen>(2), B<select>(2), B<socket>(2), "
559 #: build/C/man2/accept.2:388 build/C/man2/bind.2:332 build/C/man3/bindresvport.3:116 build/C/man2/connect.2:270 build/C/man3/getifaddrs.3:296 build/C/man2/getsockname.2:121 build/C/man2/getsockopt.2:210 build/C/man3/if_nameindex.3:153 build/C/man3/if_nametoindex.3:93 build/C/man2/listen.2:175 build/C/man2/recv.2:509 build/C/man2/recvmmsg.2:275 build/C/man2/select.2:588 build/C/man2/select_tut.2:838 build/C/man2/send.2:439 build/C/man2/sendmmsg.2:241 build/C/man3/sockatmark.3:139 build/C/man2/socket.2:419 build/C/man7/socket.7:925 build/C/man2/socketcall.2:71 build/C/man2/socketpair.2:131
565 #: build/C/man2/accept.2:395 build/C/man2/bind.2:339 build/C/man3/bindresvport.3:123 build/C/man2/connect.2:277 build/C/man3/getifaddrs.3:303 build/C/man2/getsockname.2:128 build/C/man2/getsockopt.2:217 build/C/man3/if_nameindex.3:160 build/C/man3/if_nametoindex.3:100 build/C/man2/listen.2:182 build/C/man2/recv.2:516 build/C/man2/recvmmsg.2:282 build/C/man2/select.2:595 build/C/man2/select_tut.2:845 build/C/man2/send.2:446 build/C/man2/sendmmsg.2:248 build/C/man3/sockatmark.3:146 build/C/man2/socket.2:426 build/C/man7/socket.7:932 build/C/man2/socketcall.2:78 build/C/man2/socketpair.2:138
567 "This page is part of release 3.54 of the Linux I<man-pages> project. A "
568 "description of the project, and information about reporting bugs, can be "
569 "found at \\%http://www.kernel.org/doc/man-pages/."
573 #: build/C/man2/bind.2:68
579 #: build/C/man2/bind.2:68
585 #: build/C/man2/bind.2:71
586 msgid "bind - bind a name to a socket"
590 #: build/C/man2/bind.2:78
593 "B<int bind(int >I<sockfd>B<, const struct sockaddr *>I<addr>B<,>\n"
594 "B< socklen_t >I<addrlen>B<);>\n"
598 #: build/C/man2/bind.2:92
600 "When a socket is created with B<socket>(2), it exists in a name space "
601 "(address family) but has no address assigned to it. B<bind>() assigns the "
602 "address specified by I<addr> to the socket referred to by the file "
603 "descriptor I<sockfd>. I<addrlen> specifies the size, in bytes, of the "
604 "address structure pointed to by I<addr>. Traditionally, this operation is "
605 "called \\(lqassigning a name to a socket\\(rq."
609 #: build/C/man2/bind.2:99
611 "It is normally necessary to assign a local address using B<bind>() before a "
612 "B<SOCK_STREAM> socket may receive connections (see B<accept>(2))."
616 #: build/C/man2/bind.2:130
618 "The rules used in name binding vary between address families. Consult the "
619 "manual entries in Section 7 for detailed information. For B<AF_INET> see "
620 "B<ip>(7), for B<AF_INET6> see B<ipv6>(7), for B<AF_UNIX> see B<unix>(7), for "
621 "B<AF_APPLETALK> see B<ddp>(7), for B<AF_PACKET> see B<packet>(7), for "
622 "B<AF_X25> see B<x25>(7) and for B<AF_NETLINK> see B<netlink>(7)."
626 #: build/C/man2/bind.2:137
628 "The actual structure passed for the I<addr> argument will depend on the "
629 "address family. The I<sockaddr> structure is defined as something like:"
633 #: build/C/man2/bind.2:144
636 "struct sockaddr {\n"
637 " sa_family_t sa_family;\n"
638 " char sa_data[14];\n"
643 #: build/C/man2/bind.2:152
645 "The only purpose of this structure is to cast the structure pointer passed "
646 "in I<addr> in order to avoid compiler warnings. See EXAMPLE below."
650 #: build/C/man2/bind.2:157 build/C/man2/getsockname.2:72 build/C/man2/getsockopt.2:136 build/C/man2/listen.2:87 build/C/man2/socketpair.2:74
652 "On success, zero is returned. On error, -1 is returned, and I<errno> is set "
657 #: build/C/man2/bind.2:158 build/C/man2/bind.2:182 build/C/man3/bindresvport.3:77 build/C/man2/connect.2:135 build/C/man2/send.2:285 build/C/man2/socket.2:320
662 #. e.g., privileged port in AF_INET domain
664 #: build/C/man2/bind.2:162
665 msgid "The address is protected, and the user is not the superuser."
669 #: build/C/man2/bind.2:162 build/C/man3/bindresvport.3:82 build/C/man2/connect.2:148 build/C/man2/listen.2:88
671 msgid "B<EADDRINUSE>"
675 #: build/C/man2/bind.2:165
676 msgid "The given address is already in use."
680 #: build/C/man2/bind.2:169
681 msgid "I<sockfd> is not a valid descriptor."
684 #. This may change in the future: see
685 #. .I linux/unix/sock.c for details.
687 #: build/C/man2/bind.2:174
688 msgid "The socket is already bound to an address."
692 #: build/C/man2/bind.2:178
693 msgid "I<sockfd> is a descriptor for a file, not a socket."
697 #: build/C/man2/bind.2:182
698 msgid "The following errors are specific to UNIX domain (B<AF_UNIX>) sockets:"
702 #: build/C/man2/bind.2:187
704 "Search permission is denied on a component of the path prefix. (See also "
705 "B<path_resolution>(7).)"
709 #: build/C/man2/bind.2:187
711 msgid "B<EADDRNOTAVAIL>"
715 #: build/C/man2/bind.2:191
717 "A nonexistent interface was requested or the requested address was not "
722 #: build/C/man2/bind.2:195
723 msgid "I<addr> points outside the user's accessible address space."
727 #: build/C/man2/bind.2:202
728 msgid "The I<addrlen> is wrong, or the socket was not in the B<AF_UNIX> family."
732 #: build/C/man2/bind.2:202
738 #: build/C/man2/bind.2:206
739 msgid "Too many symbolic links were encountered in resolving I<addr>."
743 #: build/C/man2/bind.2:206
745 msgid "B<ENAMETOOLONG>"
749 #: build/C/man2/bind.2:210
750 msgid "I<addr> is too long."
754 #: build/C/man2/bind.2:210
760 #: build/C/man2/bind.2:213
761 msgid "The file does not exist."
765 #: build/C/man2/bind.2:213 build/C/man2/recv.2:432 build/C/man2/select.2:322 build/C/man2/send.2:343
771 #: build/C/man2/bind.2:216
772 msgid "Insufficient kernel memory was available."
776 #: build/C/man2/bind.2:216
782 #: build/C/man2/bind.2:219
783 msgid "A component of the path prefix is not a directory."
787 #: build/C/man2/bind.2:219
793 #: build/C/man2/bind.2:222
794 msgid "The socket inode would reside on a read-only filesystem."
797 #. SVr4 documents an additional
799 #. general error condition, and
804 #. UNIX-domain error conditions.
806 #: build/C/man2/bind.2:234
807 msgid "SVr4, 4.4BSD, POSIX.1-2001 (B<bind>() first appeared in 4.2BSD)."
811 #: build/C/man2/bind.2:251
813 "The third argument of B<bind>() is in reality an I<int> (and this is what "
814 "4.x BSD and libc4 and libc5 have). Some POSIX confusion resulted in the "
815 "present I<socklen_t>, also used by glibc. See also B<accept>(2)."
819 #: build/C/man2/bind.2:251 build/C/man2/getsockopt.2:199 build/C/man2/select.2:474 build/C/man2/send.2:414 build/C/man3/sockatmark.3:95 build/C/man7/socket.7:900
824 #. FIXME What *are* transparent proxy options?
826 #: build/C/man2/bind.2:254
827 msgid "The transparent proxy options are not described."
831 #: build/C/man2/bind.2:259
833 "An example of the use of B<bind>() with Internet domain sockets can be "
834 "found in B<getaddrinfo>(3)."
837 #. listen.7 refers to this example.
838 #. accept.7 refers to this example.
839 #. unix.7 refers to this example.
841 #: build/C/man2/bind.2:266
843 "The following example shows how to bind a stream socket in the UNIX "
844 "(B<AF_UNIX>) domain, and accept connections:"
848 #: build/C/man2/bind.2:273
851 "#include E<lt>sys/socket.hE<gt>\n"
852 "#include E<lt>sys/un.hE<gt>\n"
853 "#include E<lt>stdlib.hE<gt>\n"
854 "#include E<lt>stdio.hE<gt>\n"
855 "#include E<lt>string.hE<gt>\n"
859 #: build/C/man2/bind.2:276
862 "#define MY_SOCK_PATH \"/somepath\"\n"
863 "#define LISTEN_BACKLOG 50\n"
867 #: build/C/man2/bind.2:279
870 "#define handle_error(msg) \\e\n"
871 " do { perror(msg); exit(EXIT_FAILURE); } while (0)\n"
875 #: build/C/man2/bind.2:286
879 "main(int argc, char *argv[])\n"
882 " struct sockaddr_un my_addr, peer_addr;\n"
883 " socklen_t peer_addr_size;\n"
887 #: build/C/man2/bind.2:290
890 " sfd = socket(AF_UNIX, SOCK_STREAM, 0);\n"
892 " handle_error(\"socket\");\n"
896 #: build/C/man2/bind.2:296
899 " memset(&my_addr, 0, sizeof(struct sockaddr_un));\n"
900 " /* Clear structure */\n"
901 " my_addr.sun_family = AF_UNIX;\n"
902 " strncpy(my_addr.sun_path, MY_SOCK_PATH,\n"
903 " sizeof(my_addr.sun_path) - 1);\n"
907 #: build/C/man2/bind.2:300
910 " if (bind(sfd, (struct sockaddr *) &my_addr,\n"
911 " sizeof(struct sockaddr_un)) == -1)\n"
912 " handle_error(\"bind\");\n"
916 #: build/C/man2/bind.2:303
919 " if (listen(sfd, LISTEN_BACKLOG) == -1)\n"
920 " handle_error(\"listen\");\n"
924 #: build/C/man2/bind.2:306
927 " /* Now we can accept incoming connections one\n"
928 " at a time using accept(2) */\n"
932 #: build/C/man2/bind.2:312
935 " peer_addr_size = sizeof(struct sockaddr_un);\n"
936 " cfd = accept(sfd, (struct sockaddr *) &peer_addr,\n"
937 " &peer_addr_size);\n"
939 " handle_error(\"accept\");\n"
943 #: build/C/man2/bind.2:314
945 msgid " /* Code to deal with incoming connection(s)... */\n"
949 #: build/C/man2/bind.2:318
952 " /* When no longer required, the socket pathname, MY_SOCK_PATH\n"
953 " should be deleted using unlink(2) or remove(3) */\n"
958 #: build/C/man2/bind.2:332
960 "B<accept>(2), B<connect>(2), B<getsockname>(2), B<listen>(2), B<socket>(2), "
961 "B<getaddrinfo>(3), B<getifaddrs>(3), B<ip>(7), B<ipv6>(7), "
962 "B<path_resolution>(7), B<socket>(7), B<unix>(7)"
966 #: build/C/man3/bindresvport.3:30
972 #: build/C/man3/bindresvport.3:30 build/C/man7/socket.7:45
978 #: build/C/man3/bindresvport.3:33
979 msgid "bindresvport - bind a socket to a privileged IP port"
983 #: build/C/man3/bindresvport.3:37
986 "B<#include E<lt>sys/types.hE<gt>>\n"
987 "B<#include E<lt>netinet/in.hE<gt>>\n"
991 #: build/C/man3/bindresvport.3:39
993 msgid "B<int bindresvport(int >I<sockfd>B<, struct sockaddr_in *>I<sin>B<);>\n"
996 #. Glibc actually starts searching with a port # in the range 600 to 1023
998 #: build/C/man3/bindresvport.3:46
1000 "B<bindresvport>() is used to bind a socket descriptor to a privileged "
1001 "anonymous IP port, that is, a port number arbitrarily selected from the "
1002 "range 512 to 1023."
1006 #: build/C/man3/bindresvport.3:56
1008 "If the B<bind>(2) performed by B<bindresvport>() is successful, and I<sin> "
1009 "is not NULL, then I<sin-E<gt>sin_port> returns the port number actually "
1014 #: build/C/man3/bindresvport.3:67
1016 "I<sin> can be NULL, in which case I<sin-E<gt>sin_family> is implicitly taken "
1017 "to be B<AF_INET>. However, in this case, B<bindresvport>() has no way to "
1018 "return the port number actually allocated. (This information can later be "
1019 "obtained using B<getsockname>(2).)"
1023 #: build/C/man3/bindresvport.3:72
1025 "B<bindresvport>() returns 0 on success; otherwise -1 is returned and "
1026 "I<errno> set to indicate the cause of the error."
1030 #: build/C/man3/bindresvport.3:77
1032 "B<bindresvport>() can fail for any of the same reasons as B<bind>(2). In "
1033 "addition, the following errors may occur:"
1037 #: build/C/man3/bindresvport.3:82
1039 "The caller did not have superuser privilege (to be precise: the "
1040 "B<CAP_NET_BIND_SERVICE> capability is required)."
1044 #: build/C/man3/bindresvport.3:85
1045 msgid "All privileged ports are in use."
1049 #: build/C/man3/bindresvport.3:85
1051 msgid "B<EAFNOSUPPORT> (B<EPFNOSUPPORT> in glibc 2.7 and earlier)"
1055 #: build/C/man3/bindresvport.3:92
1056 msgid "I<sin> is not NULL and I<sin-E<gt>sin_family> is not B<AF_INET>."
1060 #: build/C/man3/bindresvport.3:92
1066 #: build/C/man3/bindresvport.3:93
1068 msgid "Multithreading (see pthreads(7))"
1072 #: build/C/man3/bindresvport.3:98
1074 "Before glibc 2.17, the B<bindresvport>() function uses a static variable "
1075 "that is not protected, so it is not thread-safe."
1078 #. commit f6da27e53695ad1cc0e2a9490358decbbfdff5e5
1080 #: build/C/man3/bindresvport.3:104
1082 "Since glibc 2.17, the B<bindresvport>() function uses a lock to protect "
1083 "static variable, so it is thread-safe."
1087 #: build/C/man3/bindresvport.3:107
1088 msgid "Not in POSIX.1-2001. Present on the BSDs, Solaris, and many other systems."
1092 #: build/C/man3/bindresvport.3:113
1094 "Unlike some B<bindresvport>() implementations, the glibc implementation "
1095 "ignores any value that the caller supplies in I<sin-E<gt>sin_port>."
1099 #: build/C/man3/bindresvport.3:116
1100 msgid "B<bind>(2), B<getsockname>(2)"
1104 #: build/C/man2/connect.2:67
1110 #: build/C/man2/connect.2:67 build/C/man2/getsockname.2:40 build/C/man2/getsockopt.2:44 build/C/man3/sockatmark.3:25
1116 #: build/C/man2/connect.2:70
1117 msgid "connect - initiate a connection on a socket"
1121 #: build/C/man2/connect.2:73 build/C/man2/getsockopt.2:50 build/C/man2/listen.2:51
1123 msgid "B<#include E<lt>sys/types.hE<gt>> /* See NOTES */\n"
1127 #: build/C/man2/connect.2:75 build/C/man2/getsockname.2:46 build/C/man2/getsockopt.2:52 build/C/man2/listen.2:53 build/C/man2/recv.2:51
1129 msgid "B<#include E<lt>sys/socket.hE<gt>>\n"
1133 #: build/C/man2/connect.2:78
1136 "B<int connect(int >I<sockfd>B<, const struct sockaddr *>I<addr>B<,>\n"
1137 "B< socklen_t >I<addrlen>B<);>\n"
1141 #: build/C/man2/connect.2:97
1143 "The B<connect>() system call connects the socket referred to by the file "
1144 "descriptor I<sockfd> to the address specified by I<addr>. The I<addrlen> "
1145 "argument specifies the size of I<addr>. The format of the address in "
1146 "I<addr> is determined by the address space of the socket I<sockfd>; see "
1147 "B<socket>(2) for further details."
1151 #: build/C/man2/connect.2:113
1153 "If the socket I<sockfd> is of type B<SOCK_DGRAM> then I<addr> is the address "
1154 "to which datagrams are sent by default, and the only address from which "
1155 "datagrams are received. If the socket is of type B<SOCK_STREAM> or "
1156 "B<SOCK_SEQPACKET>, this call attempts to make a connection to the socket "
1157 "that is bound to the address specified by I<addr>."
1161 #: build/C/man2/connect.2:127
1163 "Generally, connection-based protocol sockets may successfully B<connect>() "
1164 "only once; connectionless protocol sockets may use B<connect>() multiple "
1165 "times to change their association. Connectionless sockets may dissolve the "
1166 "association by connecting to an address with the I<sa_family> member of "
1167 "I<sockaddr> set to B<AF_UNSPEC> (supported on Linux since kernel 2.2)."
1171 #: build/C/man2/connect.2:132
1173 "If the connection or binding succeeds, zero is returned. On error, -1 is "
1174 "returned, and I<errno> is set appropriately."
1178 #: build/C/man2/connect.2:135
1180 "The following are general socket errors only. There may be other "
1181 "domain-specific error codes."
1185 #: build/C/man2/connect.2:143
1187 "For UNIX domain sockets, which are identified by pathname: Write permission "
1188 "is denied on the socket file, or search permission is denied for one of the "
1189 "directories in the path prefix. (See also B<path_resolution>(7).)"
1193 #: build/C/man2/connect.2:143
1195 msgid "B<EACCES>, B<EPERM>"
1199 #: build/C/man2/connect.2:148
1201 "The user tried to connect to a broadcast address without having the socket "
1202 "broadcast flag enabled or the connection request failed because of a local "
1207 #: build/C/man2/connect.2:151
1208 msgid "Local address is already in use."
1212 #: build/C/man2/connect.2:151 build/C/man2/socket.2:324 build/C/man2/socketpair.2:75
1214 msgid "B<EAFNOSUPPORT>"
1218 #: build/C/man2/connect.2:156
1220 "The passed address didn't have the correct address family in its "
1221 "I<sa_family> field."
1225 #: build/C/man2/connect.2:156
1231 #: build/C/man2/connect.2:165
1233 "No more free local ports or insufficient entries in the routing cache. For "
1234 "B<AF_INET> see the description of I</proc/sys/net/ipv4/ip_local_port_range> "
1235 "B<ip>(7) for information on how to increase the number of local ports."
1239 #: build/C/man2/connect.2:165
1245 #: build/C/man2/connect.2:169
1247 "The socket is nonblocking and a previous connection attempt has not yet been "
1252 #: build/C/man2/connect.2:172
1253 msgid "The file descriptor is not a valid index in the descriptor table."
1257 #: build/C/man2/connect.2:172 build/C/man2/recv.2:415
1259 msgid "B<ECONNREFUSED>"
1263 #: build/C/man2/connect.2:175
1264 msgid "No-one listening on the remote address."
1268 #: build/C/man2/connect.2:178
1269 msgid "The socket structure address is outside the user's address space."
1273 #: build/C/man2/connect.2:178
1275 msgid "B<EINPROGRESS>"
1279 #: build/C/man2/connect.2:203
1281 "The socket is nonblocking and the connection cannot be completed "
1282 "immediately. It is possible to B<select>(2) or B<poll>(2) for completion "
1283 "by selecting the socket for writing. After B<select>(2) indicates "
1284 "writability, use B<getsockopt>(2) to read the B<SO_ERROR> option at level "
1285 "B<SOL_SOCKET> to determine whether B<connect>() completed successfully "
1286 "(B<SO_ERROR> is zero) or unsuccessfully (B<SO_ERROR> is one of the usual "
1287 "error codes listed here, explaining the reason for the failure)."
1290 #. For TCP, the connection will complete asynchronously.
1291 #. See http://lkml.org/lkml/2005/7/12/254
1293 #: build/C/man2/connect.2:209
1295 "The system call was interrupted by a signal that was caught; see "
1300 #: build/C/man2/connect.2:209 build/C/man2/send.2:323
1306 #: build/C/man2/connect.2:212
1307 msgid "The socket is already connected."
1311 #: build/C/man2/connect.2:212
1313 msgid "B<ENETUNREACH>"
1317 #: build/C/man2/connect.2:215
1318 msgid "Network is unreachable."
1322 #: build/C/man2/connect.2:218
1323 msgid "The file descriptor is not associated with a socket."
1327 #: build/C/man2/connect.2:218
1329 msgid "B<ETIMEDOUT>"
1333 #: build/C/man2/connect.2:225
1335 "Timeout while attempting connection. The server may be too busy to accept "
1336 "new connections. Note that for IP sockets the timeout may be very long when "
1337 "syncookies are enabled on the server."
1340 #. SVr4 documents the additional
1341 #. general error codes
1342 #. .BR EADDRNOTAVAIL ,
1344 #. .BR EAFNOSUPPORT ,
1351 #. documents many additional error conditions not described here.
1353 #: build/C/man2/connect.2:241
1355 "SVr4, 4.4BSD, (the B<connect>() function first appeared in 4.2BSD), "
1360 #: build/C/man2/connect.2:258
1362 "The third argument of B<connect>() is in reality an I<int> (and this is "
1363 "what 4.x BSD and libc4 and libc5 have). Some POSIX confusion resulted in "
1364 "the present I<socklen_t>, also used by glibc. See also B<accept>(2)."
1368 #: build/C/man2/connect.2:263
1369 msgid "An example of the use of B<connect>() is shown in B<getaddrinfo>(3)."
1373 #: build/C/man2/connect.2:270
1375 "B<accept>(2), B<bind>(2), B<getsockname>(2), B<listen>(2), B<socket>(2), "
1376 "B<path_resolution>(7)"
1380 #: build/C/man3/getifaddrs.3:36
1386 #: build/C/man3/getifaddrs.3:36
1392 #: build/C/man3/getifaddrs.3:36 build/C/man3/if_nameindex.3:26 build/C/man3/if_nametoindex.3:25
1398 #: build/C/man3/getifaddrs.3:39
1399 msgid "getifaddrs, freeifaddrs - get interface addresses"
1403 #: build/C/man3/getifaddrs.3:43
1406 "B<#include E<lt>sys/types.hE<gt>>\n"
1407 "B<#include E<lt>ifaddrs.hE<gt>>\n"
1411 #: build/C/man3/getifaddrs.3:45
1413 msgid "B<int getifaddrs(struct ifaddrs **>I<ifap>B<);>\n"
1417 #: build/C/man3/getifaddrs.3:47
1419 msgid "B<void freeifaddrs(struct ifaddrs *>I<ifa>B<);>\n"
1423 #: build/C/man3/getifaddrs.3:58
1425 "The B<getifaddrs>() function creates a linked list of structures describing "
1426 "the network interfaces of the local system, and stores the address of the "
1427 "first item of the list in I<*ifap>. The list consists of I<ifaddrs> "
1428 "structures, defined as follows:"
1432 #: build/C/man3/getifaddrs.3:77
1435 "struct ifaddrs {\n"
1436 " struct ifaddrs *ifa_next; /* Next item in list */\n"
1437 " char *ifa_name; /* Name of interface */\n"
1438 " unsigned int ifa_flags; /* Flags from SIOCGIFFLAGS */\n"
1439 " struct sockaddr *ifa_addr; /* Address of interface */\n"
1440 " struct sockaddr *ifa_netmask; /* Netmask of interface */\n"
1442 " struct sockaddr *ifu_broadaddr;\n"
1443 " /* Broadcast address of interface */\n"
1444 " struct sockaddr *ifu_dstaddr;\n"
1445 " /* Point-to-point destination address */\n"
1447 "#define ifa_broadaddr ifa_ifu.ifu_broadaddr\n"
1448 "#define ifa_dstaddr ifa_ifu.ifu_dstaddr\n"
1449 " void *ifa_data; /* Address-specific data */\n"
1454 #: build/C/man3/getifaddrs.3:84
1456 "The I<ifa_next> field contains a pointer to the next structure on the list, "
1457 "or NULL if this is the last item of the list."
1462 #. indicates the maximum length of this field.
1464 #: build/C/man3/getifaddrs.3:91
1465 msgid "The I<ifa_name> points to the null-terminated interface name."
1469 #: build/C/man3/getifaddrs.3:100
1471 "The I<ifa_flags> field contains the interface flags, as returned by the "
1472 "B<SIOCGIFFLAGS> B<ioctl>(2) operation (see B<netdevice>(7) for a list of "
1477 #: build/C/man3/getifaddrs.3:109
1479 "The I<ifa_addr> field points to a structure containing the interface "
1480 "address. (The I<sa_family> subfield should be consulted to determine the "
1481 "format of the address structure.) This field may contain a NULL pointer."
1485 #: build/C/man3/getifaddrs.3:116
1487 "The I<ifa_netmask> field points to a structure containing the netmask "
1488 "associated with I<ifa_addr>, if applicable for the address family. This "
1489 "field may contain a NULL pointer."
1493 #: build/C/man3/getifaddrs.3:131
1495 "Depending on whether the bit B<IFF_BROADCAST> or B<IFF_POINTOPOINT> is set "
1496 "in I<ifa_flags> (only one can be set at a time), either I<ifa_broadaddr> "
1497 "will contain the broadcast address associated with I<ifa_addr> (if "
1498 "applicable for the address family) or I<ifa_dstaddr> will contain the "
1499 "destination address of the point-to-point interface."
1503 #: build/C/man3/getifaddrs.3:136
1505 "The I<ifa_data> field points to a buffer containing address-family-specific "
1506 "data; this field may be NULL if there is no such data for this interface."
1510 #: build/C/man3/getifaddrs.3:142
1512 "The data returned by B<getifaddrs>() is dynamically allocated and should be "
1513 "freed using B<freeifaddrs>() when no longer needed."
1517 #: build/C/man3/getifaddrs.3:149
1519 "On success, B<getifaddrs>() returns zero; on error, -1 is returned, and "
1520 "I<errno> is set appropriately."
1524 #: build/C/man3/getifaddrs.3:162
1526 "B<getifaddrs>() may fail and set I<errno> for any of the errors specified "
1527 "for B<socket>(2), B<bind>(2), B<getsockname>(2), B<recvmsg>(2), "
1528 "B<sendto>(2), B<malloc>(3), or B<realloc>(3)."
1532 #: build/C/man3/getifaddrs.3:170
1534 "The B<getifaddrs>() function first appeared in glibc 2.3, but before glibc "
1535 "2.3.3, the implementation supported only IPv4 addresses; IPv6 support was "
1536 "added in glibc 2.3.3. Support of address families other than IPv4 is "
1537 "available only on kernels that support netlink."
1540 #. , but the BSD-derived documentation generally
1541 #. appears to be confused and obsolete on this point.
1542 #. i.e., commonly it still says one of them will be NULL, even if
1543 #. the ifa_ifu union is already present
1545 #: build/C/man3/getifaddrs.3:190
1547 "Not in POSIX.1-2001. This function first appeared in BSDi and is present on "
1548 "the BSD systems, but with slightly different semantics "
1549 "documented\\(emreturning one entry per interface, not per address. This "
1550 "means I<ifa_addr> and other fields can actually be NULL if the interface has "
1551 "no address, and no link-level address is returned if the interface has an IP "
1552 "address assigned. Also, the way of choosing either I<ifa_broadaddr> or "
1553 "I<ifa_dstaddr> differs on various systems."
1557 #: build/C/man3/getifaddrs.3:207
1559 "The addresses returned on Linux will usually be the IPv4 and IPv6 addresses "
1560 "assigned to the interface, but also one B<AF_PACKET> address per interface "
1561 "containing lower-level details about the interface and its physical layer. "
1562 "In this case, the I<ifa_data> field may contain a pointer to a I<struct "
1563 "rtnl_link_stats>, defined in I<E<lt>linux/if_link.hE<gt>> (in Linux 2.4 and "
1564 "earlier, I<struct net_device_stats>, defined in "
1565 "I<E<lt>linux/netdevice.hE<gt>>), which contains various interface attributes "
1570 #: build/C/man3/getifaddrs.3:214
1572 "The program below demonstrates the use of B<getifaddrs>(), B<freeifaddrs>(), "
1573 "and B<getnameinfo>(3). Here is what we see when running this program on one "
1578 #: build/C/man3/getifaddrs.3:228
1582 "lo address family: 17 (AF_PACKET)\n"
1583 "eth0 address family: 17 (AF_PACKET)\n"
1584 "lo address family: 2 (AF_INET)\n"
1585 " address: E<lt>127.0.0.1E<gt>\n"
1586 "eth0 address family: 2 (AF_INET)\n"
1587 " address: E<lt>10.1.1.4E<gt>\n"
1588 "lo address family: 10 (AF_INET6)\n"
1589 " address: E<lt>::1E<gt>\n"
1590 "eth0 address family: 10 (AF_INET6)\n"
1591 " address: E<lt>fe80::2d0:59ff:feda:eb51%eth0E<gt>\n"
1595 #: build/C/man3/getifaddrs.3:230 build/C/man3/if_nameindex.3:120 build/C/man2/recvmmsg.2:206
1597 msgid "Program source"
1601 #: build/C/man3/getifaddrs.3:240
1604 "#include E<lt>arpa/inet.hE<gt>\n"
1605 "#include E<lt>sys/socket.hE<gt>\n"
1606 "#include E<lt>netdb.hE<gt>\n"
1607 "#include E<lt>ifaddrs.hE<gt>\n"
1608 "#include E<lt>stdio.hE<gt>\n"
1609 "#include E<lt>stdlib.hE<gt>\n"
1610 "#include E<lt>unistd.hE<gt>\n"
1614 #: build/C/man3/getifaddrs.3:247
1618 "main(int argc, char *argv[])\n"
1620 " struct ifaddrs *ifaddr, *ifa;\n"
1622 " char host[NI_MAXHOST];\n"
1626 #: build/C/man3/getifaddrs.3:252
1629 " if (getifaddrs(&ifaddr) == -1) {\n"
1630 " perror(\"getifaddrs\");\n"
1631 " exit(EXIT_FAILURE);\n"
1636 #: build/C/man3/getifaddrs.3:255
1639 " /* Walk through linked list, maintaining head pointer so we\n"
1640 " can free list later */\n"
1644 #: build/C/man3/getifaddrs.3:259
1647 " for (ifa = ifaddr; ifa != NULL; ifa = ifa-E<gt>ifa_next) {\n"
1648 " if (ifa-E<gt>ifa_addr == NULL)\n"
1653 #: build/C/man3/getifaddrs.3:261
1655 msgid " family = ifa-E<gt>ifa_addr-E<gt>sa_family;\n"
1659 #: build/C/man3/getifaddrs.3:264
1662 " /* Display interface name and family (including symbolic\n"
1663 " form of the latter for the common families) */\n"
1667 #: build/C/man3/getifaddrs.3:270
1670 " printf(\"%s\\t address family: %d%s\\en\",\n"
1671 " ifa-E<gt>ifa_name, family,\n"
1672 " (family == AF_PACKET) ? \" (AF_PACKET)\" :\n"
1673 " (family == AF_INET) ? \" (AF_INET)\" :\n"
1674 " (family == AF_INET6) ? \" (AF_INET6)\" : \"\");\n"
1678 #: build/C/man3/getifaddrs.3:272
1680 msgid " /* For an AF_INET* interface address, display the address */\n"
1684 #: build/C/man3/getifaddrs.3:285
1687 " if (family == AF_INET || family == AF_INET6) {\n"
1688 " s = getnameinfo(ifa-E<gt>ifa_addr,\n"
1689 " (family == AF_INET) ? sizeof(struct sockaddr_in) :\n"
1690 " sizeof(struct sockaddr_in6),\n"
1691 " host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);\n"
1693 " printf(\"getnameinfo() failed: %s\\en\", gai_strerror(s));\n"
1694 " exit(EXIT_FAILURE);\n"
1696 " printf(\"\\etaddress: E<lt>%sE<gt>\\en\", host);\n"
1702 #: build/C/man3/getifaddrs.3:289
1705 " freeifaddrs(ifaddr);\n"
1706 " exit(EXIT_SUCCESS);\n"
1711 #: build/C/man3/getifaddrs.3:296
1712 msgid "B<bind>(2), B<getsockname>(2), B<socket>(2), B<packet>(7), B<ifconfig>(8)"
1716 #: build/C/man2/getsockname.2:40
1722 #: build/C/man2/getsockname.2:43
1723 msgid "getsockname - get socket name"
1727 #: build/C/man2/getsockname.2:49
1730 "B<int getsockname(int >I<sockfd>B<, struct sockaddr *>I<addr>B<, socklen_t "
1731 "*>I<addrlen>B<);>\n"
1735 #: build/C/man2/getsockname.2:62
1737 "B<getsockname>() returns the current address to which the socket I<sockfd> "
1738 "is bound, in the buffer pointed to by I<addr>. The I<addrlen> argument "
1739 "should be initialized to indicate the amount of space (in bytes) pointed to "
1740 "by I<addr>. On return it contains the actual size of the socket address."
1744 #: build/C/man2/getsockname.2:78 build/C/man2/getsockopt.2:142 build/C/man2/listen.2:96
1745 msgid "The argument I<sockfd> is not a valid descriptor."
1749 #: build/C/man2/getsockname.2:84
1751 "The I<addr> argument points to memory not in a valid part of the process "
1756 #: build/C/man2/getsockname.2:88
1757 msgid "I<addrlen> is invalid (e.g., is negative)."
1761 #: build/C/man2/getsockname.2:88 build/C/man3/if_nameindex.3:83 build/C/man2/send.2:335
1767 #: build/C/man2/getsockname.2:92
1769 "Insufficient resources were available in the system to perform the "
1774 #: build/C/man2/getsockname.2:97 build/C/man2/getsockopt.2:171
1775 msgid "The argument I<sockfd> is a file, not a socket."
1778 #. SVr4 documents additional ENOMEM
1779 #. and ENOSR error codes.
1781 #: build/C/man2/getsockname.2:103
1783 "SVr4, 4.4BSD (the B<getsockname>() function call appeared in 4.2BSD), "
1788 #: build/C/man2/getsockname.2:114
1790 "The third argument of B<getsockname>() is in reality an I<int\\ *> (and "
1791 "this is what 4.x BSD and libc4 and libc5 have). Some POSIX confusion "
1792 "resulted in the present I<socklen_t>, also used by glibc. See also "
1797 #: build/C/man2/getsockname.2:121
1799 "B<bind>(2), B<socket>(2), B<getifaddrs>(3), B<ip>(7), B<socket>(7), "
1804 #: build/C/man2/getsockopt.2:44
1810 #: build/C/man2/getsockopt.2:47
1811 msgid "getsockopt, setsockopt - get and set options on sockets"
1815 #: build/C/man2/getsockopt.2:57
1818 "B<int getsockopt(int >I<sockfd>B<, int >I<level>B<, int >I<optname>B<,>\n"
1819 "B< void *>I<optval>B<, socklen_t *>I<optlen>B<);>\n"
1820 "B<int setsockopt(int >I<sockfd>B<, int >I<level>B<, int >I<optname>B<,>\n"
1821 "B< const void *>I<optval>B<, socklen_t >I<optlen>B<);>\n"
1825 #: build/C/man2/getsockopt.2:67
1827 "B<getsockopt>() and B<setsockopt>() manipulate options for the socket "
1828 "referred to by the file descriptor I<sockfd>. Options may exist at multiple "
1829 "protocol levels; they are always present at the uppermost socket level."
1833 #: build/C/man2/getsockopt.2:86
1835 "When manipulating socket options, the level at which the option resides and "
1836 "the name of the option must be specified. To manipulate options at the "
1837 "sockets API level, I<level> is specified as B<SOL_SOCKET>. To manipulate "
1838 "options at any other level the protocol number of the appropriate protocol "
1839 "controlling the option is supplied. For example, to indicate that an option "
1840 "is to be interpreted by the B<TCP> protocol, I<level> should be set to the "
1841 "protocol number of B<TCP>; see B<getprotoent>(3)."
1845 #: build/C/man2/getsockopt.2:108
1847 "The arguments I<optval> and I<optlen> are used to access option values for "
1848 "B<setsockopt>(). For B<getsockopt>() they identify a buffer in which the "
1849 "value for the requested option(s) are to be returned. For B<getsockopt>(), "
1850 "I<optlen> is a value-result argument, initially containing the size of the "
1851 "buffer pointed to by I<optval>, and modified on return to indicate the "
1852 "actual size of the value returned. If no option value is to be supplied or "
1853 "returned, I<optval> may be NULL."
1857 #: build/C/man2/getsockopt.2:118
1859 "I<Optname> and any specified options are passed uninterpreted to the "
1860 "appropriate protocol module for interpretation. The include file "
1861 "I<E<lt>sys/socket.hE<gt>> contains definitions for socket level options, "
1862 "described below. Options at other protocol levels vary in format and name; "
1863 "consult the appropriate entries in section 4 of the manual."
1867 #: build/C/man2/getsockopt.2:127
1869 "Most socket-level options utilize an I<int> argument for I<optval>. For "
1870 "B<setsockopt>(), the argument should be nonzero to enable a boolean option, "
1871 "or zero if the option is to be disabled."
1875 #: build/C/man2/getsockopt.2:131
1877 "For a description of the available socket options see B<socket>(7) and the "
1878 "appropriate protocol man pages."
1882 #: build/C/man2/getsockopt.2:152
1884 "The address pointed to by I<optval> is not in a valid part of the process "
1885 "address space. For B<getsockopt>(), this error may also be returned if "
1886 "I<optlen> is not in a valid part of the process address space."
1890 #: build/C/man2/getsockopt.2:163
1892 "I<optlen> invalid in B<setsockopt>(). In some cases this error can also "
1893 "occur for an invalid value in I<optval> (e.g., for the B<IP_ADD_MEMBERSHIP> "
1894 "option described in B<ip>(7))."
1898 #: build/C/man2/getsockopt.2:163
1900 msgid "B<ENOPROTOOPT>"
1904 #: build/C/man2/getsockopt.2:166
1905 msgid "The option is unknown at the level indicated."
1908 #. SVr4 documents additional ENOMEM and ENOSR error codes, but does
1910 #. .BR SO_SNDLOWAT ", " SO_RCVLOWAT ", " SO_SNDTIMEO ", " SO_RCVTIMEO
1913 #: build/C/man2/getsockopt.2:178
1914 msgid "SVr4, 4.4BSD (these system calls first appeared in 4.2BSD), POSIX.1-2001."
1918 #: build/C/man2/getsockopt.2:199
1920 "The I<optlen> argument of B<getsockopt>() and B<setsockopt>() is in "
1921 "reality an I<int [*]> (and this is what 4.x BSD and libc4 and libc5 have). "
1922 "Some POSIX confusion resulted in the present I<socklen_t>, also used by "
1923 "glibc. See also B<accept>(2)."
1927 #: build/C/man2/getsockopt.2:202
1929 "Several of the socket options should be handled at lower levels of the "
1934 #: build/C/man2/getsockopt.2:210
1936 "B<ioctl>(2), B<socket>(2), B<getprotoent>(3), B<protocols>(5), B<socket>(7), "
1937 "B<tcp>(7), B<unix>(7)"
1941 #: build/C/man3/if_nameindex.3:26
1943 msgid "IF_NAMEINDEX"
1947 #: build/C/man3/if_nameindex.3:26
1953 #: build/C/man3/if_nameindex.3:29
1954 msgid "if_nameindex, if_freenameindex - get network interface names and indexes"
1958 #: build/C/man3/if_nameindex.3:32 build/C/man3/if_nametoindex.3:32
1960 msgid "B<#include E<lt>net/if.hE<gt>>\n"
1964 #: build/C/man3/if_nameindex.3:35
1967 "B<struct if_nameindex *if_nameindex(void);>\n"
1968 "B<void if_freenameindex(struct if_nameindex *>I<ptr>B<);>\n"
1972 #: build/C/man3/if_nameindex.3:46
1974 "The B<if_nameindex>() function returns an array of I<if_nameindex> "
1975 "structures, each containing information about one of the network interfaces "
1976 "on the local system. The I<if_nameindex> structure contains at least the "
1977 "following entries:"
1981 #: build/C/man3/if_nameindex.3:51
1984 " unsigned int if_index; /* Index of interface (1, 2, ...) */\n"
1985 " char *if_name; /* Null-terminated name (\"eth0\", etc.) */\n"
1989 #: build/C/man3/if_nameindex.3:65
1991 "The I<if_index> field contains the interface index. The I<ifa_name> field "
1992 "points to the null-terminated interface name. The end of the array is "
1993 "indicated by entry with I<if_index> set to zero and I<ifa_name> set to NULL."
1997 #: build/C/man3/if_nameindex.3:71
1999 "The data structure returned by B<if_nameindex>() is dynamically allocated "
2000 "and should be freed using B<if_freenameindex>() when no longer needed."
2004 #: build/C/man3/if_nameindex.3:78
2006 "On success, B<if_nameindex>() returns pointer to the array; on error, a "
2007 "NULL pointer is returned, and I<errno> is set appropriately."
2011 #: build/C/man3/if_nameindex.3:83
2012 msgid "B<if_nameindex>() may fail and set I<errno> if:"
2016 #: build/C/man3/if_nameindex.3:86
2017 msgid "Insufficient resources available."
2021 #: build/C/man3/if_nameindex.3:97
2023 "B<if_nameindex>() may also fail for any of the errors specified for "
2024 "B<socket>(2), B<bind>(2), B<ioctl>(2), B<getsockname>(2), B<recvmsg>(2), "
2025 "B<sendto>(2), or B<malloc>(3)."
2029 #: build/C/man3/if_nameindex.3:104
2031 "The B<if_nameindex>() function first appeared in glibc 2.1, but before "
2032 "glibc 2.3.4, the implementation supported only interfaces with IPv4 "
2033 "addresses. Support of interfaces that don't have IPv4 addresses is "
2034 "available only on kernels that support netlink."
2038 #: build/C/man3/if_nameindex.3:106 build/C/man3/if_nametoindex.3:87
2039 msgid "RFC\\ 3493, POSIX.1-2001."
2043 #: build/C/man3/if_nameindex.3:108 build/C/man3/if_nametoindex.3:89
2044 msgid "This function first appeared in BSDi."
2048 #: build/C/man3/if_nameindex.3:112
2050 "The program below demonstrates the use of the functions described on this "
2051 "page. An example of the output this program might produce is the following:"
2055 #: build/C/man3/if_nameindex.3:118
2065 #: build/C/man3/if_nameindex.3:126
2068 "#include E<lt>net/if.hE<gt>\n"
2069 "#include E<lt>stdio.hE<gt>\n"
2070 "#include E<lt>stdlib.hE<gt>\n"
2071 "#include E<lt>unistd.hE<gt>\n"
2075 #: build/C/man3/if_nameindex.3:131
2079 "main(int argc, char *argv[])\n"
2081 " struct if_nameindex *if_ni, *i;\n"
2085 #: build/C/man3/if_nameindex.3:137
2088 " if_ni = if_nameindex();\n"
2089 " if (if_ni == NULL) {\n"
2090 " perror(\"if_nameindex\");\n"
2091 " exit(EXIT_FAILURE);\n"
2096 #: build/C/man3/if_nameindex.3:140
2099 " for (i = if_ni; ! (i-E<gt>if_index == 0 && i-E<gt>if_name == NULL); "
2101 " printf(\"%u: %s\\en\", i-E<gt>if_index, i-E<gt>if_name);\n"
2105 #: build/C/man3/if_nameindex.3:142
2107 msgid " if_freenameindex(if_ni);\n"
2111 #: build/C/man3/if_nameindex.3:145 build/C/man2/select.2:573
2114 " exit(EXIT_SUCCESS);\n"
2119 #: build/C/man3/if_nameindex.3:153
2121 "B<getsockopt>(2), B<setsockopt>(2), B<getifaddrs>(3), B<if_indextoname>(3), "
2122 "B<if_nametoindex>(3), B<ifconfig>(8)"
2126 #: build/C/man3/if_nametoindex.3:25
2128 msgid "IF_NAMETOINDEX"
2132 #: build/C/man3/if_nametoindex.3:25
2138 #: build/C/man3/if_nametoindex.3:29
2140 "if_nametoindex, if_indextoname - mappings between network interface names "
2145 #: build/C/man3/if_nametoindex.3:34
2147 msgid "B<unsigned int if_nametoindex(const char *>I<ifname>B<);>\n"
2151 #: build/C/man3/if_nametoindex.3:36
2153 msgid "B<char *if_indextoname(unsigned int ifindex, char *>I<ifname>B<);>\n"
2157 #: build/C/man3/if_nametoindex.3:43
2159 "The B<if_nametoindex>() function returns the index of the network interface "
2160 "corresponding to the name I<ifname>."
2164 #: build/C/man3/if_nametoindex.3:54
2166 "The B<if_indextoname>() function returns the name of the network interface "
2167 "corresponding to the interface index I<ifindex>. The name is placed in the "
2168 "buffer pointed to by I<ifname>. The buffer must allow for the storage of at "
2169 "least B<IF_NAMESIZE> bytes."
2173 #: build/C/man3/if_nametoindex.3:61
2175 "On success, B<if_nametoindex>() returns the index number of the network "
2176 "interface; on error, 0 is returned and I<errno> is set appropriately."
2180 #: build/C/man3/if_nametoindex.3:69
2182 "On success, B<if_indextoname>() returns I<ifname>; on error, NULL is "
2183 "returned and I<errno> is set appropriately."
2187 #: build/C/man3/if_nametoindex.3:74
2188 msgid "B<if_indextoname>() may fail and set I<errno> if:"
2192 #: build/C/man3/if_nametoindex.3:74
2198 #: build/C/man3/if_nametoindex.3:77
2199 msgid "No interface found for the index."
2203 #: build/C/man3/if_nametoindex.3:85
2205 "B<if_nametoindex>() and B<if_indextoname>() may also fail for any of the "
2206 "errors specified for B<socket>(2) or B<ioctl>(2)."
2210 #: build/C/man3/if_nametoindex.3:93
2211 msgid "B<getifaddrs>(3), B<if_nameindex>(3), B<ifconfig>(8)"
2215 #: build/C/man2/listen.2:45
2221 #: build/C/man2/listen.2:45
2227 #: build/C/man2/listen.2:48
2228 msgid "listen - listen for connections on a socket"
2232 #: build/C/man2/listen.2:55
2234 msgid "B<int listen(int >I<sockfd>B<, int >I<backlog>B<);>\n"
2238 #: build/C/man2/listen.2:63
2240 "B<listen>() marks the socket referred to by I<sockfd> as a passive socket, "
2241 "that is, as a socket that will be used to accept incoming connection "
2242 "requests using B<accept>(2)."
2246 #: build/C/man2/listen.2:70
2248 "The I<sockfd> argument is a file descriptor that refers to a socket of type "
2249 "B<SOCK_STREAM> or B<SOCK_SEQPACKET>."
2253 #: build/C/man2/listen.2:82
2255 "The I<backlog> argument defines the maximum length to which the queue of "
2256 "pending connections for I<sockfd> may grow. If a connection request arrives "
2257 "when the queue is full, the client may receive an error with an indication "
2258 "of B<ECONNREFUSED> or, if the underlying protocol supports retransmission, "
2259 "the request may be ignored so that a later reattempt at connection succeeds."
2263 #: build/C/man2/listen.2:91
2264 msgid "Another socket is already listening on the same port."
2268 #: build/C/man2/listen.2:101 build/C/man2/send.2:354
2269 msgid "The argument I<sockfd> is not a socket."
2273 #: build/C/man2/listen.2:106
2274 msgid "The socket is not of a type that supports the B<listen>() operation."
2278 #: build/C/man2/listen.2:111
2280 "4.4BSD, POSIX.1-2001. The B<listen>() function call first appeared in "
2285 #: build/C/man2/listen.2:113
2286 msgid "To accept connections, the following steps are performed:"
2290 #: build/C/man2/listen.2:114 build/C/man2/select_tut.2:347
2296 #: build/C/man2/listen.2:117
2297 msgid "A socket is created with B<socket>(2)."
2301 #: build/C/man2/listen.2:117 build/C/man2/select_tut.2:356
2307 #: build/C/man2/listen.2:123
2309 "The socket is bound to a local address using B<bind>(2), so that other "
2310 "sockets may be B<connect>(2)ed to it."
2314 #: build/C/man2/listen.2:123 build/C/man2/select_tut.2:360
2320 #: build/C/man2/listen.2:127
2322 "A willingness to accept incoming connections and a queue limit for incoming "
2323 "connections are specified with B<listen>()."
2327 #: build/C/man2/listen.2:127 build/C/man2/select_tut.2:367
2333 #: build/C/man2/listen.2:130
2334 msgid "Connections are accepted with B<accept>(2)."
2338 #: build/C/man2/listen.2:153
2340 "The behavior of the I<backlog> argument on TCP sockets changed with Linux "
2341 "2.2. Now it specifies the queue length for I<completely> established "
2342 "sockets waiting to be accepted, instead of the number of incomplete "
2343 "connection requests. The maximum length of the queue for incomplete sockets "
2344 "can be set using I</proc/sys/net/ipv4/tcp_max_syn_backlog>. When syncookies "
2345 "are enabled there is no logical maximum length and this setting is ignored. "
2346 "See B<tcp>(7) for more information."
2349 #. The following is now rather historic information (MTK, Jun 05)
2350 #. Don't rely on this value in portable applications since BSD
2351 #. (and some BSD-derived systems) limit the backlog to 5.
2353 #: build/C/man2/listen.2:166
2355 "If the I<backlog> argument is greater than the value in "
2356 "I</proc/sys/net/core/somaxconn>, then it is silently truncated to that "
2357 "value; the default value in this file is 128. In kernels before 2.4.25, "
2358 "this limit was a hard coded value, B<SOMAXCONN>, with the value 128."
2362 #: build/C/man2/listen.2:175
2363 msgid "B<accept>(2), B<bind>(2), B<connect>(2), B<socket>(2), B<socket>(7)"
2367 #: build/C/man2/recv.2:41
2373 #: build/C/man2/recv.2:41
2379 #: build/C/man2/recv.2:44
2380 msgid "recv, recvfrom, recvmsg - receive a message from a socket"
2384 #: build/C/man2/recv.2:49 build/C/man2/select.2:53 build/C/man2/select_tut.2:47
2386 msgid "B<#include E<lt>sys/types.hE<gt>>\n"
2390 #: build/C/man2/recv.2:53
2393 "B<ssize_t recv(int >I<sockfd>B<, void *>I<buf>B<, size_t >I<len>B<, int "
2398 #: build/C/man2/recv.2:56
2401 "B<ssize_t recvfrom(int >I<sockfd>B<, void *>I<buf>B<, size_t >I<len>B<, int "
2403 "B< struct sockaddr *>I<src_addr>B<, socklen_t "
2404 "*>I<addrlen>B<);>\n"
2408 #: build/C/man2/recv.2:58
2411 "B<ssize_t recvmsg(int >I<sockfd>B<, struct msghdr *>I<msg>B<, int "
2416 #: build/C/man2/recv.2:66
2418 "The B<recvfrom>() and B<recvmsg>() calls are used to receive messages from "
2419 "a socket, and may be used to receive data on a socket whether or not it is "
2420 "connection-oriented."
2423 #. (Note: for datagram sockets in both the UNIX and Internet domains,
2427 #. is also filled in for stream sockets in the UNIX domain, but is not
2428 #. filled in for stream sockets in the Internet domain.)
2429 #. [The above notes on AF_UNIX and AF_INET sockets apply as at
2430 #. Kernel 2.4.18. (MTK, 22 Jul 02)]
2432 #: build/C/man2/recv.2:95
2434 "If I<src_addr> is not NULL, and the underlying protocol provides the source "
2435 "address, this source address is filled in. When I<src_addr> is NULL, "
2436 "nothing is filled in; in this case, I<addrlen> is not used, and should also "
2437 "be NULL. The argument I<addrlen> is a value-result argument, which the "
2438 "caller should initialize before the call to the size of the buffer "
2439 "associated with I<src_addr>, and modified on return to indicate the actual "
2440 "size of the source address. The returned address is truncated if the buffer "
2441 "provided is too small; in this case, I<addrlen> will return a value greater "
2442 "than was supplied to the call."
2446 #: build/C/man2/recv.2:107
2448 "The B<recv>() call is normally used only on a I<connected> socket (see "
2449 "B<connect>(2)) and is identical to B<recvfrom>() with a NULL I<src_addr> "
2454 #: build/C/man2/recv.2:113
2456 "All three routines return the length of the message on successful "
2457 "completion. If a message is too long to fit in the supplied buffer, excess "
2458 "bytes may be discarded depending on the type of socket the message is "
2463 #: build/C/man2/recv.2:123
2465 "If no messages are available at the socket, the receive calls wait for a "
2466 "message to arrive, unless the socket is nonblocking (see B<fcntl>(2)), in "
2467 "which case the value -1 is returned and the external variable I<errno> is "
2468 "set to B<EAGAIN> or B<EWOULDBLOCK>. The receive calls normally return any "
2469 "data available, up to the requested amount, rather than waiting for receipt "
2470 "of the full amount requested."
2474 #: build/C/man2/recv.2:129
2476 "The B<select>(2) or B<poll>(2) call may be used to determine when more "
2481 #: build/C/man2/recv.2:135
2483 "The I<flags> argument to a B<recv>() call is formed by ORing one or more of "
2484 "the following values:"
2488 #: build/C/man2/recv.2:135
2490 msgid "B<MSG_CMSG_CLOEXEC> (B<recvmsg>() only; since Linux 2.6.23)"
2494 #: build/C/man2/recv.2:146
2496 "Set the close-on-exec flag for the file descriptor received via a UNIX "
2497 "domain file descriptor using the B<SCM_RIGHTS> operation (described in "
2498 "B<unix>(7)). This flag is useful for the same reasons as the B<O_CLOEXEC> "
2499 "flag of B<open>(2)."
2503 #: build/C/man2/recv.2:146 build/C/man2/send.2:188
2505 msgid "B<MSG_DONTWAIT> (since Linux 2.2)"
2509 #: build/C/man2/recv.2:156
2511 "Enables nonblocking operation; if the operation would block, the call fails "
2512 "with the error B<EAGAIN> or B<EWOULDBLOCK> (this can also be enabled using "
2513 "the B<O_NONBLOCK> flag with the B<F_SETFL> B<fcntl>(2))."
2517 #: build/C/man2/recv.2:156
2519 msgid "B<MSG_ERRQUEUE> (since Linux 2.2)"
2523 #: build/C/man2/recv.2:175
2525 "This flag specifies that queued errors should be received from the socket "
2526 "error queue. The error is passed in an ancillary message with a type "
2527 "dependent on the protocol (for IPv4 B<IP_RECVERR>). The user should supply "
2528 "a buffer of sufficient size. See B<cmsg>(3) and B<ip>(7) for more "
2529 "information. The payload of the original packet that caused the error is "
2530 "passed as normal data via I<msg_iovec>. The original destination address of "
2531 "the datagram that caused the error is supplied via I<msg_name>."
2535 #: build/C/man2/recv.2:187 build/C/man2/recv.2:250
2537 "For local errors, no address is passed (this can be checked with the "
2538 "I<cmsg_len> member of the I<cmsghdr>). For error receives, the "
2539 "B<MSG_ERRQUEUE> is set in the I<msghdr>. After an error has been passed, "
2540 "the pending socket error is regenerated based on the next queued error and "
2541 "will be passed on the next socket operation."
2545 #: build/C/man2/recv.2:191
2546 msgid "The error is supplied in a I<sock_extended_err> structure:"
2550 #: build/C/man2/recv.2:198
2553 "#define SO_EE_ORIGIN_NONE 0\n"
2554 "#define SO_EE_ORIGIN_LOCAL 1\n"
2555 "#define SO_EE_ORIGIN_ICMP 2\n"
2556 "#define SO_EE_ORIGIN_ICMP6 3\n"
2560 #: build/C/man2/recv.2:210
2563 "struct sock_extended_err\n"
2565 " uint32_t ee_errno; /* error number */\n"
2566 " uint8_t ee_origin; /* where the error originated */\n"
2567 " uint8_t ee_type; /* type */\n"
2568 " uint8_t ee_code; /* code */\n"
2569 " uint8_t ee_pad; /* padding */\n"
2570 " uint32_t ee_info; /* additional information */\n"
2571 " uint32_t ee_data; /* other data */\n"
2572 " /* More data may follow */\n"
2577 #: build/C/man2/recv.2:212
2579 msgid "struct sockaddr *SO_EE_OFFENDER(struct sock_extended_err *);\n"
2583 #: build/C/man2/recv.2:236
2585 "I<ee_errno> contains the I<errno> number of the queued error. I<ee_origin> "
2586 "is the origin code of where the error originated. The other fields are "
2587 "protocol-specific. The macro B<SOCK_EE_OFFENDER> returns a pointer to the "
2588 "address of the network object where the error originated from given a "
2589 "pointer to the ancillary message. If this address is not known, the "
2590 "I<sa_family> member of the I<sockaddr> contains B<AF_UNSPEC> and the other "
2591 "fields of the I<sockaddr> are undefined. The payload of the packet that "
2592 "caused the error is passed as normal data."
2596 #: build/C/man2/recv.2:250 build/C/man2/recv.2:381 build/C/man2/send.2:230
2602 #: build/C/man2/recv.2:257
2604 "This flag requests receipt of out-of-band data that would not be received in "
2605 "the normal data stream. Some protocols place expedited data at the head of "
2606 "the normal data queue, and thus this flag cannot be used with such "
2611 #: build/C/man2/recv.2:257
2617 #: build/C/man2/recv.2:264
2619 "This flag causes the receive operation to return data from the beginning of "
2620 "the receive queue without removing that data from the queue. Thus, a "
2621 "subsequent receive call will return the same data."
2625 #: build/C/man2/recv.2:264
2627 msgid "B<MSG_TRUNC> (since Linux 2.2)"
2631 #: build/C/man2/recv.2:275
2633 "For raw (B<AF_PACKET>), Internet datagram (since Linux 2.4.27/2.6.8), "
2634 "netlink (since Linux 2.6.22) and UNIX datagram (since Linux 3.4) sockets: "
2635 "return the real length of the packet or datagram, even when it was longer "
2636 "than the passed buffer. Not implemented for UNIX domain (B<unix>(7)) "
2641 #: build/C/man2/recv.2:278
2642 msgid "For use with Internet stream sockets, see B<tcp>(7)."
2646 #: build/C/man2/recv.2:278
2648 msgid "B<MSG_WAITALL> (since Linux 2.2)"
2652 #: build/C/man2/recv.2:285
2654 "This flag requests that the operation block until the full request is "
2655 "satisfied. However, the call may still return less data than requested if a "
2656 "signal is caught, an error or disconnect occurs, or the next data to be "
2657 "received is of a different type than that returned."
2661 #: build/C/man2/recv.2:293
2663 "The B<recvmsg>() call uses a I<msghdr> structure to minimize the number of "
2664 "directly supplied arguments. This structure is defined as follows in "
2665 "I<E<lt>sys/socket.hE<gt>>:"
2669 #: build/C/man2/recv.2:300
2672 "struct iovec { /* Scatter/gather array items */\n"
2673 " void *iov_base; /* Starting address */\n"
2674 " size_t iov_len; /* Number of bytes to transfer */\n"
2679 #: build/C/man2/recv.2:310 build/C/man2/send.2:258
2683 " void *msg_name; /* optional address */\n"
2684 " socklen_t msg_namelen; /* size of address */\n"
2685 " struct iovec *msg_iov; /* scatter/gather array */\n"
2686 " size_t msg_iovlen; /* # elements in msg_iov */\n"
2687 " void *msg_control; /* ancillary data, see below */\n"
2688 " size_t msg_controllen; /* ancillary data buffer len */\n"
2689 " int msg_flags; /* flags on received message */\n"
2694 #: build/C/man2/recv.2:340
2696 "Here I<msg_name> and I<msg_namelen> specify the source address if the socket "
2697 "is unconnected; I<msg_name> may be given as a NULL pointer if no names are "
2698 "desired or required. The fields I<msg_iov> and I<msg_iovlen> describe "
2699 "scatter-gather locations, as discussed in B<readv>(2). The field "
2700 "I<msg_control>, which has length I<msg_controllen>, points to a buffer for "
2701 "other protocol control-related messages or miscellaneous ancillary data. "
2702 "When B<recvmsg>() is called, I<msg_controllen> should contain the length of "
2703 "the available buffer in I<msg_control>; upon return from a successful call "
2704 "it will contain the length of the control message sequence."
2708 #: build/C/man2/recv.2:342
2709 msgid "The messages are of the form:"
2713 #: build/C/man2/recv.2:352
2716 "struct cmsghdr {\n"
2717 " socklen_t cmsg_len; /* data byte count, including hdr */\n"
2718 " int cmsg_level; /* originating protocol */\n"
2719 " int cmsg_type; /* protocol-specific type */\n"
2721 " unsigned char cmsg_data[]; */\n"
2726 #: build/C/man2/recv.2:357
2727 msgid "Ancillary data should be accessed only by the macros defined in B<cmsg>(3)."
2731 #: build/C/man2/recv.2:360
2733 "As an example, Linux uses this ancillary data mechanism to pass extended "
2734 "errors, IP options, or file descriptors over UNIX domain sockets."
2738 #: build/C/man2/recv.2:368
2740 "The I<msg_flags> field in the I<msghdr> is set on return of B<recvmsg>(). "
2741 "It can contain several flags:"
2745 #: build/C/man2/recv.2:368
2751 #: build/C/man2/recv.2:373
2753 "indicates end-of-record; the data returned completed a record (generally "
2754 "used with sockets of type B<SOCK_SEQPACKET>)."
2758 #: build/C/man2/recv.2:373
2760 msgid "B<MSG_TRUNC>"
2764 #: build/C/man2/recv.2:377
2766 "indicates that the trailing portion of a datagram was discarded because the "
2767 "datagram was larger than the buffer supplied."
2771 #: build/C/man2/recv.2:377
2773 msgid "B<MSG_CTRUNC>"
2777 #: build/C/man2/recv.2:381
2779 "indicates that some control data were discarded due to lack of space in the "
2780 "buffer for ancillary data."
2784 #: build/C/man2/recv.2:384
2785 msgid "is returned to indicate that expedited or out-of-band data were received."
2789 #: build/C/man2/recv.2:384
2791 msgid "B<MSG_ERRQUEUE>"
2795 #: build/C/man2/recv.2:388
2797 "indicates that no data was received but an extended error from the socket "
2802 #: build/C/man2/recv.2:396
2804 "These calls return the number of bytes received, or -1 if an error "
2805 "occurred. In the event of an error, I<errno> is set to indicate the error. "
2806 "The return value will be 0 when the peer has performed an orderly shutdown."
2810 #: build/C/man2/recv.2:401
2812 "These are some standard errors generated by the socket layer. Additional "
2813 "errors may be generated and returned from the underlying protocol modules; "
2814 "see their manual pages."
2817 #. Actually EAGAIN on Linux
2819 #: build/C/man2/recv.2:410
2821 "The socket is marked nonblocking and the receive operation would block, or a "
2822 "receive timeout had been set and the timeout expired before data was "
2823 "received. POSIX.1-2001 allows either error to be returned for this case, "
2824 "and does not require these constants to have the same value, so a portable "
2825 "application should check for both possibilities."
2829 #: build/C/man2/recv.2:415
2830 msgid "The argument I<sockfd> is an invalid descriptor."
2834 #: build/C/man2/recv.2:419
2836 "A remote host refused to allow the network connection (typically because it "
2837 "is not running the requested service)."
2841 #: build/C/man2/recv.2:423
2842 msgid "The receive buffer pointer(s) point outside the process's address space."
2846 #: build/C/man2/recv.2:428
2848 "The receive was interrupted by delivery of a signal before any data were "
2849 "available; see B<signal>(7)."
2853 #: build/C/man2/recv.2:432 build/C/man2/send.2:323
2854 msgid "Invalid argument passed."
2858 #: build/C/man2/recv.2:436
2859 msgid "Could not allocate memory for B<recvmsg>()."
2863 #: build/C/man2/recv.2:436 build/C/man2/send.2:346
2869 #: build/C/man2/recv.2:443
2871 "The socket is associated with a connection-oriented protocol and has not "
2872 "been connected (see B<connect>(2) and B<accept>(2))."
2876 #: build/C/man2/recv.2:448
2877 msgid "The argument I<sockfd> does not refer to a socket."
2881 #: build/C/man2/recv.2:451
2882 msgid "4.4BSD (these function calls first appeared in 4.2BSD), POSIX.1-2001."
2886 #: build/C/man2/recv.2:458
2888 "POSIX.1-2001 describes only the B<MSG_OOB>, B<MSG_PEEK>, and B<MSG_WAITALL> "
2893 #: build/C/man2/recv.2:474
2895 "The prototypes given above follow glibc2. The Single UNIX Specification "
2896 "agrees, except that it has return values of type I<ssize_t> (while 4.x BSD "
2897 "and libc4 and libc5 all have I<int>). The I<flags> argument is I<int> in "
2898 "4.x BSD, but I<unsigned int> in libc4 and libc5. The I<len> argument is "
2899 "I<int> in 4.x BSD, but I<size_t> in libc4 and libc5. The I<addrlen> "
2900 "argument is I<int\\ *> in 4.x BSD, libc4 and libc5. The present "
2901 "I<socklen_t\\ *> was invented by POSIX. See also B<accept>(2)."
2904 #. glibc bug raised 12 Mar 2006
2905 #. http://sourceware.org/bugzilla/show_bug.cgi?id=2448
2906 #. The problem is an underlying kernel issue: the size of the
2907 #. __kernel_size_t type used to type this field varies
2908 #. across architectures, but socklen_t is always 32 bits.
2910 #: build/C/man2/recv.2:488 build/C/man2/send.2:409
2912 "According to POSIX.1-2001, the I<msg_controllen> field of the I<msghdr> "
2913 "structure should be typed as I<socklen_t>, but glibc currently types it as "
2918 #: build/C/man2/recv.2:493
2920 "See B<recvmmsg>(2) for information about a Linux-specific system call that "
2921 "can be used to receive multiple datagrams in a single call."
2925 #: build/C/man2/recv.2:498
2926 msgid "An example of the use of B<recvfrom>() is shown in B<getaddrinfo>(3)."
2930 #: build/C/man2/recv.2:509
2932 "B<fcntl>(2), B<getsockopt>(2), B<read>(2), B<recvmmsg>(2), B<select>(2), "
2933 "B<shutdown>(2), B<socket>(2), B<cmsg>(3), B<sockatmark>(3), B<socket>(7)"
2937 #: build/C/man2/recvmmsg.2:31
2943 #: build/C/man2/recvmmsg.2:31
2949 #: build/C/man2/recvmmsg.2:34
2950 msgid "recvmmsg - receive multiple messages on a socket"
2954 #: build/C/man2/recvmmsg.2:38 build/C/man2/sendmmsg.2:35
2957 "B<#define _GNU_SOURCE>\n"
2958 "B<#include E<lt>sys/socket.hE<gt>>\n"
2962 #: build/C/man2/recvmmsg.2:41
2965 "B<int recvmmsg(int >I<sockfd>B<, struct mmsghdr *>I<msgvec>B<, unsigned int "
2970 #: build/C/man2/recvmmsg.2:43
2972 msgid "B< unsigned int >I<flags>B<, struct timespec *>I<timeout>B<);>\n"
2976 #: build/C/man2/recvmmsg.2:55
2978 "The B<recvmmsg>() system call is an extension of B<recvmsg>(2) that allows "
2979 "the caller to receive multiple messages from a socket using a single system "
2980 "call. (This has performance benefits for some applications.) A further "
2981 "extension over B<recvmsg>(2) is support for a timeout on the receive "
2986 #: build/C/man2/recvmmsg.2:59
2988 "The I<sockfd> argument is the file descriptor of the socket to receive data "
2993 #: build/C/man2/recvmmsg.2:67 build/C/man2/sendmmsg.2:62
2995 "The I<msgvec> argument is a pointer to an array of I<mmsghdr> structures. "
2996 "The size of this array is specified in I<vlen>."
3000 #: build/C/man2/recvmmsg.2:73 build/C/man2/sendmmsg.2:68
3001 msgid "The I<mmsghdr> structure is defined in I<E<lt>sys/socket.hE<gt>> as:"
3005 #: build/C/man2/recvmmsg.2:80
3008 "struct mmsghdr {\n"
3009 " struct msghdr msg_hdr; /* Message header */\n"
3010 " unsigned int msg_len; /* Number of received bytes for header */\n"
3015 #: build/C/man2/recvmmsg.2:95
3017 "The I<msg_hdr> field is a I<msghdr> structure, as described in "
3018 "B<recvmsg>(2). The I<msg_len> field is the number of bytes returned for the "
3019 "message in the entry. This field has the same value as the return value of "
3020 "a single B<recvmsg>(2) on the header."
3024 #: build/C/man2/recvmmsg.2:102
3026 "The I<flags> argument contains flags ORed together. The flags are the same "
3027 "as documented for B<recvmsg>(2), with the following addition:"
3031 #: build/C/man2/recvmmsg.2:102
3033 msgid "B<MSG_WAITFORONE> (since Linux 2.6.34)"
3037 #: build/C/man2/recvmmsg.2:107
3038 msgid "Turns on B<MSG_DONTWAIT> after the first message has been received."
3042 #: build/C/man2/recvmmsg.2:123
3044 "The I<timeout> argument points to a I<struct timespec> (see "
3045 "B<clock_gettime>(2)) defining a timeout (seconds plus nanoseconds) for the "
3046 "receive operation. (This interval will be rounded up to the system clock "
3047 "granularity, and kernel scheduling delays mean that the blocking interval "
3048 "may overrun by a small amount.) If I<timeout> is I<NULL> then the operation "
3049 "blocks indefinitely."
3053 #: build/C/man2/recvmmsg.2:134
3055 "A blocking B<recvmmsg>() call blocks until I<vlen> messages have been "
3056 "received or until the timeout expires. A nonblocking call reads as many "
3057 "messages as are available (up to the limit specified by I<vlen>) and "
3058 "returns immediately."
3062 #: build/C/man2/recvmmsg.2:149
3064 "On return from B<recvmmsg>(), successive elements of I<msgvec> are updated "
3065 "to contain information about each received message: I<msg_len> contains the "
3066 "size of the received message; the subfields of I<msg_hdr> are updated as "
3067 "described in B<recvmsg>(2). The return value of the call indicates the "
3068 "number of elements of I<msgvec> that have been updated."
3072 #: build/C/man2/recvmmsg.2:157
3074 "On success, B<recvmmsg>() returns the number of messages received in "
3075 "I<msgvec>; on error, -1 is returned, and I<errno> is set to indicate the "
3080 #: build/C/man2/recvmmsg.2:161
3082 "Errors are as for B<recvmsg>(2). In addition, the following error can "
3087 #: build/C/man2/recvmmsg.2:165
3088 msgid "I<timeout> is invalid."
3092 #: build/C/man2/recvmmsg.2:170
3094 "The B<recvmmsg>() system call was added in Linux 2.6.33. Support in glibc "
3095 "was added in version 2.12."
3099 #: build/C/man2/recvmmsg.2:173
3100 msgid "B<recvmmsg>() is Linux-specific."
3104 #: build/C/man2/recvmmsg.2:181
3106 "The following program uses B<recvmmsg>() to receive multiple messages on a "
3107 "socket and stores them in multiple buffers. The call returns if all buffers "
3108 "are filled or if the timeout specified has expired."
3112 #: build/C/man2/recvmmsg.2:184
3114 "The following snippet periodically generates UDP datagrams containing a "
3119 #: build/C/man2/recvmmsg.2:189
3122 "$B< while true; do echo $RANDOM E<gt> /dev/udp/127.0.0.1/1234; >\n"
3123 "B<sleep 0.25; done>\n"
3127 #: build/C/man2/recvmmsg.2:194
3129 "These datagrams are read by the example application, which can give the "
3134 #: build/C/man2/recvmmsg.2:204
3138 "5 messages received\n"
3147 #: build/C/man2/recvmmsg.2:215
3150 "#define _GNU_SOURCE\n"
3151 "#include E<lt>netinet/ip.hE<gt>\n"
3152 "#include E<lt>stdio.hE<gt>\n"
3153 "#include E<lt>stdlib.hE<gt>\n"
3154 "#include E<lt>string.hE<gt>\n"
3155 "#include E<lt>sys/socket.hE<gt>\n"
3159 #: build/C/man2/recvmmsg.2:228
3166 "#define BUFSIZE 200\n"
3167 "#define TIMEOUT 1\n"
3168 " int sockfd, retval, i;\n"
3169 " struct sockaddr_in sa;\n"
3170 " struct mmsghdr msgs[VLEN];\n"
3171 " struct iovec iovecs[VLEN];\n"
3172 " char bufs[VLEN][BUFSIZE+1];\n"
3173 " struct timespec timeout;\n"
3177 #: build/C/man2/recvmmsg.2:234 build/C/man2/sendmmsg.2:201
3180 " sockfd = socket(AF_INET, SOCK_DGRAM, 0);\n"
3181 " if (sockfd == -1) {\n"
3182 " perror(\"socket()\");\n"
3183 " exit(EXIT_FAILURE);\n"
3188 #: build/C/man2/recvmmsg.2:242
3191 " sa.sin_family = AF_INET;\n"
3192 " sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);\n"
3193 " sa.sin_port = htons(1234);\n"
3194 " if (bind(sockfd, (struct sockaddr *) &sa, sizeof(sa)) == -1) {\n"
3195 " perror(\"bind()\");\n"
3196 " exit(EXIT_FAILURE);\n"
3201 #: build/C/man2/recvmmsg.2:250
3204 " memset(msgs, 0, sizeof(msgs));\n"
3205 " for (i = 0; i E<lt> VLEN; i++) {\n"
3206 " iovecs[i].iov_base = bufs[i];\n"
3207 " iovecs[i].iov_len = BUFSIZE;\n"
3208 " msgs[i].msg_hdr.msg_iov = &iovecs[i];\n"
3209 " msgs[i].msg_hdr.msg_iovlen = 1;\n"
3214 #: build/C/man2/recvmmsg.2:253
3217 " timeout.tv_sec = TIMEOUT;\n"
3218 " timeout.tv_nsec = 0;\n"
3222 #: build/C/man2/recvmmsg.2:259
3225 " retval = recvmmsg(sockfd, msgs, VLEN, 0, &timeout);\n"
3226 " if (retval == -1) {\n"
3227 " perror(\"recvmmsg()\");\n"
3228 " exit(EXIT_FAILURE);\n"
3233 #: build/C/man2/recvmmsg.2:267
3236 " printf(\"%d messages received\\en\", retval);\n"
3237 " for (i = 0; i E<lt> retval; i++) {\n"
3238 " bufs[i][msgs[i].msg_len] = 0;\n"
3239 " printf(\"%d %s\", i+1, bufs[i]);\n"
3241 " exit(EXIT_SUCCESS);\n"
3246 #: build/C/man2/recvmmsg.2:275
3248 "B<clock_gettime>(2), B<recvmsg>(2), B<sendmmsg>(2), B<sendmsg>(2), "
3249 "B<socket>(2), B<socket>(7)"
3253 #: build/C/man2/select.2:38
3259 #: build/C/man2/select.2:38
3265 #: build/C/man2/select.2:42 build/C/man2/select_tut.2:36
3267 "select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO - synchronous I/O "
3272 #: build/C/man2/select.2:45 build/C/man2/select_tut.2:39
3274 msgid "/* According to POSIX.1-2001 */\n"
3278 #: build/C/man2/select.2:47 build/C/man2/select.2:68 build/C/man2/select_tut.2:41 build/C/man2/select_tut.2:62
3280 msgid "B<#include E<lt>sys/select.hE<gt>>\n"
3284 #: build/C/man2/select.2:49 build/C/man2/select_tut.2:43
3286 msgid "/* According to earlier standards */\n"
3290 #: build/C/man2/select.2:51 build/C/man2/select_tut.2:45
3292 msgid "B<#include E<lt>sys/time.hE<gt>>\n"
3296 #: build/C/man2/select.2:55 build/C/man2/select_tut.2:49
3298 msgid "B<#include E<lt>unistd.hE<gt>>\n"
3302 #: build/C/man2/select.2:58
3305 "B<int select(int >I<nfds>B<, fd_set *>I<readfds>B<, fd_set "
3306 "*>I<writefds>B<,>\n"
3307 "B< fd_set *>I<exceptfds>B<, struct timeval *>I<timeout>B<);>\n"
3311 #: build/C/man2/select.2:60 build/C/man2/select_tut.2:54
3313 msgid "B<void FD_CLR(int >I<fd>B<, fd_set *>I<set>B<);>\n"
3317 #: build/C/man2/select.2:62 build/C/man2/select_tut.2:56
3319 msgid "B<int FD_ISSET(int >I<fd>B<, fd_set *>I<set>B<);>\n"
3323 #: build/C/man2/select.2:64 build/C/man2/select_tut.2:58
3325 msgid "B<void FD_SET(int >I<fd>B<, fd_set *>I<set>B<);>\n"
3329 #: build/C/man2/select.2:66 build/C/man2/select_tut.2:60
3331 msgid "B<void FD_ZERO(fd_set *>I<set>B<);>\n"
3335 #: build/C/man2/select.2:72
3338 "B<int pselect(int >I<nfds>B<, fd_set *>I<readfds>B<, fd_set "
3339 "*>I<writefds>B<,>\n"
3340 "B< fd_set *>I<exceptfds>B<, const struct timespec "
3341 "*>I<timeout>B<,>\n"
3342 "B< const sigset_t *>I<sigmask>B<);>\n"
3346 #: build/C/man2/select.2:77 build/C/man2/select_tut.2:71 build/C/man3/sockatmark.3:36
3347 msgid "Feature Test Macro Requirements for glibc (see B<feature_test_macros>(7)):"
3351 #: build/C/man2/select.2:81 build/C/man2/select_tut.2:75
3353 "B<pselect>(): _POSIX_C_SOURCE\\ E<gt>=\\ 200112L || _XOPEN_SOURCE\\ E<gt>=\\ "
3358 #: build/C/man2/select.2:92
3360 "B<select>() and B<pselect>() allow a program to monitor multiple file "
3361 "descriptors, waiting until one or more of the file descriptors become "
3362 "\"ready\" for some class of I/O operation (e.g., input possible). A file "
3363 "descriptor is considered ready if it is possible to perform the "
3364 "corresponding I/O operation (e.g., B<read>(2)) without blocking."
3368 #: build/C/man2/select.2:98
3370 "The operation of B<select>() and B<pselect>() is identical, other than "
3371 "these three differences:"
3375 #: build/C/man2/select.2:98
3381 #: build/C/man2/select.2:108
3383 "B<select>() uses a timeout that is a I<struct timeval> (with seconds and "
3384 "microseconds), while B<pselect>() uses a I<struct timespec> (with seconds "
3389 #: build/C/man2/select.2:108
3395 #: build/C/man2/select.2:116
3397 "B<select>() may update the I<timeout> argument to indicate how much time "
3398 "was left. B<pselect>() does not change this argument."
3402 #: build/C/man2/select.2:116
3408 #: build/C/man2/select.2:125
3410 "B<select>() has no I<sigmask> argument, and behaves as B<pselect>() called "
3411 "with NULL I<sigmask>."
3415 #: build/C/man2/select.2:143
3417 "Three independent sets of file descriptors are watched. Those listed in "
3418 "I<readfds> will be watched to see if characters become available for reading "
3419 "(more precisely, to see if a read will not block; in particular, a file "
3420 "descriptor is also ready on end-of-file), those in I<writefds> will be "
3421 "watched to see if a write will not block, and those in I<exceptfds> will be "
3422 "watched for exceptions. On exit, the sets are modified in place to indicate "
3423 "which file descriptors actually changed status. Each of the three file "
3424 "descriptor sets may be specified as NULL if no file descriptors are to be "
3425 "watched for the corresponding class of events."
3429 #: build/C/man2/select.2:156
3431 "Four macros are provided to manipulate the sets. B<FD_ZERO>() clears a "
3432 "set. B<FD_SET>() and B<FD_CLR>() respectively add and remove a given file "
3433 "descriptor from a set. B<FD_ISSET>() tests to see if a file descriptor is "
3434 "part of the set; this is useful after B<select>() returns."
3438 #: build/C/man2/select.2:159
3440 "I<nfds> is the highest-numbered file descriptor in any of the three sets, "
3445 #: build/C/man2/select.2:179
3447 "The I<timeout> argument specifies the interval that B<select>() should "
3448 "block waiting for a file descriptor to become ready. This interval will be "
3449 "rounded up to the system clock granularity, and kernel scheduling delays "
3450 "mean that the blocking interval may overrun by a small amount. If both "
3451 "fields of the I<timeval> structure are zero, then B<select>() returns "
3452 "immediately. (This is useful for polling.) If I<timeout> is NULL (no "
3453 "timeout), B<select>() can block indefinitely."
3457 #: build/C/man2/select.2:189
3459 "I<sigmask> is a pointer to a signal mask (see B<sigprocmask>(2)); if it is "
3460 "not NULL, then B<pselect>() first replaces the current signal mask by the "
3461 "one pointed to by I<sigmask>, then does the \"select\" function, and then "
3462 "restores the original signal mask."
3466 #: build/C/man2/select.2:195
3468 "Other than the difference in the precision of the I<timeout> argument, the "
3469 "following B<pselect>() call:"
3473 #: build/C/man2/select.2:199
3476 " ready = pselect(nfds, &readfds, &writefds, &exceptfds,\n"
3477 " timeout, &sigmask);\n"
3481 #: build/C/man2/select.2:204
3482 msgid "is equivalent to I<atomically> executing the following calls:"
3486 #: build/C/man2/select.2:207
3488 msgid " sigset_t origmask;\n"
3492 #: build/C/man2/select.2:211
3495 " pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);\n"
3496 " ready = select(nfds, &readfds, &writefds, &exceptfds, timeout);\n"
3497 " pthread_sigmask(SIG_SETMASK, &origmask, NULL);\n"
3501 #: build/C/man2/select.2:232
3503 "The reason that B<pselect>() is needed is that if one wants to wait for "
3504 "either a signal or for a file descriptor to become ready, then an atomic "
3505 "test is needed to prevent race conditions. (Suppose the signal handler sets "
3506 "a global flag and returns. Then a test of this global flag followed by a "
3507 "call of B<select>() could hang indefinitely if the signal arrived just "
3508 "after the test but just before the call. By contrast, B<pselect>() allows "
3509 "one to first block signals, handle the signals that have come in, then call "
3510 "B<pselect>() with the desired I<sigmask>, avoiding the race.)"
3514 #: build/C/man2/select.2:232
3520 #: build/C/man2/select.2:236
3522 "The time structures involved are defined in I<E<lt>sys/time.hE<gt>> and look "
3527 #: build/C/man2/select.2:243
3530 "struct timeval {\n"
3531 " long tv_sec; /* seconds */\n"
3532 " long tv_usec; /* microseconds */\n"
3537 #: build/C/man2/select.2:247
3542 #: build/C/man2/select.2:254
3545 "struct timespec {\n"
3546 " long tv_sec; /* seconds */\n"
3547 " long tv_nsec; /* nanoseconds */\n"
3552 #: build/C/man2/select.2:258
3553 msgid "(However, see below on the POSIX.1-2001 versions.)"
3557 #: build/C/man2/select.2:266
3559 "Some code calls B<select>() with all three sets empty, I<nfds> zero, and a "
3560 "non-NULL I<timeout> as a fairly portable way to sleep with subsecond "
3564 #. .PP - it is rumored that:
3565 #. On BSD, when a timeout occurs, the file descriptor bits are not changed.
3566 #. - it is certainly true that:
3567 #. Linux follows SUSv2 and sets the bit masks to zero upon a timeout.
3569 #: build/C/man2/select.2:289
3571 "On Linux, B<select>() modifies I<timeout> to reflect the amount of time not "
3572 "slept; most other implementations do not do this. (POSIX.1-2001 permits "
3573 "either behavior.) This causes problems both when Linux code which reads "
3574 "I<timeout> is ported to other operating systems, and when code is ported to "
3575 "Linux that reuses a I<struct timeval> for multiple B<select>()s in a loop "
3576 "without reinitializing it. Consider I<timeout> to be undefined after "
3577 "B<select>() returns."
3581 #: build/C/man2/select.2:306
3583 "On success, B<select>() and B<pselect>() return the number of file "
3584 "descriptors contained in the three returned descriptor sets (that is, the "
3585 "total number of bits that are set in I<readfds>, I<writefds>, I<exceptfds>) "
3586 "which may be zero if the timeout expires before anything interesting "
3587 "happens. On error, -1 is returned, and I<errno> is set appropriately; the "
3588 "sets and I<timeout> become undefined, so do not rely on their contents after "
3593 #: build/C/man2/select.2:312
3595 "An invalid file descriptor was given in one of the sets. (Perhaps a file "
3596 "descriptor that was already closed, or one on which an error has occurred.)"
3600 #: build/C/man2/select.2:316
3601 msgid "A signal was caught; see B<signal>(7)."
3605 #: build/C/man2/select.2:322
3606 msgid "I<nfds> is negative or the value contained within I<timeout> is invalid."
3610 #: build/C/man2/select.2:325
3611 msgid "unable to allocate memory for internal tables."
3615 #: build/C/man2/select.2:331
3617 "B<pselect>() was added to Linux in kernel 2.6.16. Prior to this, "
3618 "B<pselect>() was emulated in glibc (but see BUGS)."
3622 #: build/C/man2/select.2:342
3624 "B<select>() conforms to POSIX.1-2001 and 4.4BSD (B<select>() first "
3625 "appeared in 4.2BSD). Generally portable to/from non-BSD systems supporting "
3626 "clones of the BSD socket layer (including System V variants). However, note "
3627 "that the System V variant typically sets the timeout variable before exit, "
3628 "but the BSD variant does not."
3632 #: build/C/man2/select.2:346
3633 msgid "B<pselect>() is defined in POSIX.1g, and in POSIX.1-2001."
3637 #: build/C/man2/select.2:363
3639 "An I<fd_set> is a fixed size buffer. Executing B<FD_CLR>() or B<FD_SET>() "
3640 "with a value of I<fd> that is negative or is equal to or larger than "
3641 "B<FD_SETSIZE> will result in undefined behavior. Moreover, POSIX requires "
3642 "I<fd> to be a valid file descriptor."
3646 #: build/C/man2/select.2:372
3648 "Concerning the types involved, the classical situation is that the two "
3649 "fields of a I<timeval> structure are typed as I<long> (as shown above), and "
3650 "the structure is defined in I<E<lt>sys/time.hE<gt>>. The POSIX.1-2001 "
3655 #: build/C/man2/select.2:379
3658 "struct timeval {\n"
3659 " time_t tv_sec; /* seconds */\n"
3660 " suseconds_t tv_usec; /* microseconds */\n"
3665 #: build/C/man2/select.2:390
3667 "where the structure is defined in I<E<lt>sys/select.hE<gt>> and the data "
3668 "types I<time_t> and I<suseconds_t> are defined in I<E<lt>sys/types.hE<gt>>."
3672 #: build/C/man2/select.2:402
3674 "Concerning prototypes, the classical situation is that one should include "
3675 "I<E<lt>time.hE<gt>> for B<select>(). The POSIX.1-2001 situation is that one "
3676 "should include I<E<lt>sys/select.hE<gt>> for B<select>() and B<pselect>()."
3680 #: build/C/man2/select.2:414
3682 "Libc4 and libc5 do not have a I<E<lt>sys/select.hE<gt>> header; under glibc "
3683 "2.0 and later this header exists. Under glibc 2.0 it unconditionally gives "
3684 "the wrong prototype for B<pselect>(). Under glibc 2.1 to 2.2.1 it gives "
3685 "B<pselect>() when B<_GNU_SOURCE> is defined. Since glibc 2.2.2 the "
3686 "requirements are as shown in the SYNOPSIS."
3690 #: build/C/man2/select.2:414
3692 msgid "Multithreaded applications"
3696 #: build/C/man2/select.2:430
3698 "If a file descriptor being monitored by B<select>() is closed in another "
3699 "thread, the result is unspecified. On some UNIX systems, B<select>() "
3700 "unblocks and returns, with an indication that the file descriptor is ready "
3701 "(a subsequent I/O operation will likely fail with an error, unless another "
3702 "the file descriptor reopened between the time B<select>() returned and the "
3703 "I/O operations was performed). On Linux (and some other systems), closing "
3704 "the file descriptor in another thread has no effect on B<select>(). In "
3705 "summary, any application that relies on a particular behavior in this "
3706 "scenario must be considered buggy."
3710 #: build/C/man2/select.2:430
3716 #: build/C/man2/select.2:438
3718 "The B<pselect>() interface described in this page is implemented by glibc. "
3719 "The underlying Linux system call is named B<pselect6>(). This system call "
3720 "has somewhat different behavior from the glibc wrapper function."
3724 #: build/C/man2/select.2:453
3726 "The Linux B<pselect6>() system call modifies its I<timeout> argument. "
3727 "However, the glibc wrapper function hides this behavior by using a local "
3728 "variable for the timeout argument that is passed to the system call. Thus, "
3729 "the glibc B<pselect>() function does not modify its I<timeout> argument; "
3730 "this is the behavior required by POSIX.1-2001."
3734 #: build/C/man2/select.2:459
3736 "The final argument of the B<pselect6>() system call is not a I<sigset_t\\ "
3737 "*> pointer, but is instead a structure of the form:"
3741 #: build/C/man2/select.2:467
3745 " const sigset_t *ss; /* Pointer to signal set */\n"
3746 " size_t ss_len; /* Size (in bytes) of object pointed\n"
3752 #: build/C/man2/select.2:474
3754 "This allows the system call to obtain both a pointer to the signal set and "
3755 "its size, while allowing for the fact that most architectures support a "
3756 "maximum of 6 arguments to a system call."
3760 #: build/C/man2/select.2:480
3762 "Glibc 2.0 provided a version of B<pselect>() that did not take a I<sigmask> "
3767 #: build/C/man2/select.2:493
3769 "Starting with version 2.1, glibc provided an emulation of B<pselect>() that "
3770 "was implemented using B<sigprocmask>(2) and B<select>(). This "
3771 "implementation remained vulnerable to the very race condition that "
3772 "B<pselect>() was designed to prevent. Modern versions of glibc use the "
3773 "(race-free) B<pselect>() system call on kernels where it is provided."
3777 #: build/C/man2/select.2:506
3779 "On systems that lack B<pselect>(), reliable (and more portable) signal "
3780 "trapping can be achieved using the self-pipe trick. In this technique, a "
3781 "signal handler writes a byte to a pipe whose other end is monitored by "
3782 "B<select>() in the main program. (To avoid possibly blocking when writing "
3783 "to a pipe that may be full or reading from a pipe that may be empty, "
3784 "nonblocking I/O is used when reading from and writing to the pipe.)"
3787 #. Stevens discusses a case where accept can block after select
3788 #. returns successfully because of an intervening RST from the client.
3789 #. Maybe the kernel should have returned EIO in such a situation?
3791 #: build/C/man2/select.2:522
3793 "Under Linux, B<select>() may report a socket file descriptor as \"ready for "
3794 "reading\", while nevertheless a subsequent read blocks. This could for "
3795 "example happen when data has arrived but upon examination has wrong checksum "
3796 "and is discarded. There may be other circumstances in which a file "
3797 "descriptor is spuriously reported as ready. Thus it may be safer to use "
3798 "B<O_NONBLOCK> on sockets that should not block."
3802 #: build/C/man2/select.2:537
3804 "On Linux, B<select>() also modifies I<timeout> if the call is interrupted "
3805 "by a signal handler (i.e., the B<EINTR> error return). This is not "
3806 "permitted by POSIX.1-2001. The Linux B<pselect>() system call has the same "
3807 "behavior, but the glibc wrapper hides this behavior by internally copying "
3808 "the I<timeout> to a local variable and passing that variable to the system "
3813 #: build/C/man2/select.2:544
3816 "#include E<lt>stdio.hE<gt>\n"
3817 "#include E<lt>stdlib.hE<gt>\n"
3818 "#include E<lt>sys/time.hE<gt>\n"
3819 "#include E<lt>sys/types.hE<gt>\n"
3820 "#include E<lt>unistd.hE<gt>\n"
3824 #: build/C/man2/select.2:551
3831 " struct timeval tv;\n"
3836 #: build/C/man2/select.2:555
3839 " /* Watch stdin (fd 0) to see when it has input. */\n"
3840 " FD_ZERO(&rfds);\n"
3841 " FD_SET(0, &rfds);\n"
3845 #: build/C/man2/select.2:559
3848 " /* Wait up to five seconds. */\n"
3850 " tv.tv_usec = 0;\n"
3854 #: build/C/man2/select.2:562
3857 " retval = select(1, &rfds, NULL, NULL, &tv);\n"
3858 " /* Don't rely on the value of tv now! */\n"
3862 #: build/C/man2/select.2:570
3865 " if (retval == -1)\n"
3866 " perror(\"select()\");\n"
3867 " else if (retval)\n"
3868 " printf(\"Data is available now.\\en\");\n"
3869 " /* FD_ISSET(0, &rfds) will be true. */\n"
3871 " printf(\"No data within five seconds.\\en\");\n"
3875 #: build/C/man2/select.2:585
3877 "B<accept>(2), B<connect>(2), B<poll>(2), B<read>(2), B<recv>(2), B<send>(2), "
3878 "B<sigprocmask>(2), B<write>(2), B<epoll>(7), B<time>(7)"
3882 #: build/C/man2/select.2:588
3883 msgid "For a tutorial with discussion and examples, see B<select_tut>(2)."
3887 #: build/C/man2/select_tut.2:32
3893 #: build/C/man2/select_tut.2:32
3899 #: build/C/man2/select_tut.2:52
3902 "B<int select(int >I<nfds>B<, fd_set *>I<readfds>B<, fd_set "
3903 "*>I<writefds>B<,>\n"
3904 "B< fd_set *>I<exceptfds>B<, struct timeval *>I<utimeout>B<);>\n"
3908 #: build/C/man2/select_tut.2:66
3911 "B<int pselect(int >I<nfds>B<, fd_set *>I<readfds>B<, fd_set "
3912 "*>I<writefds>B<,>\n"
3913 "B< fd_set *>I<exceptfds>B<, const struct timespec "
3914 "*>I<ntimeout>B<,>\n"
3915 "B< const sigset_t *>I<sigmask>B<);>\n"
3919 #: build/C/man2/select_tut.2:83
3921 "B<select>() (or B<pselect>()) is used to efficiently monitor multiple file "
3922 "descriptors, to see if any of them is, or becomes, \"ready\"; that is, to "
3923 "see whether I/O becomes possible, or an \"exceptional condition\" has "
3924 "occurred on any of the descriptors."
3928 #: build/C/man2/select_tut.2:108
3930 "Its principal arguments are three \"sets\" of file descriptors: I<readfds>, "
3931 "I<writefds>, and I<exceptfds>. Each set is declared as type I<fd_set>, and "
3932 "its contents can be manipulated with the macros B<FD_CLR>(), B<FD_ISSET>(), "
3933 "B<FD_SET>(), and B<FD_ZERO>(). A newly declared set should first be cleared "
3934 "using B<FD_ZERO>(). B<select>() modifies the contents of the sets "
3935 "according to the rules described below; after calling B<select>() you can "
3936 "test if a file descriptor is still present in a set with the B<FD_ISSET>() "
3937 "macro. B<FD_ISSET>() returns nonzero if a specified file descriptor is "
3938 "present in a set and zero if it is not. B<FD_CLR>() removes a file "
3939 "descriptor from a set."
3943 #: build/C/man2/select_tut.2:108
3949 #: build/C/man2/select_tut.2:109
3955 #: build/C/man2/select_tut.2:118
3957 "This set is watched to see if data is available for reading from any of its "
3958 "file descriptors. After B<select>() has returned, I<readfds> will be "
3959 "cleared of all file descriptors except for those that are immediately "
3960 "available for reading."
3964 #: build/C/man2/select_tut.2:118
3970 #: build/C/man2/select_tut.2:127
3972 "This set is watched to see if there is space to write data to any of its "
3973 "file descriptors. After B<select>() has returned, I<writefds> will be "
3974 "cleared of all file descriptors except for those that are immediately "
3975 "available for writing."
3979 #: build/C/man2/select_tut.2:127
3981 msgid "I<exceptfds>"
3985 #: build/C/man2/select_tut.2:149
3987 "This set is watched for \"exceptional conditions\". In practice, only one "
3988 "such exceptional condition is common: the availability of I<out-of-band> "
3989 "(OOB) data for reading from a TCP socket. See B<recv>(2), B<send>(2), and "
3990 "B<tcp>(7) for more details about OOB data. (One other less common case "
3991 "where B<select>(2) indicates an exceptional condition occurs with "
3992 "pseudoterminals in packet mode; see B<tty_ioctl>(4).) After B<select>() "
3993 "has returned, I<exceptfds> will be cleared of all file descriptors except "
3994 "for those for which an exceptional condition has occurred."
3998 #: build/C/man2/select_tut.2:149
4004 #: build/C/man2/select_tut.2:156
4006 "This is an integer one more than the maximum of any file descriptor in any "
4007 "of the sets. In other words, while adding file descriptors to each of the "
4008 "sets, you must calculate the maximum integer value of all of them, then "
4009 "increment this value by one, and then pass this as I<nfds>."
4013 #: build/C/man2/select_tut.2:156
4019 #: build/C/man2/select_tut.2:169
4021 "This is the longest time B<select>() may wait before returning, even if "
4022 "nothing interesting happened. If this value is passed as NULL, then "
4023 "B<select>() blocks indefinitely waiting for a file descriptor to become "
4024 "ready. I<utimeout> can be set to zero seconds, which causes B<select>() to "
4025 "return immediately, with information about the readiness of file descriptors "
4026 "at the time of the call. The structure I<struct timeval> is defined as:"
4030 #: build/C/man2/select_tut.2:176
4033 "struct timeval {\n"
4034 " time_t tv_sec; /* seconds */\n"
4035 " long tv_usec; /* microseconds */\n"
4040 #: build/C/man2/select_tut.2:178
4046 #: build/C/man2/select_tut.2:187
4048 "This argument for B<pselect>() has the same meaning as I<utimeout>, but "
4049 "I<struct timespec> has nanosecond precision as follows:"
4053 #: build/C/man2/select_tut.2:194
4056 "struct timespec {\n"
4057 " long tv_sec; /* seconds */\n"
4058 " long tv_nsec; /* nanoseconds */\n"
4063 #: build/C/man2/select_tut.2:196
4069 #: build/C/man2/select_tut.2:213
4071 "This argument holds a set of signals that the kernel should unblock (i.e., "
4072 "remove from the signal mask of the calling thread), while the caller is "
4073 "blocked inside the B<pselect>() call (see B<sigaddset>(3) and "
4074 "B<sigprocmask>(2)). It may be NULL, in which case the call does not modify "
4075 "the signal mask on entry and exit to the function. In this case, "
4076 "B<pselect>() will then behave just like B<select>()."
4080 #: build/C/man2/select_tut.2:213
4082 msgid "Combining signal and data events"
4086 #: build/C/man2/select_tut.2:257
4088 "B<pselect>() is useful if you are waiting for a signal as well as for file "
4089 "descriptor(s) to become ready for I/O. Programs that receive signals "
4090 "normally use the signal handler only to raise a global flag. The global "
4091 "flag will indicate that the event must be processed in the main loop of the "
4092 "program. A signal will cause the B<select>() (or B<pselect>()) call to "
4093 "return with I<errno> set to B<EINTR>. This behavior is essential so that "
4094 "signals can be processed in the main loop of the program, otherwise "
4095 "B<select>() would block indefinitely. Now, somewhere in the main loop will "
4096 "be a conditional to check the global flag. So we must ask: what if a signal "
4097 "arrives after the conditional, but before the B<select>() call? The answer "
4098 "is that B<select>() would block indefinitely, even though an event is "
4099 "actually pending. This race condition is solved by the B<pselect>() call. "
4100 "This call can be used to set the signal mask to a set of signals that are "
4101 "only to be received within the B<pselect>() call. For instance, let us say "
4102 "that the event in question was the exit of a child process. Before the "
4103 "start of the main loop, we would block B<SIGCHLD> using B<sigprocmask>(2). "
4104 "Our B<pselect>() call would enable B<SIGCHLD> by using an empty signal "
4105 "mask. Our program would look like:"
4109 #: build/C/man2/select_tut.2:260
4111 msgid "static volatile sig_atomic_t got_SIGCHLD = 0;\n"
4115 #: build/C/man2/select_tut.2:266
4119 "child_sig_handler(int sig)\n"
4121 " got_SIGCHLD = 1;\n"
4126 #: build/C/man2/select_tut.2:274
4130 "main(int argc, char *argv[])\n"
4132 " sigset_t sigmask, empty_mask;\n"
4133 " struct sigaction sa;\n"
4134 " fd_set readfds, writefds, exceptfds;\n"
4139 #: build/C/man2/select_tut.2:281
4142 " sigemptyset(&sigmask);\n"
4143 " sigaddset(&sigmask, SIGCHLD);\n"
4144 " if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) {\n"
4145 " perror(\"sigprocmask\");\n"
4146 " exit(EXIT_FAILURE);\n"
4151 #: build/C/man2/select_tut.2:289
4154 " sa.sa_flags = 0;\n"
4155 " sa.sa_handler = child_sig_handler;\n"
4156 " sigemptyset(&sa.sa_mask);\n"
4157 " if (sigaction(SIGCHLD, &sa, NULL) == -1) {\n"
4158 " perror(\"sigaction\");\n"
4159 " exit(EXIT_FAILURE);\n"
4164 #: build/C/man2/select_tut.2:291
4166 msgid " sigemptyset(&empty_mask);\n"
4170 #: build/C/man2/select_tut.2:295
4173 " for (;;) { /* main loop */\n"
4174 " /* Initialize readfds, writefds, and exceptfds\n"
4175 " before the pselect() call. (Code omitted.) */\n"
4179 #: build/C/man2/select_tut.2:301
4182 " r = pselect(nfds, &readfds, &writefds, &exceptfds,\n"
4183 " NULL, &empty_mask);\n"
4184 " if (r == -1 && errno != EINTR) {\n"
4185 " /* Handle error */\n"
4190 #: build/C/man2/select_tut.2:304
4193 " if (got_SIGCHLD) {\n"
4194 " got_SIGCHLD = 0;\n"
4198 #: build/C/man2/select_tut.2:308
4201 " /* Handle signalled event here; e.g., wait() for all\n"
4202 " terminated children. (Code omitted.) */\n"
4207 #: build/C/man2/select_tut.2:312
4210 " /* main body of program */\n"
4216 #: build/C/man2/select_tut.2:313
4222 #: build/C/man2/select_tut.2:334
4224 "So what is the point of B<select>()? Can't I just read and write to my "
4225 "descriptors whenever I want? The point of B<select>() is that it watches "
4226 "multiple descriptors at the same time and properly puts the process to sleep "
4227 "if there is no activity. UNIX programmers often find themselves in a "
4228 "position where they have to handle I/O from more than one file descriptor "
4229 "where the data flow may be intermittent. If you were to merely create a "
4230 "sequence of B<read>(2) and B<write>(2) calls, you would find that one of "
4231 "your calls may block waiting for data from/to a file descriptor, while "
4232 "another file descriptor is unused though ready for I/O. B<select>() "
4233 "efficiently copes with this situation."
4237 #: build/C/man2/select_tut.2:334
4243 #: build/C/man2/select_tut.2:347
4245 "Many people who try to use B<select>() come across behavior that is "
4246 "difficult to understand and produces nonportable or borderline results. For "
4247 "instance, the above program is carefully written not to block at any point, "
4248 "even though it does not set its file descriptors to nonblocking mode. It is "
4249 "easy to introduce subtle errors that will remove the advantage of using "
4250 "B<select>(), so here is a list of essentials to watch for when using "
4255 #: build/C/man2/select_tut.2:356
4257 "You should always try to use B<select>() without a timeout. Your program "
4258 "should have nothing to do if there is no data available. Code that depends "
4259 "on timeouts is not usually portable and is difficult to debug."
4263 #: build/C/man2/select_tut.2:360
4265 "The value I<nfds> must be properly calculated for efficiency as explained "
4270 #: build/C/man2/select_tut.2:367
4272 "No file descriptor must be added to any set if you do not intend to check "
4273 "its result after the B<select>() call, and respond appropriately. See next "
4278 #: build/C/man2/select_tut.2:373
4280 "After B<select>() returns, all file descriptors in all sets should be "
4281 "checked to see if they are ready."
4285 #: build/C/man2/select_tut.2:373
4291 #: build/C/man2/select_tut.2:388
4293 "The functions B<read>(2), B<recv>(2), B<write>(2), and B<send>(2) do I<not> "
4294 "necessarily read/write the full amount of data that you have requested. If "
4295 "they do read/write the full amount, it's because you have a low traffic load "
4296 "and a fast stream. This is not always going to be the case. You should "
4297 "cope with the case of your functions managing to send or receive only a "
4302 #: build/C/man2/select_tut.2:388
4308 #: build/C/man2/select_tut.2:396
4310 "Never read/write only in single bytes at a time unless you are really sure "
4311 "that you have a small amount of data to process. It is extremely "
4312 "inefficient not to read/write as much data as you can buffer each time. The "
4313 "buffers in the example below are 1024 bytes although they could easily be "
4318 #: build/C/man2/select_tut.2:396
4323 #. Nonetheless, you should still cope with these errors for completeness.
4325 #: build/C/man2/select_tut.2:418
4327 "The functions B<read>(2), B<recv>(2), B<write>(2), and B<send>(2) as well "
4328 "as the B<select>() call can return -1 with I<errno> set to B<EINTR>, or "
4329 "with I<errno> set to B<EAGAIN> (B<EWOULDBLOCK>). These results must be "
4330 "properly managed (not done properly above). If your program is not going to "
4331 "receive any signals, then it is unlikely you will get B<EINTR>. If your "
4332 "program does not set nonblocking I/O, you will not get B<EAGAIN>."
4336 #: build/C/man2/select_tut.2:418
4342 #: build/C/man2/select_tut.2:427
4344 "Never call B<read>(2), B<recv>(2), B<write>(2), or B<send>(2) with a buffer "
4349 #: build/C/man2/select_tut.2:427
4355 #: build/C/man2/select_tut.2:443
4357 "If the functions B<read>(2), B<recv>(2), B<write>(2), and B<send>(2) fail "
4358 "with errors other than those listed in B<7.>, or one of the input functions "
4359 "returns 0, indicating end of file, then you should I<not> pass that "
4360 "descriptor to B<select>() again. In the example below, I close the "
4361 "descriptor immediately, and then set it to -1 to prevent it being included "
4366 #: build/C/man2/select_tut.2:443
4372 #: build/C/man2/select_tut.2:450
4374 "The timeout value must be initialized with each new call to B<select>(), "
4375 "since some operating systems modify the structure. B<pselect>() however "
4376 "does not modify its timeout structure."
4380 #: build/C/man2/select_tut.2:450
4385 #. "I have heard" does not fill me with confidence, and doesn't
4386 #. belong in a man page, so I've commented this point out.
4389 #. I have heard that the Windows socket layer does not cope with OOB data
4391 #. It also does not cope with
4393 #. calls when no file descriptors are set at all.
4394 #. Having no file descriptors set is a useful
4395 #. way to sleep the process with subsecond precision by using the timeout.
4396 #. (See further on.)
4398 #: build/C/man2/select_tut.2:469
4400 "Since B<select>() modifies its file descriptor sets, if the call is being "
4401 "used in a loop, then the sets must be reinitialized before each call."
4405 #: build/C/man2/select_tut.2:469
4407 msgid "Usleep emulation"
4411 #: build/C/man2/select_tut.2:476
4413 "On systems that do not have a B<usleep>(3) function, you can call "
4414 "B<select>() with a finite timeout and no file descriptors as follows:"
4418 #: build/C/man2/select_tut.2:482
4421 " struct timeval tv;\n"
4423 " tv.tv_usec = 200000; /* 0.2 seconds */\n"
4424 " select(0, NULL, NULL, NULL, &tv);\n"
4428 #: build/C/man2/select_tut.2:485
4429 msgid "This is guaranteed to work only on UNIX systems, however."
4433 #: build/C/man2/select_tut.2:490
4435 "On success, B<select>() returns the total number of file descriptors still "
4436 "present in the file descriptor sets."
4440 #: build/C/man2/select_tut.2:496
4442 "If B<select>() timed out, then the return value will be zero. The file "
4443 "descriptors set should be all empty (but may not be on some systems)."
4447 #: build/C/man2/select_tut.2:503
4449 "A return value of -1 indicates an error, with I<errno> being set "
4450 "appropriately. In the case of an error, the contents of the returned sets "
4451 "and the I<struct timeout> contents are undefined and should not be used. "
4452 "B<pselect>() however never modifies I<ntimeout>."
4456 #: build/C/man2/select_tut.2:512
4458 "Generally speaking, all operating systems that support sockets also support "
4459 "B<select>(). B<select>() can be used to solve many problems in a portable "
4460 "and efficient way that naive programmers try to solve in a more complicated "
4461 "manner using threads, forking, IPCs, signals, memory sharing, and so on."
4465 #: build/C/man2/select_tut.2:521
4467 "The B<poll>(2) system call has the same functionality as B<select>(), and "
4468 "is somewhat more efficient when monitoring sparse file descriptor sets. It "
4469 "is nowadays widely available, but historically was less portable than "
4474 #: build/C/man2/select_tut.2:529
4476 "The Linux-specific B<epoll>(7) API provides an interface that is more "
4477 "efficient than B<select>(2) and B<poll>(2) when monitoring large numbers "
4478 "of file descriptors."
4482 #: build/C/man2/select_tut.2:534
4484 "Here is an example that better demonstrates the true utility of "
4485 "B<select>(). The listing below is a TCP forwarding program that forwards "
4486 "from one TCP port to another."
4490 #: build/C/man2/select_tut.2:547
4493 "#include E<lt>stdlib.hE<gt>\n"
4494 "#include E<lt>stdio.hE<gt>\n"
4495 "#include E<lt>unistd.hE<gt>\n"
4496 "#include E<lt>sys/time.hE<gt>\n"
4497 "#include E<lt>sys/types.hE<gt>\n"
4498 "#include E<lt>string.hE<gt>\n"
4499 "#include E<lt>signal.hE<gt>\n"
4500 "#include E<lt>sys/socket.hE<gt>\n"
4501 "#include E<lt>netinet/in.hE<gt>\n"
4502 "#include E<lt>arpa/inet.hE<gt>\n"
4503 "#include E<lt>errno.hE<gt>\n"
4507 #: build/C/man2/select_tut.2:549
4509 msgid "static int forward_port;\n"
4513 #: build/C/man2/select_tut.2:552
4517 "#define max(x,y) ((x) E<gt> (y) ? (x) : (y))\n"
4521 #: build/C/man2/select_tut.2:559
4525 "listen_socket(int listen_port)\n"
4527 " struct sockaddr_in a;\n"
4533 #: build/C/man2/select_tut.2:583
4536 " if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) {\n"
4537 " perror(\"socket\");\n"
4541 " if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,\n"
4542 " &yes, sizeof(yes)) == -1) {\n"
4543 " perror(\"setsockopt\");\n"
4547 " memset(&a, 0, sizeof(a));\n"
4548 " a.sin_port = htons(listen_port);\n"
4549 " a.sin_family = AF_INET;\n"
4550 " if (bind(s, (struct sockaddr *) &a, sizeof(a)) == -1) {\n"
4551 " perror(\"bind\");\n"
4555 " printf(\"accepting connections on port %d\\en\", listen_port);\n"
4562 #: build/C/man2/select_tut.2:589
4566 "connect_socket(int connect_port, char *address)\n"
4568 " struct sockaddr_in a;\n"
4573 #: build/C/man2/select_tut.2:595
4576 " if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) {\n"
4577 " perror(\"socket\");\n"
4584 #: build/C/man2/select_tut.2:599
4587 " memset(&a, 0, sizeof(a));\n"
4588 " a.sin_port = htons(connect_port);\n"
4589 " a.sin_family = AF_INET;\n"
4593 #: build/C/man2/select_tut.2:605
4596 " if (!inet_aton(address, (struct in_addr *) &a.sin_addr.s_addr)) {\n"
4597 " perror(\"bad IP address format\");\n"
4604 #: build/C/man2/select_tut.2:614
4607 " if (connect(s, (struct sockaddr *) &a, sizeof(a)) == -1) {\n"
4608 " perror(\"connect()\");\n"
4609 " shutdown(s, SHUT_RDWR);\n"
4618 #: build/C/man2/select_tut.2:622
4621 "#define SHUT_FD1 do { \\e\n"
4622 " if (fd1 E<gt>= 0) { \\e\n"
4623 " shutdown(fd1, SHUT_RDWR); \\e\n"
4624 " close(fd1); \\e\n"
4631 #: build/C/man2/select_tut.2:630
4634 "#define SHUT_FD2 do { \\e\n"
4635 " if (fd2 E<gt>= 0) { \\e\n"
4636 " shutdown(fd2, SHUT_RDWR); \\e\n"
4637 " close(fd2); \\e\n"
4644 #: build/C/man2/select_tut.2:632
4646 msgid "#define BUF_SIZE 1024\n"
4650 #: build/C/man2/select_tut.2:641
4654 "main(int argc, char *argv[])\n"
4657 " int fd1 = -1, fd2 = -1;\n"
4658 " char buf1[BUF_SIZE], buf2[BUF_SIZE];\n"
4659 " int buf1_avail, buf1_written;\n"
4660 " int buf2_avail, buf2_written;\n"
4664 #: build/C/man2/select_tut.2:647
4667 " if (argc != 4) {\n"
4668 " fprintf(stderr, \"Usage\\en\\etfwd E<lt>listen-portE<gt> \"\n"
4669 " \"E<lt>forward-to-portE<gt> "
4670 "E<lt>forward-to-ip-addressE<gt>\\en\");\n"
4671 " exit(EXIT_FAILURE);\n"
4676 #: build/C/man2/select_tut.2:649
4678 msgid " signal(SIGPIPE, SIG_IGN);\n"
4682 #: build/C/man2/select_tut.2:651
4684 msgid " forward_port = atoi(argv[2]);\n"
4688 #: build/C/man2/select_tut.2:655
4691 " h = listen_socket(atoi(argv[1]));\n"
4693 " exit(EXIT_FAILURE);\n"
4697 #: build/C/man2/select_tut.2:659
4701 " int r, nfds = 0;\n"
4702 " fd_set rd, wr, er;\n"
4706 #: build/C/man2/select_tut.2:689
4712 " FD_SET(h, &rd);\n"
4713 " nfds = max(nfds, h);\n"
4714 " if (fd1 E<gt> 0 && buf1_avail E<lt> BUF_SIZE) {\n"
4715 " FD_SET(fd1, &rd);\n"
4716 " nfds = max(nfds, fd1);\n"
4718 " if (fd2 E<gt> 0 && buf2_avail E<lt> BUF_SIZE) {\n"
4719 " FD_SET(fd2, &rd);\n"
4720 " nfds = max(nfds, fd2);\n"
4722 " if (fd1 E<gt> 0 && buf2_avail - buf2_written E<gt> 0) {\n"
4723 " FD_SET(fd1, &wr);\n"
4724 " nfds = max(nfds, fd1);\n"
4726 " if (fd2 E<gt> 0 && buf1_avail - buf1_written E<gt> 0) {\n"
4727 " FD_SET(fd2, &wr);\n"
4728 " nfds = max(nfds, fd2);\n"
4730 " if (fd1 E<gt> 0) {\n"
4731 " FD_SET(fd1, &er);\n"
4732 " nfds = max(nfds, fd1);\n"
4734 " if (fd2 E<gt> 0) {\n"
4735 " FD_SET(fd2, &er);\n"
4736 " nfds = max(nfds, fd2);\n"
4741 #: build/C/man2/select_tut.2:691
4743 msgid " r = select(nfds + 1, &rd, &wr, &er, NULL);\n"
4747 #: build/C/man2/select_tut.2:694
4750 " if (r == -1 && errno == EINTR)\n"
4755 #: build/C/man2/select_tut.2:699
4759 " perror(\"select()\");\n"
4760 " exit(EXIT_FAILURE);\n"
4765 #: build/C/man2/select_tut.2:703
4768 " if (FD_ISSET(h, &rd)) {\n"
4769 " unsigned int l;\n"
4770 " struct sockaddr_in client_address;\n"
4774 #: build/C/man2/select_tut.2:722
4777 " memset(&client_address, 0, l = sizeof(client_address));\n"
4778 " r = accept(h, (struct sockaddr *) &client_address, &l);\n"
4780 " perror(\"accept()\");\n"
4784 " buf1_avail = buf1_written = 0;\n"
4785 " buf2_avail = buf2_written = 0;\n"
4787 " fd2 = connect_socket(forward_port, argv[3]);\n"
4791 " printf(\"connect from %s\\en\",\n"
4792 " inet_ntoa(client_address.sin_addr));\n"
4798 #: build/C/man2/select_tut.2:724
4800 msgid " /* NB: read oob data before normal reads */\n"
4804 #: build/C/man2/select_tut.2:728
4807 " if (fd1 E<gt> 0)\n"
4808 " if (FD_ISSET(fd1, &er)) {\n"
4813 #: build/C/man2/select_tut.2:738
4816 " r = recv(fd1, &c, 1, MSG_OOB);\n"
4820 " send(fd2, &c, 1, MSG_OOB);\n"
4822 " if (fd2 E<gt> 0)\n"
4823 " if (FD_ISSET(fd2, &er)) {\n"
4828 #: build/C/man2/select_tut.2:781
4831 " r = recv(fd2, &c, 1, MSG_OOB);\n"
4835 " send(fd1, &c, 1, MSG_OOB);\n"
4837 " if (fd1 E<gt> 0)\n"
4838 " if (FD_ISSET(fd1, &rd)) {\n"
4839 " r = read(fd1, buf1 + buf1_avail,\n"
4840 " BUF_SIZE - buf1_avail);\n"
4844 " buf1_avail += r;\n"
4846 " if (fd2 E<gt> 0)\n"
4847 " if (FD_ISSET(fd2, &rd)) {\n"
4848 " r = read(fd2, buf2 + buf2_avail,\n"
4849 " BUF_SIZE - buf2_avail);\n"
4853 " buf2_avail += r;\n"
4855 " if (fd1 E<gt> 0)\n"
4856 " if (FD_ISSET(fd1, &wr)) {\n"
4857 " r = write(fd1, buf2 + buf2_written,\n"
4858 " buf2_avail - buf2_written);\n"
4862 " buf2_written += r;\n"
4864 " if (fd2 E<gt> 0)\n"
4865 " if (FD_ISSET(fd2, &wr)) {\n"
4866 " r = write(fd2, buf1 + buf1_written,\n"
4867 " buf1_avail - buf1_written);\n"
4871 " buf1_written += r;\n"
4876 #: build/C/man2/select_tut.2:783
4878 msgid " /* check if write data has caught read data */\n"
4882 #: build/C/man2/select_tut.2:788
4885 " if (buf1_written == buf1_avail)\n"
4886 " buf1_written = buf1_avail = 0;\n"
4887 " if (buf2_written == buf2_avail)\n"
4888 " buf2_written = buf2_avail = 0;\n"
4892 #: build/C/man2/select_tut.2:791
4895 " /* one side has closed the connection, keep\n"
4896 " writing to the other side until empty */\n"
4900 #: build/C/man2/select_tut.2:799
4903 " if (fd1 E<lt> 0 && buf1_avail - buf1_written == 0)\n"
4905 " if (fd2 E<lt> 0 && buf2_avail - buf2_written == 0)\n"
4908 " exit(EXIT_SUCCESS);\n"
4913 #: build/C/man2/select_tut.2:813
4915 "The above program properly forwards most kinds of TCP connections including "
4916 "OOB signal data transmitted by B<telnet> servers. It handles the tricky "
4917 "problem of having data flow in both directions simultaneously. You might "
4918 "think it more efficient to use a B<fork>(2) call and devote a thread to "
4919 "each stream. This becomes more tricky than you might suspect. Another idea "
4920 "is to set nonblocking I/O using B<fcntl>(2). This also has its problems "
4921 "because you end up using inefficient timeouts."
4925 #: build/C/man2/select_tut.2:819
4927 "The program does not handle more than one simultaneous connection at a time, "
4928 "although it could easily be extended to do this with a linked list of "
4929 "buffers\\(emone for each connection. At the moment, new connections cause "
4930 "the current connection to be dropped."
4934 #. This man page was written by Paul Sheer.
4936 #: build/C/man2/select_tut.2:838
4938 "B<accept>(2), B<connect>(2), B<ioctl>(2), B<poll>(2), B<read>(2), "
4939 "B<recv>(2), B<select>(2), B<send>(2), B<sigprocmask>(2), B<write>(2), "
4940 "B<sigaddset>(3), B<sigdelset>(3), B<sigemptyset>(3), B<sigfillset>(3), "
4941 "B<sigismember>(3), B<epoll>(7)"
4945 #: build/C/man2/send.2:40
4951 #: build/C/man2/send.2:40
4957 #: build/C/man2/send.2:43
4958 msgid "send, sendto, sendmsg - send a message on a socket"
4962 #: build/C/man2/send.2:47
4965 "B<#include E<lt>sys/types.hE<gt>>\n"
4966 "B<#include E<lt>sys/socket.hE<gt>>\n"
4970 #: build/C/man2/send.2:50
4973 "B<ssize_t send(int >I<sockfd>B<, const void *>I<buf>B<, size_t >I<len>B<, "
4974 "int >I<flags>B<);>\n"
4978 #: build/C/man2/send.2:54
4981 "B<ssize_t sendto(int >I<sockfd>B<, const void *>I<buf>B<, size_t >I<len>B<, "
4982 "int >I<flags>B<,>\n"
4983 "B< const struct sockaddr *>I<dest_addr>B<, socklen_t "
4984 ">I<addrlen>B<);>\n"
4988 #: build/C/man2/send.2:57
4991 "B<ssize_t sendmsg(int >I<sockfd>B<, const struct msghdr *>I<msg>B<, int "
4996 #: build/C/man2/send.2:65
4998 "The system calls B<send>(), B<sendto>(), and B<sendmsg>() are used to "
4999 "transmit a message to another socket."
5003 #: build/C/man2/send.2:84
5005 "The B<send>() call may be used only when the socket is in a I<connected> "
5006 "state (so that the intended recipient is known). The only difference "
5007 "between B<send>() and B<write>(2) is the presence of I<flags>. With a "
5008 "zero I<flags> argument, B<send>() is equivalent to B<write>(2). Also, the "
5013 #: build/C/man2/send.2:86
5015 msgid " send(sockfd, buf, len, flags);\n"
5019 #: build/C/man2/send.2:88
5020 msgid "is equivalent to"
5024 #: build/C/man2/send.2:90
5026 msgid " sendto(sockfd, buf, len, flags, NULL, 0);\n"
5030 #: build/C/man2/send.2:94
5031 msgid "The argument I<sockfd> is the file descriptor of the sending socket."
5035 #: build/C/man2/send.2:122
5037 "If B<sendto>() is used on a connection-mode (B<SOCK_STREAM>, "
5038 "B<SOCK_SEQPACKET>) socket, the arguments I<dest_addr> and I<addrlen> are "
5039 "ignored (and the error B<EISCONN> may be returned when they are not NULL and "
5040 "0), and the error B<ENOTCONN> is returned when the socket was not actually "
5041 "connected. Otherwise, the address of the target is given by I<dest_addr> "
5042 "with I<addrlen> specifying its size. For B<sendmsg>(), the address of the "
5043 "target is given by I<msg.msg_name>, with I<msg.msg_namelen> specifying its "
5048 #: build/C/man2/send.2:138
5050 "For B<send>() and B<sendto>(), the message is found in I<buf> and has "
5051 "length I<len>. For B<sendmsg>(), the message is pointed to by the elements "
5052 "of the array I<msg.msg_iov>. The B<sendmsg>() call also allows sending "
5053 "ancillary data (also known as control information)."
5057 #: build/C/man2/send.2:143
5059 "If the message is too long to pass atomically through the underlying "
5060 "protocol, the error B<EMSGSIZE> is returned, and the message is not "
5065 #: build/C/man2/send.2:147
5067 "No indication of failure to deliver is implicit in a B<send>(). Locally "
5068 "detected errors are indicated by a return value of -1."
5072 #: build/C/man2/send.2:160
5074 "When the message does not fit into the send buffer of the socket, B<send>() "
5075 "normally blocks, unless the socket has been placed in nonblocking I/O mode. "
5076 "In nonblocking mode it would fail with the error B<EAGAIN> or B<EWOULDBLOCK> "
5077 "in this case. The B<select>(2) call may be used to determine when it is "
5078 "possible to send more data."
5081 #. FIXME ? document MSG_PROXY (which went away in 2.3.15)
5083 #: build/C/man2/send.2:166
5085 "The I<flags> argument is the bitwise OR of zero or more of the following "
5090 #: build/C/man2/send.2:166
5092 msgid "B<MSG_CONFIRM> (Since Linux 2.3.15)"
5096 #: build/C/man2/send.2:180
5098 "Tell the link layer that forward progress happened: you got a successful "
5099 "reply from the other side. If the link layer doesn't get this it will "
5100 "regularly reprobe the neighbor (e.g., via a unicast ARP). Only valid on "
5101 "B<SOCK_DGRAM> and B<SOCK_RAW> sockets and currently implemented only for "
5102 "IPv4 and IPv6. See B<arp>(7) for details."
5106 #: build/C/man2/send.2:180
5108 msgid "B<MSG_DONTROUTE>"
5112 #: build/C/man2/send.2:188
5114 "Don't use a gateway to send out the packet, send to hosts only on directly "
5115 "connected networks. This is usually used only by diagnostic or routing "
5116 "programs. This is defined only for protocol families that route; packet "
5121 #: build/C/man2/send.2:199
5123 "Enables nonblocking operation; if the operation would block, B<EAGAIN> or "
5124 "B<EWOULDBLOCK> is returned (this can also be enabled using the B<O_NONBLOCK> "
5125 "flag with the B<F_SETFL> B<fcntl>(2))."
5129 #: build/C/man2/send.2:199
5131 msgid "B<MSG_EOR> (since Linux 2.2)"
5135 #: build/C/man2/send.2:203
5137 "Terminates a record (when this notion is supported, as for sockets of type "
5138 "B<SOCK_SEQPACKET>)."
5142 #: build/C/man2/send.2:203
5144 msgid "B<MSG_MORE> (Since Linux 2.4.4)"
5148 #: build/C/man2/send.2:212
5150 "The caller has more data to send. This flag is used with TCP sockets to "
5151 "obtain the same effect as the B<TCP_CORK> socket option (see B<tcp>(7)), "
5152 "with the difference that this flag can be set on a per-call basis."
5156 #: build/C/man2/send.2:221
5158 "Since Linux 2.6, this flag is also supported for UDP sockets, and informs "
5159 "the kernel to package all of the data sent in calls with this flag set into "
5160 "a single datagram which is transmitted only when a call is performed that "
5161 "does not specify this flag. (See also the B<UDP_CORK> socket option "
5162 "described in B<udp>(7).)"
5166 #: build/C/man2/send.2:221
5168 msgid "B<MSG_NOSIGNAL> (since Linux 2.2)"
5172 #: build/C/man2/send.2:230
5174 "Requests not to send B<SIGPIPE> on errors on stream oriented sockets when "
5175 "the other end breaks the connection. The B<EPIPE> error is still returned."
5179 #: build/C/man2/send.2:239
5181 "Sends I<out-of-band> data on sockets that support this notion (e.g., of type "
5182 "B<SOCK_STREAM>); the underlying protocol must also support I<out-of-band> "
5187 #: build/C/man2/send.2:246
5189 "The definition of the I<msghdr> structure follows. See B<recv>(2) and "
5190 "below for an exact description of its fields."
5193 #. Still to be documented:
5194 #. Send file descriptors and user credentials using the
5195 #. msg_control* fields.
5196 #. The flags returned in msg_flags.
5198 #: build/C/man2/send.2:275
5200 "You may send control information using the I<msg_control> and "
5201 "I<msg_controllen> members. The maximum control buffer length the kernel can "
5202 "process is limited per socket by the value in "
5203 "I</proc/sys/net/core/optmem_max>; see B<socket>(7)."
5207 #: build/C/man2/send.2:280
5209 "On success, these calls return the number of characters sent. On error, -1 "
5210 "is returned, and I<errno> is set appropriately."
5214 #: build/C/man2/send.2:285
5216 "These are some standard errors generated by the socket layer. Additional "
5217 "errors may be generated and returned from the underlying protocol modules; "
5218 "see their respective manual pages."
5222 #: build/C/man2/send.2:293
5224 "(For UNIX domain sockets, which are identified by pathname) Write "
5225 "permission is denied on the destination socket file, or search permission is "
5226 "denied for one of the directories the path prefix. (See "
5227 "B<path_resolution>(7).)"
5231 #: build/C/man2/send.2:296
5233 "(For UDP sockets) An attempt was made to send to a network/broadcast address "
5234 "as though it was a unicast address."
5237 #. Actually EAGAIN on Linux
5239 #: build/C/man2/send.2:304
5241 "The socket is marked nonblocking and the requested operation would block. "
5242 "POSIX.1-2001 allows either error to be returned for this case, and does not "
5243 "require these constants to have the same value, so a portable application "
5244 "should check for both possibilities."
5248 #: build/C/man2/send.2:307
5249 msgid "An invalid descriptor was specified."
5253 #: build/C/man2/send.2:307
5255 msgid "B<ECONNRESET>"
5259 #: build/C/man2/send.2:310
5260 msgid "Connection reset by peer."
5264 #: build/C/man2/send.2:310
5266 msgid "B<EDESTADDRREQ>"
5270 #: build/C/man2/send.2:313
5271 msgid "The socket is not connection-mode, and no peer address is set."
5275 #: build/C/man2/send.2:316
5276 msgid "An invalid user space address was specified for an argument."
5280 #: build/C/man2/send.2:320
5281 msgid "A signal occurred before any data was transmitted; see B<signal>(7)."
5285 #: build/C/man2/send.2:329
5287 "The connection-mode socket was connected already but a recipient was "
5288 "specified. (Now either this error is returned, or the recipient "
5289 "specification is ignored.)"
5293 #: build/C/man2/send.2:329
5298 #. (e.g., SOCK_DGRAM )
5300 #: build/C/man2/send.2:335
5302 "The socket type requires that message be sent atomically, and the size of "
5303 "the message to be sent made this impossible."
5307 #: build/C/man2/send.2:343
5309 "The output queue for a network interface was full. This generally indicates "
5310 "that the interface has stopped sending, but may be caused by transient "
5311 "congestion. (Normally, this does not occur in Linux. Packets are just "
5312 "silently dropped when a device queue overflows.)"
5316 #: build/C/man2/send.2:346
5317 msgid "No memory available."
5321 #: build/C/man2/send.2:349
5322 msgid "The socket is not connected, and no target has been given."
5326 #: build/C/man2/send.2:359
5327 msgid "Some bit in the I<flags> argument is inappropriate for the socket type."
5331 #: build/C/man2/send.2:359
5337 #: build/C/man2/send.2:368
5339 "The local end has been shut down on a connection oriented socket. In this "
5340 "case the process will also receive a B<SIGPIPE> unless B<MSG_NOSIGNAL> is "
5345 #: build/C/man2/send.2:371
5346 msgid "4.4BSD, SVr4, POSIX.1-2001. These function calls appeared in 4.2BSD."
5350 #: build/C/man2/send.2:382
5352 "POSIX.1-2001 describes only the B<MSG_OOB> and B<MSG_EOR> flags. "
5353 "POSIX.1-2008 adds a specification of B<MSG_NOSIGNAL>. The B<MSG_CONFIRM> "
5354 "flag is a Linux extension."
5358 #: build/C/man2/send.2:395
5360 "The prototypes given above follow the Single UNIX Specification, as glibc2 "
5361 "also does; the I<flags> argument was I<int> in 4.x BSD, but I<unsigned int> "
5362 "in libc4 and libc5; the I<len> argument was I<int> in 4.x BSD and libc4, but "
5363 "I<size_t> in libc5; the I<addrlen> argument was I<int> in 4.x BSD and libc4 "
5364 "and libc5. See also B<accept>(2)."
5368 #: build/C/man2/send.2:414
5370 "See B<sendmmsg>(2) for information about a Linux-specific system call that "
5371 "can be used to transmit multiple datagrams in a single call."
5375 #: build/C/man2/send.2:419
5376 msgid "Linux may return B<EPIPE> instead of B<ENOTCONN>."
5380 #: build/C/man2/send.2:424
5381 msgid "An example of the use of B<sendto>() is shown in B<getaddrinfo>(3)."
5385 #: build/C/man2/send.2:439
5387 "B<fcntl>(2), B<getsockopt>(2), B<recv>(2), B<select>(2), B<sendfile>(2), "
5388 "B<sendmmsg>(2), B<shutdown>(2), B<socket>(2), B<write>(2), B<cmsg>(3), "
5389 "B<ip>(7), B<socket>(7), B<tcp>(7), B<udp>(7)"
5393 #: build/C/man2/sendmmsg.2:28
5399 #: build/C/man2/sendmmsg.2:28
5405 #: build/C/man2/sendmmsg.2:31
5406 msgid "sendmmsg - send multiple messages on a socket"
5410 #: build/C/man2/sendmmsg.2:39
5413 "B<int sendmmsg(int >I<sockfd>B<, struct mmsghdr *>I<msgvec>B<, unsigned int "
5415 "B< unsigned int >I<flags>B<);>\n"
5418 #. See commit 228e548e602061b08ee8e8966f567c12aa079682
5420 #: build/C/man2/sendmmsg.2:49
5422 "The B<sendmmsg>() system call is an extension of B<sendmsg>(2) that allows "
5423 "the caller to transmit multiple messages on a socket using a single system "
5424 "call. (This has performance benefits for some applications.)"
5428 #: build/C/man2/sendmmsg.2:54
5430 "The I<sockfd> argument is the file descriptor of the socket on which data is "
5431 "to be transmitted."
5435 #: build/C/man2/sendmmsg.2:75
5438 "struct mmsghdr {\n"
5439 " struct msghdr msg_hdr; /* Message header */\n"
5440 " unsigned int msg_len; /* Number of bytes transmitted */\n"
5445 #: build/C/man2/sendmmsg.2:91
5447 "The I<msg_hdr> field is a I<msghdr> structure, as described in "
5448 "B<sendmsg>(2). The I<msg_len> field is used to return the number of bytes "
5449 "sent from the message in I<msg_hdr> (i.e., the same as the return value from "
5450 "a single B<sendmsg>(2) call)."
5454 #: build/C/man2/sendmmsg.2:97
5456 "The I<flags> argument contains flags ORed together. The flags are the same "
5457 "as for B<sendmsg>(2)."
5461 #: build/C/man2/sendmmsg.2:107
5463 "A blocking B<sendmmsg>() call blocks until I<vlen> messages have been "
5464 "sent. A nonblocking call sends as many messages as possible (up to the "
5465 "limit specified by I<vlen>) and returns immediately."
5469 #: build/C/man2/sendmmsg.2:119
5471 "On return from B<sendmmsg>(), the I<msg_len> fields of successive elements "
5472 "of I<msgvec> are updated to contain the number of bytes transmitted from the "
5473 "corresponding I<msg_hdr>. The return value of the call indicates the number "
5474 "of elements of I<msgvec> that have been updated."
5478 #: build/C/man2/sendmmsg.2:129
5480 "On success, B<sendmmsg>() returns the number of messages sent from "
5481 "I<msgvec>; if this is less than I<vlen>, the caller can retry with a further "
5482 "B<sendmmsg>() call to send the remaining messages."
5486 #: build/C/man2/sendmmsg.2:133
5487 msgid "On error, -1 is returned, and I<errno> is set to indicate the error."
5490 #. commit 728ffb86f10873aaf4abd26dde691ee40ae731fe
5491 #. ... only return an error if no datagrams could be sent.
5492 #. If less than the requested number of messages were sent, the application
5493 #. must retry starting at the first failed one and if the problem is
5494 #. persistent the error will be returned.
5496 #. This matches the behaviour of other syscalls like read/write - it
5497 #. is not an error if less than the requested number of elements are sent.
5499 #: build/C/man2/sendmmsg.2:145
5501 "Errors are as for B<sendmsg>(2). An error is returned only if no datagrams "
5506 #: build/C/man2/sendmmsg.2:150
5508 "The B<sendmmsg>() system call was added in Linux 3.0. Support in glibc was "
5509 "added in version 2.14."
5513 #: build/C/man2/sendmmsg.2:153
5514 msgid "B<sendmmsg>() is Linux-specific."
5517 #. commit 98382f419f32d2c12d021943b87dea555677144b
5518 #. net: Cap number of elements for sendmmsg
5520 #. To limit the amount of time we can spend in sendmmsg, cap the
5521 #. number of elements to UIO_MAXIOV (currently 1024).
5523 #. For error handling an application using sendmmsg needs to retry at
5524 #. the first unsent message, so capping is simpler and requires less
5525 #. application logic than returning EINVAL.
5527 #: build/C/man2/sendmmsg.2:168
5528 msgid "The value specified in I<vlen> is capped to B<UIO_MAXIOV> (1024)."
5532 #: build/C/man2/sendmmsg.2:177
5534 "The example below uses B<sendmmsg>() to send I<onetwo> and I<three> in two "
5535 "distinct UDP datagrams using one system call. The contents of the first "
5536 "datagram originates from a pair of buffers."
5540 #: build/C/man2/sendmmsg.2:186
5543 "#define _GNU_SOURCE\n"
5544 "#include E<lt>netinet/ip.hE<gt>\n"
5545 "#include E<lt>stdio.hE<gt>\n"
5546 "#include E<lt>stdlib.hE<gt>\n"
5547 "#include E<lt>string.hE<gt>\n"
5548 "#include E<lt>sys/types.hE<gt>\n"
5549 "#include E<lt>sys/socket.hE<gt>\n"
5553 #: build/C/man2/sendmmsg.2:195
5560 " struct sockaddr_in sa;\n"
5561 " struct mmsghdr msg[2];\n"
5562 " struct iovec msg1[2], msg2;\n"
5567 #: build/C/man2/sendmmsg.2:209
5570 " sa.sin_family = AF_INET;\n"
5571 " sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);\n"
5572 " sa.sin_port = htons(1234);\n"
5573 " if (connect(sockfd, (struct sockaddr *) &sa, sizeof(sa)) == -1) {\n"
5574 " perror(\"connect()\");\n"
5575 " exit(EXIT_FAILURE);\n"
5580 #: build/C/man2/sendmmsg.2:215
5583 " memset(msg1, 0, sizeof(msg1));\n"
5584 " msg1[0].iov_base = \"one\";\n"
5585 " msg1[0].iov_len = 3;\n"
5586 " msg1[1].iov_base = \"two\";\n"
5587 " msg1[1].iov_len = 3;\n"
5591 #: build/C/man2/sendmmsg.2:219
5594 " memset(&msg2, 0, sizeof(msg2));\n"
5595 " msg2.iov_base = \"three\";\n"
5596 " msg2.iov_len = 5;\n"
5600 #: build/C/man2/sendmmsg.2:223
5603 " memset(msg, 0, sizeof(msg));\n"
5604 " msg[0].msg_hdr.msg_iov = msg1;\n"
5605 " msg[0].msg_hdr.msg_iovlen = 2;\n"
5609 #: build/C/man2/sendmmsg.2:226
5612 " msg[1].msg_hdr.msg_iov = &msg2;\n"
5613 " msg[1].msg_hdr.msg_iovlen = 1;\n"
5617 #: build/C/man2/sendmmsg.2:232
5620 " retval = sendmmsg(sockfd, msg, 2, 0);\n"
5621 " if (retval == -1)\n"
5622 " perror(\"sendmmsg()\");\n"
5624 " printf(\"%d messages sent\\en\", retval);\n"
5628 #: build/C/man2/sendmmsg.2:235
5636 #: build/C/man2/sendmmsg.2:241
5637 msgid "B<recvmmsg>(2), B<sendmsg>(2), B<socket>(2), B<socket>(7)"
5641 #: build/C/man3/sockatmark.3:25
5647 #: build/C/man3/sockatmark.3:28
5648 msgid "sockatmark - determine whether socket is at out-of-band mark"
5652 #: build/C/man3/sockatmark.3:30 build/C/man2/socket.2:50 build/C/man7/socket.7:50 build/C/man2/socketpair.2:49
5653 msgid "B<#include E<lt>sys/socket.hE<gt>>"
5657 #: build/C/man3/sockatmark.3:32
5658 msgid "B<int sockatmark(int >I<sockfd>B<);>"
5662 #: build/C/man3/sockatmark.3:41
5664 "B<sockatmark>(): _POSIX_C_SOURCE\\ E<gt>=\\ 200112L || _XOPEN_SOURCE\\ "
5669 #: build/C/man3/sockatmark.3:51
5671 "B<sockatmark>() returns a value indicating whether or not the socket "
5672 "referred to by the file descriptor I<sockfd> is at the out-of-band mark. If "
5673 "the socket is at the mark, then 1 is returned; if the socket is not at the "
5674 "mark, 0 is returned. This function does not remove the out-of-band mark."
5678 #: build/C/man3/sockatmark.3:58
5680 "A successful call to B<sockatmark>() returns 1 if the socket is at the "
5681 "out-of-band mark, or 0 if it is not. On error, -1 is returned and I<errno> "
5682 "is set to indicate the error."
5686 #: build/C/man3/sockatmark.3:63
5687 msgid "I<sockfd> is not a valid file descriptor."
5690 #. POSIX.1 says ENOTTY for this case
5692 #: build/C/man3/sockatmark.3:70
5693 msgid "I<sockfd> is not a file descriptor to which B<sockatmark>() can be applied."
5697 #: build/C/man3/sockatmark.3:73
5698 msgid "B<sockatmark>() was added to glibc in version 2.2.4."
5702 #: build/C/man3/sockatmark.3:75
5703 msgid "POSIX.1-2001."
5707 #: build/C/man3/sockatmark.3:82
5709 "If B<sockatmark>() returns 1, then the out-of-band data can be read using "
5710 "the B<MSG_OOB> flag of B<recv>(2)."
5714 #: build/C/man3/sockatmark.3:84
5715 msgid "Out-of-band data is supported only on some stream socket protocols."
5719 #: build/C/man3/sockatmark.3:89
5721 "B<sockatmark>() can safely be called from a handler for the B<SIGURG> "
5726 #: build/C/man3/sockatmark.3:95
5728 "B<sockatmark>() is implemented using the B<SIOCATMARK> B<ioctl>(2) "
5733 #: build/C/man3/sockatmark.3:99
5734 msgid "Prior to glibc 2.4, B<sockatmark>() did not work."
5738 #: build/C/man3/sockatmark.3:104
5740 "The following code can be used after receipt of a B<SIGURG> signal to read "
5741 "(and discard) all data up to the mark, and then read the byte of data at the "
5746 #: build/C/man3/sockatmark.3:109
5749 " char buf[BUF_LEN];\n"
5755 #: build/C/man3/sockatmark.3:116
5759 " atmark = sockatmark(sockfd);\n"
5760 " if (atmark == -1) {\n"
5761 " perror(\"sockatmark\");\n"
5767 #: build/C/man3/sockatmark.3:119
5775 #: build/C/man3/sockatmark.3:126
5778 " s = read(sockfd, buf, BUF_LEN) E<lt>= 0);\n"
5780 " perror(\"read\");\n"
5781 " if (s E<lt>= 0)\n"
5787 #: build/C/man3/sockatmark.3:133
5790 " if (atmark == 1) {\n"
5791 " if (recv(sockfd, &oobdata, 1, MSG_OOB) == -1) {\n"
5792 " perror(\"recv\");\n"
5799 #: build/C/man3/sockatmark.3:139
5800 msgid "B<fcntl>(2), B<recv>(2), B<send>(2), B<tcp>(7)"
5804 #: build/C/man2/socket.2:43 build/C/man7/socket.7:45
5810 #: build/C/man2/socket.2:43
5816 #: build/C/man2/socket.2:46
5817 msgid "socket - create an endpoint for communication"
5821 #: build/C/man2/socket.2:48 build/C/man2/socketpair.2:47
5822 msgid "B<#include E<lt>sys/types.hE<gt>> /* See NOTES */"
5826 #: build/C/man2/socket.2:52
5827 msgid "B<int socket(int >I<domain>B<, int >I<type>B<, int >I<protocol>B<);>"
5831 #: build/C/man2/socket.2:55
5832 msgid "B<socket>() creates an endpoint for communication and returns a descriptor."
5836 #: build/C/man2/socket.2:63
5838 "The I<domain> argument specifies a communication domain; this selects the "
5839 "protocol family which will be used for communication. These families are "
5840 "defined in I<E<lt>sys/socket.hE<gt>>. The currently understood formats "
5845 #: build/C/man2/socket.2:66
5847 msgid "Name:Purpose:Man page\n"
5851 #: build/C/man2/socket.2:67 build/C/man2/socket.2:74 build/C/man2/socket.2:79 build/C/man2/socket.2:84 build/C/man2/socket.2:87 build/C/man2/socket.2:94 build/C/man2/socket.2:99 build/C/man2/socket.2:104 build/C/man2/socket.2:107 build/C/man2/socket.2:112
5857 #: build/C/man2/socket.2:68
5859 msgid "B<AF_UNIX>, B<AF_LOCAL>\n"
5863 #: build/C/man2/socket.2:69 build/C/man2/socket.2:71 build/C/man2/socket.2:89 build/C/man2/socket.2:91 build/C/man2/socket.2:101 build/C/man2/socket.2:114 build/C/man2/socket.2:116 build/C/man7/socket.7:181
5869 #: build/C/man2/socket.2:70
5871 msgid "Local communication\n"
5875 #: build/C/man2/socket.2:72
5877 msgid "B<unix>(7)\n"
5881 #: build/C/man2/socket.2:73 build/C/man2/socket.2:78 build/C/man2/socket.2:83 build/C/man2/socket.2:93 build/C/man2/socket.2:98 build/C/man2/socket.2:111 build/C/man2/socket.2:118 build/C/man7/socket.7:160 build/C/man7/socket.7:164 build/C/man7/socket.7:167 build/C/man7/socket.7:173 build/C/man7/socket.7:176 build/C/man7/socket.7:185 build/C/man7/socket.7:192
5887 #: build/C/man2/socket.2:75
5889 msgid "B<AF_INET>\n"
5893 #: build/C/man2/socket.2:76
5895 msgid "T}:IPv4 Internet protocols:T{\n"
5899 #: build/C/man2/socket.2:77
5905 #: build/C/man2/socket.2:80
5907 msgid "B<AF_INET6>\n"
5911 #: build/C/man2/socket.2:81
5913 msgid "T}:IPv6 Internet protocols:T{\n"
5917 #: build/C/man2/socket.2:82
5919 msgid "B<ipv6>(7)\n"
5923 #: build/C/man2/socket.2:85
5929 #: build/C/man2/socket.2:86
5931 msgid "T}:IPX - Novell protocols:\n"
5935 #: build/C/man2/socket.2:88
5937 msgid "B<AF_NETLINK>\n"
5941 #: build/C/man2/socket.2:90
5943 msgid "Kernel user interface device\n"
5947 #: build/C/man2/socket.2:92
5949 msgid "B<netlink>(7)\n"
5953 #: build/C/man2/socket.2:95
5959 #: build/C/man2/socket.2:96
5961 msgid "T}:ITU-T X.25 / ISO-8208 protocol:T{\n"
5965 #: build/C/man2/socket.2:97
5971 #: build/C/man2/socket.2:100
5973 msgid "B<AF_AX25>\n"
5977 #: build/C/man2/socket.2:102
5979 msgid "Amateur radio AX.25 protocol\n"
5983 #: build/C/man2/socket.2:103
5989 #: build/C/man2/socket.2:105
5991 msgid "B<AF_ATMPVC>\n"
5995 #: build/C/man2/socket.2:106
5997 msgid "T}:Access to raw ATM PVCs:\n"
6001 #: build/C/man2/socket.2:108
6003 msgid "B<AF_APPLETALK>\n"
6007 #: build/C/man2/socket.2:109
6009 msgid "T}:Appletalk:T{\n"
6013 #: build/C/man2/socket.2:110
6019 #: build/C/man2/socket.2:113
6021 msgid "B<AF_PACKET>\n"
6025 #: build/C/man2/socket.2:115
6027 msgid "Low level packet interface\n"
6031 #: build/C/man2/socket.2:117
6033 msgid "B<packet>(7)\n"
6037 #: build/C/man2/socket.2:126
6039 "The socket has the indicated I<type>, which specifies the communication "
6040 "semantics. Currently defined types are:"
6044 #: build/C/man2/socket.2:126
6046 msgid "B<SOCK_STREAM>"
6050 #: build/C/man2/socket.2:130
6052 "Provides sequenced, reliable, two-way, connection-based byte streams. An "
6053 "out-of-band data transmission mechanism may be supported."
6057 #: build/C/man2/socket.2:130
6059 msgid "B<SOCK_DGRAM>"
6063 #: build/C/man2/socket.2:134
6065 "Supports datagrams (connectionless, unreliable messages of a fixed maximum "
6070 #: build/C/man2/socket.2:134
6072 msgid "B<SOCK_SEQPACKET>"
6076 #: build/C/man2/socket.2:139
6078 "Provides a sequenced, reliable, two-way connection-based data transmission "
6079 "path for datagrams of fixed maximum length; a consumer is required to read "
6080 "an entire packet with each input system call."
6084 #: build/C/man2/socket.2:139
6090 #: build/C/man2/socket.2:142
6091 msgid "Provides raw network protocol access."
6095 #: build/C/man2/socket.2:142
6101 #: build/C/man2/socket.2:145
6102 msgid "Provides a reliable datagram layer that does not guarantee ordering."
6106 #: build/C/man2/socket.2:145
6108 msgid "B<SOCK_PACKET>"
6112 #: build/C/man2/socket.2:150
6113 msgid "Obsolete and should not be used in new programs; see B<packet>(7)."
6117 #: build/C/man2/socket.2:156
6119 "Some socket types may not be implemented by all protocol families; for "
6120 "example, B<SOCK_SEQPACKET> is not implemented for B<AF_INET>."
6124 #: build/C/man2/socket.2:164
6126 "Since Linux 2.6.27, the I<type> argument serves a second purpose: in "
6127 "addition to specifying a socket type, it may include the bitwise OR of any "
6128 "of the following values, to modify the behavior of B<socket>():"
6132 #: build/C/man2/socket.2:198
6134 "The I<protocol> specifies a particular protocol to be used with the socket. "
6135 "Normally only a single protocol exists to support a particular socket type "
6136 "within a given protocol family, in which case I<protocol> can be specified "
6137 "as 0. However, it is possible that many protocols may exist, in which case "
6138 "a particular protocol must be specified in this manner. The protocol number "
6139 "to use is specific to the ``communication domain'' in which communication is "
6140 "to take place; see B<protocols>(5). See B<getprotoent>(3) on how to map "
6141 "protocol name strings to protocol numbers."
6145 #: build/C/man2/socket.2:228
6147 "Sockets of type B<SOCK_STREAM> are full-duplex byte streams, similar to "
6148 "pipes. They do not preserve record boundaries. A stream socket must be in "
6149 "a I<connected> state before any data may be sent or received on it. A "
6150 "connection to another socket is created with a B<connect>(2) call. Once "
6151 "connected, data may be transferred using B<read>(2) and B<write>(2) calls "
6152 "or some variant of the B<send>(2) and B<recv>(2) calls. When a session "
6153 "has been completed a B<close>(2) may be performed. Out-of-band data may "
6154 "also be transmitted as described in B<send>(2) and received as described in "
6159 #: build/C/man2/socket.2:254
6161 "The communications protocols which implement a B<SOCK_STREAM> ensure that "
6162 "data is not lost or duplicated. If a piece of data for which the peer "
6163 "protocol has buffer space cannot be successfully transmitted within a "
6164 "reasonable length of time, then the connection is considered to be dead. "
6165 "When B<SO_KEEPALIVE> is enabled on the socket the protocol checks in a "
6166 "protocol-specific manner if the other end is still alive. A B<SIGPIPE> "
6167 "signal is raised if a process sends or receives on a broken stream; this "
6168 "causes naive processes, which do not handle the signal, to exit. "
6169 "B<SOCK_SEQPACKET> sockets employ the same system calls as B<SOCK_STREAM> "
6170 "sockets. The only difference is that B<read>(2) calls will return only the "
6171 "amount of data requested, and any data remaining in the arriving packet will "
6172 "be discarded. Also all message boundaries in incoming datagrams are "
6177 #: build/C/man2/socket.2:264
6179 "B<SOCK_DGRAM> and B<SOCK_RAW> sockets allow sending of datagrams to "
6180 "correspondents named in B<sendto>(2) calls. Datagrams are generally "
6181 "received with B<recvfrom>(2), which returns the next datagram along with the "
6182 "address of its sender."
6186 #: build/C/man2/socket.2:271
6188 "B<SOCK_PACKET> is an obsolete socket type to receive raw packets directly "
6189 "from the device driver. Use B<packet>(7) instead."
6193 #: build/C/man2/socket.2:294
6195 "An B<fcntl>(2) B<F_SETOWN> operation can be used to specify a process or "
6196 "process group to receive a B<SIGURG> signal when the out-of-band data "
6197 "arrives or B<SIGPIPE> signal when a B<SOCK_STREAM> connection breaks "
6198 "unexpectedly. This operation may also be used to set the process or process "
6199 "group that receives the I/O and asynchronous notification of I/O events via "
6200 "B<SIGIO>. Using B<F_SETOWN> is equivalent to an B<ioctl>(2) call with the "
6201 "B<FIOSETOWN> or B<SIOCSPGRP> argument."
6205 #: build/C/man2/socket.2:304
6207 "When the network signals an error condition to the protocol module (e.g., "
6208 "using a ICMP message for IP) the pending error flag is set for the socket. "
6209 "The next operation on this socket will return the error code of the pending "
6210 "error. For some protocols it is possible to enable a per-socket error queue "
6211 "to retrieve detailed information about the error; see B<IP_RECVERR> in "
6216 #: build/C/man2/socket.2:314
6218 "The operation of sockets is controlled by socket level I<options>. These "
6219 "options are defined in I<E<lt>sys/socket.hE<gt>>. The functions "
6220 "B<setsockopt>(2) and B<getsockopt>(2) are used to set and get options, "
6225 #: build/C/man2/socket.2:319
6227 "On success, a file descriptor for the new socket is returned. On error, -1 "
6228 "is returned, and I<errno> is set appropriately."
6232 #: build/C/man2/socket.2:324
6234 "Permission to create a socket of the specified type and/or protocol is "
6239 #: build/C/man2/socket.2:327
6240 msgid "The implementation does not support the specified address family."
6244 #: build/C/man2/socket.2:330
6245 msgid "Unknown protocol, or protocol family not available."
6248 #. Since Linux 2.6.27
6250 #: build/C/man2/socket.2:335
6251 msgid "Invalid flags in I<type>."
6255 #: build/C/man2/socket.2:338
6256 msgid "Process file table overflow."
6260 #: build/C/man2/socket.2:341
6262 msgid "B<ENOBUFS> or B<ENOMEM>"
6266 #: build/C/man2/socket.2:346
6268 "Insufficient memory is available. The socket cannot be created until "
6269 "sufficient resources are freed."
6273 #: build/C/man2/socket.2:346 build/C/man2/socketpair.2:92
6275 msgid "B<EPROTONOSUPPORT>"
6279 #: build/C/man2/socket.2:350
6281 "The protocol type or the specified protocol is not supported within this "
6286 #: build/C/man2/socket.2:352
6287 msgid "Other errors may be generated by the underlying protocol modules."
6291 #: build/C/man2/socket.2:354
6292 msgid "4.4BSD, POSIX.1-2001."
6296 #: build/C/man2/socket.2:360
6297 msgid "The B<SOCK_NONBLOCK> and B<SOCK_CLOEXEC> flags are Linux-specific."
6301 #: build/C/man2/socket.2:366
6303 "B<socket>() appeared in 4.2BSD. It is generally portable to/from non-BSD "
6304 "systems supporting clones of the BSD socket layer (including System V "
6309 #: build/C/man2/socket.2:385
6311 "The manifest constants used under 4.x BSD for protocol families are "
6312 "B<PF_UNIX>, B<PF_INET>, and so on, while B<AF_UNIX>, B<AF_INET>, and so on "
6313 "are used for address families. However, already the BSD man page promises: "
6314 "\"The protocol family generally is the same as the address family\", and "
6315 "subsequent standards use AF_* everywhere."
6319 #: build/C/man2/socket.2:390
6320 msgid "An example of the use of B<socket>() is shown in B<getaddrinfo>(3)."
6324 #: build/C/man2/socket.2:413
6326 "B<accept>(2), B<bind>(2), B<connect>(2), B<fcntl>(2), B<getpeername>(2), "
6327 "B<getsockname>(2), B<getsockopt>(2), B<ioctl>(2), B<listen>(2), B<read>(2), "
6328 "B<recv>(2), B<select>(2), B<send>(2), B<shutdown>(2), B<socketpair>(2), "
6329 "B<write>(2), B<getprotoent>(3), B<ip>(7), B<socket>(7), B<tcp>(7), "
6330 "B<udp>(7), B<unix>(7)"
6334 #: build/C/man2/socket.2:419
6336 "\\(lqAn Introductory 4.3BSD Interprocess Communication Tutorial\\(rq and "
6337 "\\(lqBSD Interprocess Communication Tutorial\\(rq, reprinted in I<UNIX "
6338 "Programmer's Supplementary Documents Volume 1.>"
6342 #: build/C/man7/socket.7:48
6343 msgid "socket - Linux socket interface"
6347 #: build/C/man7/socket.7:52
6349 "I<sockfd>B< = socket(int >I<socket_family>B<, int >I<socket_type>B<, int "
6354 #: build/C/man7/socket.7:71
6356 "This manual page describes the Linux networking socket layer user "
6357 "interface. The BSD compatible sockets are the uniform interface between the "
6358 "user process and the network protocol stacks in the kernel. The protocol "
6359 "modules are grouped into I<protocol families> like B<AF_INET>, B<AF_IPX>, "
6360 "B<AF_PACKET> and I<socket types> like B<SOCK_STREAM> or B<SOCK_DGRAM>. See "
6361 "B<socket>(2) for more information on families and types."
6365 #: build/C/man7/socket.7:71
6367 msgid "Socket-layer functions"
6371 #: build/C/man7/socket.7:75
6373 "These functions are used by the user process to send or receive packets and "
6374 "to do other socket operations. For more information see their respective "
6379 #: build/C/man7/socket.7:91
6381 "B<socket>(2) creates a socket, B<connect>(2) connects a socket to a remote "
6382 "socket address, the B<bind>(2) function binds a socket to a local socket "
6383 "address, B<listen>(2) tells the socket that new connections shall be "
6384 "accepted, and B<accept>(2) is used to get a new socket with a new incoming "
6385 "connection. B<socketpair>(2) returns two connected anonymous sockets "
6386 "(implemented only for a few local families like B<AF_UNIX>)"
6390 #: build/C/man7/socket.7:113
6392 "B<send>(2), B<sendto>(2), and B<sendmsg>(2) send data over a socket, and "
6393 "B<recv>(2), B<recvfrom>(2), B<recvmsg>(2) receive data from a socket. "
6394 "B<poll>(2) and B<select>(2) wait for arriving data or a readiness to send "
6395 "data. In addition, the standard I/O operations like B<write>(2), "
6396 "B<writev>(2), B<sendfile>(2), B<read>(2), and B<readv>(2) can be used to "
6397 "read and write data."
6401 #: build/C/man7/socket.7:124
6403 "B<getsockname>(2) returns the local socket address and B<getpeername>(2) "
6404 "returns the remote socket address. B<getsockopt>(2) and B<setsockopt>(2) "
6405 "are used to set or get socket layer or protocol options. B<ioctl>(2) can "
6406 "be used to set or read some other options."
6410 #: build/C/man7/socket.7:129
6412 "B<close>(2) is used to close a socket. B<shutdown>(2) closes parts of a "
6413 "full-duplex socket connection."
6417 #: build/C/man7/socket.7:135
6419 "Seeking, or calling B<pread>(2) or B<pwrite>(2) with a nonzero position is "
6420 "not supported on sockets."
6424 #: build/C/man7/socket.7:152
6426 "It is possible to do nonblocking I/O on sockets by setting the B<O_NONBLOCK> "
6427 "flag on a socket file descriptor using B<fcntl>(2). Then all operations "
6428 "that would block will (usually) return with B<EAGAIN> (operation should be "
6429 "retried later); B<connect>(2) will return B<EINPROGRESS> error. The user "
6430 "can then wait for various events via B<poll>(2) or B<select>(2)."
6434 #: build/C/man7/socket.7:156
6436 msgid "I/O events\n"
6440 #: build/C/man7/socket.7:157
6442 msgid "Event:Poll flag:Occurrence\n"
6446 #: build/C/man7/socket.7:158 build/C/man7/socket.7:161
6448 msgid "Read:POLLIN:T{\n"
6452 #: build/C/man7/socket.7:159
6454 msgid "New data arrived.\n"
6458 #: build/C/man7/socket.7:162
6460 msgid "A connection setup has been completed\n"
6464 #: build/C/man7/socket.7:163
6466 msgid "(for connection-oriented sockets)\n"
6470 #: build/C/man7/socket.7:165 build/C/man7/socket.7:168
6472 msgid "Read:POLLHUP:T{\n"
6476 #: build/C/man7/socket.7:166
6478 msgid "A disconnection request has been initiated by the other end.\n"
6482 #: build/C/man7/socket.7:169
6484 msgid "A connection is broken (only for connection-oriented protocols).\n"
6488 #: build/C/man7/socket.7:170
6490 msgid "When the socket is written\n"
6494 #: build/C/man7/socket.7:171
6496 msgid "B<SIGPIPE>\n"
6500 #: build/C/man7/socket.7:172
6502 msgid "is also sent.\n"
6506 #: build/C/man7/socket.7:174
6508 msgid "Write:POLLOUT:T{\n"
6512 #: build/C/man7/socket.7:175
6514 msgid "Socket has enough send buffer space for writing new data.\n"
6518 #: build/C/man7/socket.7:177
6520 msgid "Read/Write:T{\n"
6524 #: build/C/man7/socket.7:178
6530 #: build/C/man7/socket.7:179
6536 #: build/C/man7/socket.7:180
6542 #: build/C/man7/socket.7:182
6544 msgid "An outgoing\n"
6548 #: build/C/man7/socket.7:183
6550 msgid "B<connect>(2)\n"
6554 #: build/C/man7/socket.7:184
6560 #: build/C/man7/socket.7:186
6562 msgid "Read/Write:POLLERR:An asynchronous error occurred.\n"
6566 #: build/C/man7/socket.7:187
6568 msgid "Read/Write:POLLHUP:The other end has shut down one direction.\n"
6572 #: build/C/man7/socket.7:188
6574 msgid "Exception:POLLPRI:T{\n"
6578 #: build/C/man7/socket.7:189
6580 msgid "Urgent data arrived.\n"
6584 #: build/C/man7/socket.7:190
6590 #: build/C/man7/socket.7:191
6592 msgid "is sent then.\n"
6596 #: build/C/man7/socket.7:220
6598 "An alternative to B<poll>(2) and B<select>(2) is to let the kernel inform "
6599 "the application about events via a B<SIGIO> signal. For that the B<O_ASYNC> "
6600 "flag must be set on a socket file descriptor via B<fcntl>(2) and a valid "
6601 "signal handler for B<SIGIO> must be installed via B<sigaction>(2). See the "
6602 "I<Signals> discussion below."
6606 #: build/C/man7/socket.7:220
6608 msgid "Socket address structures"
6612 #: build/C/man7/socket.7:236
6614 "Each socket domain has its own format for socket addresses, with a "
6615 "domain-specific address structure. Each of these structures begins with an "
6616 "integer \"family\" field (typed as I<sa_family_t>) that indicates the type "
6617 "of the address structure. This allows the various system calls (e.g., "
6618 "B<connect>(2), B<bind>(2), B<accept>(2), B<getsockname>(2), "
6619 "B<getpeername>(2)), which are generic to all socket domains, to determine "
6620 "the domain of a particular socket address."
6624 #: build/C/man7/socket.7:246
6626 "To allow any type of socket address to be passed to interfaces in the "
6627 "sockets API, the type I<struct sockaddr> is defined. The purpose of this "
6628 "type is purely to allow casting of domain-specific socket address types to a "
6629 "\"generic\" type, so as to avoid compiler warnings about type mismatches in "
6630 "calls to the sockets API."
6634 #: build/C/man7/socket.7:256
6636 "In addition, the sockets API provides the data type I<struct "
6637 "sockaddr_storage>. This type is suitable to accommodate all supported "
6638 "domain-specific socket address structures; it is large enough and is aligned "
6639 "properly. (In particular, it is large enough to hold IPv6 socket "
6640 "addresses.) The structure includes the following field, which can be used "
6641 "to identify the type of socket address actually stored in the structure:"
6645 #: build/C/man7/socket.7:260
6647 msgid " sa_family_t ss_family;\n"
6651 #: build/C/man7/socket.7:268
6653 "The I<sockaddr_storage> structure is useful in programs that must handle "
6654 "socket addresses in a generic way (e.g., programs that must deal with both "
6655 "IPv4 and IPv6 socket addresses)."
6659 #: build/C/man7/socket.7:268
6661 msgid "Socket options"
6665 #. In the list below, the text used to describe argument types
6666 #. for each socket option should be more consistent
6668 #. SO_ACCEPTCONN is in POSIX.1-2001, and its origin is explained in
6669 #. W R Stevens, UNPv1
6671 #: build/C/man7/socket.7:286
6673 "The socket options listed below can be set by using B<setsockopt>(2) and "
6674 "read with B<getsockopt>(2) with the socket level set to B<SOL_SOCKET> for "
6675 "all sockets. Unless otherwise noted, I<optval> is a pointer to an I<int>."
6679 #: build/C/man7/socket.7:286
6681 msgid "B<SO_ACCEPTCONN>"
6685 #: build/C/man7/socket.7:294
6687 "Returns a value indicating whether or not this socket has been marked to "
6688 "accept connections with B<listen>(2). The value 0 indicates that this is "
6689 "not a listening socket, the value 1 indicates that this is a listening "
6690 "socket. This socket option is read-only."
6694 #: build/C/man7/socket.7:294
6696 msgid "B<SO_BINDTODEVICE>"
6700 #: build/C/man7/socket.7:313
6702 "Bind this socket to a particular device like \\(lqeth0\\(rq, as specified in "
6703 "the passed interface name. If the name is an empty string or the option "
6704 "length is zero, the socket device binding is removed. The passed option is "
6705 "a variable-length null-terminated interface name string with the maximum "
6706 "size of B<IFNAMSIZ>. If a socket is bound to an interface, only packets "
6707 "received from that particular interface are processed by the socket. Note "
6708 "that this works only for some socket types, particularly B<AF_INET> "
6709 "sockets. It is not supported for packet sockets (use normal B<bind>(2) "
6714 #: build/C/man7/socket.7:327
6716 "Before Linux 3.8, this socket option could be set, but could not retrieved "
6717 "with B<getsockopt>(2). Since Linux 3.8, it is readable. The I<optlen> "
6718 "argument should contain the buffer size available to receive the device name "
6719 "and is recommended to be B<IFNAMSZ> bytes. The real device name length is "
6720 "reported back in the I<optlen> argument."
6724 #: build/C/man7/socket.7:327
6726 msgid "B<SO_BROADCAST>"
6730 #: build/C/man7/socket.7:333
6732 "Set or get the broadcast flag. When enabled, datagram sockets are allowed "
6733 "to send packets to a broadcast address. This option has no effect on "
6734 "stream-oriented sockets."
6738 #: build/C/man7/socket.7:333
6740 msgid "B<SO_BSDCOMPAT>"
6744 #: build/C/man7/socket.7:345
6746 "Enable BSD bug-to-bug compatibility. This is used by the UDP protocol "
6747 "module in Linux 2.0 and 2.2. If enabled ICMP errors received for a UDP "
6748 "socket will not be passed to the user program. In later kernel versions, "
6749 "support for this option has been phased out: Linux 2.4 silently ignores it, "
6750 "and Linux 2.6 generates a kernel warning (printk()) if a program uses this "
6751 "option. Linux 2.0 also enabled BSD bug-to-bug compatibility options (random "
6752 "header changing, skipping of the broadcast flag) for raw sockets with this "
6753 "option, but that was removed in Linux 2.2."
6757 #: build/C/man7/socket.7:345
6763 #: build/C/man7/socket.7:351
6765 "Enable socket debugging. Only allowed for processes with the "
6766 "B<CAP_NET_ADMIN> capability or an effective user ID of 0."
6770 #: build/C/man7/socket.7:351
6772 msgid "B<SO_DOMAIN> (since Linux 2.6.32)"
6776 #: build/C/man7/socket.7:359
6778 "Retrieves the socket domain as an integer, returning a value such as "
6779 "B<AF_INET6>. See B<socket>(2) for details. This socket option is "
6784 #: build/C/man7/socket.7:359
6790 #: build/C/man7/socket.7:364
6792 "Get and clear the pending socket error. This socket option is read-only. "
6793 "Expects an integer."
6797 #: build/C/man7/socket.7:364
6799 msgid "B<SO_DONTROUTE>"
6803 #: build/C/man7/socket.7:373
6805 "Don't send via a gateway, send only to directly connected hosts. The same "
6806 "effect can be achieved by setting the B<MSG_DONTROUTE> flag on a socket "
6807 "B<send>(2) operation. Expects an integer boolean flag."
6811 #: build/C/man7/socket.7:373
6813 msgid "B<SO_KEEPALIVE>"
6817 #: build/C/man7/socket.7:377
6819 "Enable sending of keep-alive messages on connection-oriented sockets. "
6820 "Expects an integer boolean flag."
6824 #: build/C/man7/socket.7:377
6826 msgid "B<SO_LINGER>"
6830 #: build/C/man7/socket.7:385
6832 "Sets or gets the B<SO_LINGER> option. The argument is a I<linger> "
6837 #: build/C/man7/socket.7:392
6841 " int l_onoff; /* linger active */\n"
6842 " int l_linger; /* how many seconds to linger for */\n"
6847 #: build/C/man7/socket.7:406
6849 "When enabled, a B<close>(2) or B<shutdown>(2) will not return until all "
6850 "queued messages for the socket have been successfully sent or the linger "
6851 "timeout has been reached. Otherwise, the call returns immediately and the "
6852 "closing is done in the background. When the socket is closed as part of "
6853 "B<exit>(2), it always lingers in the background."
6857 #: build/C/man7/socket.7:406
6859 msgid "B<SO_MARK> (since Linux 2.6.25)"
6862 #. commit 4a19ec5800fc3bb64e2d87c4d9fdd9e636086fe0
6863 #. and 914a9ab386a288d0f22252fc268ecbc048cdcbd5
6865 #: build/C/man7/socket.7:417
6867 "Set the mark for each packet sent through this socket (similar to the "
6868 "netfilter MARK target but socket-based). Changing the mark can be used for "
6869 "mark-based routing without netfilter or for packet filtering. Setting this "
6870 "option requires the B<CAP_NET_ADMIN> capability."
6874 #: build/C/man7/socket.7:417
6876 msgid "B<SO_OOBINLINE>"
6879 #. don't document it because it can do too much harm.
6882 #: build/C/man7/socket.7:426
6884 "If this option is enabled, out-of-band data is directly placed into the "
6885 "receive data stream. Otherwise out-of-band data is passed only when the "
6886 "B<MSG_OOB> flag is set during receiving."
6890 #: build/C/man7/socket.7:426
6892 msgid "B<SO_PASSCRED>"
6895 #. FIXME Document SO_PASSSEC, added in 2.6.18; there is some info
6896 #. in the 2.6.18 ChangeLog
6898 #: build/C/man7/socket.7:435
6900 "Enable or disable the receiving of the B<SCM_CREDENTIALS> control message. "
6901 "For more information see B<unix>(7)."
6905 #: build/C/man7/socket.7:435
6907 msgid "B<SO_PEEK_OFF> (since Linux 3.4)"
6910 #. commit ef64a54f6e558155b4f149bb10666b9e914b6c54
6912 #: build/C/man7/socket.7:445
6914 "This option, which is currently supported only for B<unix>(7) sockets, sets "
6915 "the value of the \"peek offset\" for the B<recv(2)> system call when used "
6916 "with B<MSG_PEEK> flag."
6920 #: build/C/man7/socket.7:453
6922 "When this option is set to a negative value (it is set to -1 for all new "
6923 "sockets), traditional behavior is provided: B<recv(2)> with the B<MSG_PEEK> "
6924 "flag will peek data from the front of the queue."
6928 #: build/C/man7/socket.7:460
6930 "When the option is set to a value greater than or equal to zero, then the "
6931 "next peek at data queued in the socket will occur at the byte offset "
6932 "specified by the option value. At the same time, the \"peek offset\" will "
6933 "be incremented by the number of bytes that were peeked from the queue, so "
6934 "that a subsequent peek will return the next data in the queue."
6938 #: build/C/man7/socket.7:472
6940 "If data is removed from the front of the queue via a call to B<recv>(2) (or "
6941 "similar) without the B<MSG_PEEK> flag, the \"peek offset\" will be decreased "
6942 "by the number of bytes removed. In other words, receiving data without the "
6943 "B<MSG_PEEK> flag will cause the \"peek offset\" to be adjusted to maintain "
6944 "the correct relative position in the queued data, so that a subsequent peek "
6945 "will retrieve the data that would have been retrieved had the data not been "
6950 #: build/C/man7/socket.7:477
6952 "For datagram sockets, if the \"peek offset\" points to the middle of a "
6953 "packet, the data returned will be marked with the B<MSG_TRUNC> flag."
6957 #: build/C/man7/socket.7:481
6959 "The following example serves to illustrate the use of B<SO_PEEK_OFF>. "
6960 "Suppose a stream socket has the following queued input data:"
6964 #: build/C/man7/socket.7:483
6966 msgid " aabbccddeeff\n"
6970 #: build/C/man7/socket.7:488
6972 "The following sequence of B<recv>(2) calls would have the effect noted in "
6977 #: build/C/man7/socket.7:493
6980 "int ov = 4; // Set peek offset to 4\n"
6981 "setsockopt(fd, SOL_SOCKET, SO_PEEK_OFF, &ov, sizeof(ov));\n"
6985 #: build/C/man7/socket.7:498
6988 "recv(fd, buf, 2, MSG_PEEK); // Peeks \"cc\"; offset set to 6\n"
6989 "recv(fd, buf, 2, MSG_PEEK); // Peeks \"dd\"; offset set to 8\n"
6990 "recv(fd, buf, 2, 0); // Reads \"aa\"; offset set to 6\n"
6991 "recv(fd, buf, 2, MSG_PEEK); // Peeks \"ee\"; offset set to 8\n"
6995 #: build/C/man7/socket.7:500
6997 msgid "B<SO_PEERCRED>"
7001 #: build/C/man7/socket.7:523
7003 "Return the credentials of the foreign process connected to this socket. "
7004 "This is possible only for connected B<AF_UNIX> stream sockets and B<AF_UNIX> "
7005 "stream and datagram socket pairs created using B<socketpair>(2); see "
7006 "B<unix>(7). The returned credentials are those that were in effect at the "
7007 "time of the call to B<connect>(2) or B<socketpair>(2). The argument is a "
7008 "I<ucred> structure; define the B<GNU_SOURCE> feature test macro to obtain "
7009 "the definition of that structure from I<E<lt>sys/socket.hE<gt>>. This "
7010 "socket option is read-only."
7014 #: build/C/man7/socket.7:523
7016 msgid "B<SO_PRIORITY>"
7020 #: build/C/man7/socket.7:536
7022 "Set the protocol-defined priority for all packets to be sent on this "
7023 "socket. Linux uses this value to order the networking queues: packets with "
7024 "a higher priority may be processed first depending on the selected device "
7025 "queueing discipline. For B<ip>(7), this also sets the IP type-of-service "
7026 "(TOS) field for outgoing packets. Setting a priority outside the range 0 to "
7027 "6 requires the B<CAP_NET_ADMIN> capability."
7031 #: build/C/man7/socket.7:536
7033 msgid "B<SO_PROTOCOL> (since Linux 2.6.32)"
7037 #: build/C/man7/socket.7:544
7039 "Retrieves the socket protocol as an integer, returning a value such as "
7040 "B<IPPROTO_SCTP>. See B<socket>(2) for details. This socket option is "
7045 #: build/C/man7/socket.7:544
7047 msgid "B<SO_RCVBUF>"
7050 #. Most (all?) other implementations do not do this -- MTK, Dec 05
7051 #. The following thread on LMKL is quite informative:
7052 #. getsockopt/setsockopt with SO_RCVBUF and SO_SNDBUF "non-standard" behaviour
7054 #. http://thread.gmane.org/gmane.linux.kernel/1328935
7056 #: build/C/man7/socket.7:563
7058 "Sets or gets the maximum socket receive buffer in bytes. The kernel doubles "
7059 "this value (to allow space for bookkeeping overhead) when it is set using "
7060 "B<setsockopt>(2), and this doubled value is returned by B<getsockopt>(2). "
7061 "The default value is set by the I</proc/sys/net/core/rmem_default> file, and "
7062 "the maximum allowed value is set by the I</proc/sys/net/core/rmem_max> "
7063 "file. The minimum (doubled) value for this option is 256."
7067 #: build/C/man7/socket.7:563
7069 msgid "B<SO_RCVBUFFORCE> (since Linux 2.6.14)"
7073 #: build/C/man7/socket.7:572
7075 "Using this socket option, a privileged (B<CAP_NET_ADMIN>) process can "
7076 "perform the same task as B<SO_RCVBUF>, but the I<rmem_max> limit can be "
7081 #: build/C/man7/socket.7:572
7083 msgid "B<SO_RCVLOWAT> and B<SO_SNDLOWAT>"
7086 #. See http://marc.theaimsgroup.com/?l=linux-kernel&m=111049368106984&w=2
7087 #. Tested on kernel 2.6.14 -- mtk, 30 Nov 05
7089 #: build/C/man7/socket.7:601
7091 "Specify the minimum number of bytes in the buffer until the socket layer "
7092 "will pass the data to the protocol (B<SO_SNDLOWAT>) or the user on "
7093 "receiving (B<SO_RCVLOWAT>). These two values are initialized to 1. "
7094 "B<SO_SNDLOWAT> is not changeable on Linux (B<setsockopt>(2) fails with the "
7095 "error B<ENOPROTOOPT>). B<SO_RCVLOWAT> is changeable only since Linux 2.4. "
7096 "The B<select>(2) and B<poll>(2) system calls currently do not respect the "
7097 "B<SO_RCVLOWAT> setting on Linux, and mark a socket readable when even a "
7098 "single byte of data is available. A subsequent read from the socket will "
7099 "block until B<SO_RCVLOWAT> bytes are available."
7103 #: build/C/man7/socket.7:601
7105 msgid "B<SO_RCVTIMEO> and B<SO_SNDTIMEO>"
7108 #. Not implemented in 2.0.
7109 #. Implemented in 2.1.11 for getsockopt: always return a zero struct.
7110 #. Implemented in 2.3.41 for setsockopt, and actually used.
7111 #. in fact to EAGAIN
7113 #: build/C/man7/socket.7:636
7115 "Specify the receiving or sending timeouts until reporting an error. The "
7116 "argument is a I<struct timeval>. If an input or output function blocks for "
7117 "this period of time, and data has been sent or received, the return value of "
7118 "that function will be the amount of data transferred; if no data has been "
7119 "transferred and the timeout has been reached then -1 is returned with "
7120 "I<errno> set to B<EAGAIN> or B<EWOULDBLOCK>, or B<EINPROGRESS> (for "
7121 "B<connect>(2)) just as if the socket was specified to be nonblocking. If "
7122 "the timeout is set to zero (the default) then the operation will never "
7123 "timeout. Timeouts only have effect for system calls that perform socket I/O "
7124 "(e.g., B<read>(2), B<recvmsg>(2), B<send>(2), B<sendmsg>(2)); timeouts have "
7125 "no effect for B<select>(2), B<poll>(2), B<epoll_wait>(2), and so on."
7129 #: build/C/man7/socket.7:636
7131 msgid "B<SO_REUSEADDR>"
7135 #: build/C/man7/socket.7:651
7137 "Indicates that the rules used in validating addresses supplied in a "
7138 "B<bind>(2) call should allow reuse of local addresses. For B<AF_INET> "
7139 "sockets this means that a socket may bind, except when there is an active "
7140 "listening socket bound to the address. When the listening socket is bound "
7141 "to B<INADDR_ANY> with a specific port then it is not possible to bind to "
7142 "this port for any local address. Argument is an integer boolean flag."
7146 #: build/C/man7/socket.7:651
7148 msgid "B<SO_SNDBUF>"
7151 #. Most (all?) other implementations do not do this -- MTK, Dec 05
7152 #. See also the comment to SO_RCVBUF (17 Jul 2012 LKML mail)
7154 #: build/C/man7/socket.7:667
7156 "Sets or gets the maximum socket send buffer in bytes. The kernel doubles "
7157 "this value (to allow space for bookkeeping overhead) when it is set using "
7158 "B<setsockopt>(2), and this doubled value is returned by B<getsockopt>(2). "
7159 "The default value is set by the I</proc/sys/net/core/wmem_default> file and "
7160 "the maximum allowed value is set by the I</proc/sys/net/core/wmem_max> "
7161 "file. The minimum (doubled) value for this option is 2048."
7165 #: build/C/man7/socket.7:667
7167 msgid "B<SO_SNDBUFFORCE> (since Linux 2.6.14)"
7171 #: build/C/man7/socket.7:676
7173 "Using this socket option, a privileged (B<CAP_NET_ADMIN>) process can "
7174 "perform the same task as B<SO_SNDBUF>, but the I<wmem_max> limit can be "
7179 #: build/C/man7/socket.7:676
7181 msgid "B<SO_TIMESTAMP>"
7185 #: build/C/man7/socket.7:692
7187 "Enable or disable the receiving of the B<SO_TIMESTAMP> control message. The "
7188 "timestamp control message is sent with level B<SOL_SOCKET> and the "
7189 "I<cmsg_data> field is a I<struct timeval> indicating the reception time of "
7190 "the last packet passed to the user in this call. See B<cmsg>(3) for "
7191 "details on control messages."
7195 #: build/C/man7/socket.7:692
7201 #: build/C/man7/socket.7:697
7203 "Gets the socket type as an integer (e.g., B<SOCK_STREAM>). This socket "
7204 "option is read-only."
7208 #: build/C/man7/socket.7:697
7214 #: build/C/man7/socket.7:708
7216 "When writing onto a connection-oriented socket that has been shut down (by "
7217 "the local or the remote end) B<SIGPIPE> is sent to the writing process and "
7218 "B<EPIPE> is returned. The signal is not sent when the write call specified "
7219 "the B<MSG_NOSIGNAL> flag."
7223 #: build/C/man7/socket.7:733
7225 "When requested with the B<FIOSETOWN> B<fcntl>(2) or B<SIOCSPGRP> "
7226 "B<ioctl>(2), B<SIGIO> is sent when an I/O event occurs. It is possible to "
7227 "use B<poll>(2) or B<select>(2) in the signal handler to find out which "
7228 "socket the event occurred on. An alternative (in Linux 2.2) is to set a "
7229 "real-time signal using the B<F_SETSIG> B<fcntl>(2); the handler of the real "
7230 "time signal will be called with the file descriptor in the I<si_fd> field of "
7231 "its I<siginfo_t>. See B<fcntl>(2) for more information."
7234 #. .SS Ancillary messages
7236 #: build/C/man7/socket.7:741
7238 "Under some circumstances (e.g., multiple processes accessing a single "
7239 "socket), the condition that caused the B<SIGIO> may have already disappeared "
7240 "when the process reacts to the signal. If this happens, the process should "
7241 "wait again because Linux will resend the signal later."
7245 #: build/C/man7/socket.7:741
7247 msgid "/proc interfaces"
7251 #: build/C/man7/socket.7:745
7253 "The core socket networking parameters can be accessed via files in the "
7254 "directory I</proc/sys/net/core/>."
7258 #: build/C/man7/socket.7:745
7260 msgid "I<rmem_default>"
7264 #: build/C/man7/socket.7:748
7265 msgid "contains the default setting in bytes of the socket receive buffer."
7269 #: build/C/man7/socket.7:748
7275 #: build/C/man7/socket.7:754
7277 "contains the maximum socket receive buffer size in bytes which a user may "
7278 "set by using the B<SO_RCVBUF> socket option."
7282 #: build/C/man7/socket.7:754
7284 msgid "I<wmem_default>"
7288 #: build/C/man7/socket.7:757
7289 msgid "contains the default setting in bytes of the socket send buffer."
7293 #: build/C/man7/socket.7:757
7299 #: build/C/man7/socket.7:763
7301 "contains the maximum socket send buffer size in bytes which a user may set "
7302 "by using the B<SO_SNDBUF> socket option."
7306 #: build/C/man7/socket.7:763
7308 msgid "I<message_cost> and I<message_burst>"
7312 #: build/C/man7/socket.7:767
7314 "configure the token bucket filter used to load limit warning messages caused "
7315 "by external network events."
7319 #: build/C/man7/socket.7:767
7321 msgid "I<netdev_max_backlog>"
7325 #: build/C/man7/socket.7:770
7326 msgid "Maximum number of packets in the global input queue."
7330 #: build/C/man7/socket.7:770
7332 msgid "I<optmem_max>"
7335 #. netdev_fastroute is not documented because it is experimental
7337 #: build/C/man7/socket.7:775
7339 "Maximum length of ancillary data and user control data like the iovecs per "
7344 #: build/C/man7/socket.7:775
7350 #: build/C/man7/socket.7:778
7351 msgid "These operations can be accessed using B<ioctl>(2):"
7355 #: build/C/man7/socket.7:782
7358 "I<error>B< = ioctl(>I<ip_socket>B<, >I<ioctl_type>B<, "
7359 ">I<&value_result>B<);>\n"
7363 #: build/C/man7/socket.7:784
7365 msgid "B<SIOCGSTAMP>"
7369 #: build/C/man7/socket.7:808
7371 "Return a I<struct timeval> with the receive timestamp of the last packet "
7372 "passed to the user. This is useful for accurate round trip time "
7373 "measurements. See B<setitimer>(2) for a description of I<struct timeval>. "
7374 "This ioctl should be used only if the socket option B<SO_TIMESTAMP> is not "
7375 "set on the socket. Otherwise, it returns the timestamp of the last packet "
7376 "that was received while B<SO_TIMESTAMP> was not set, or it fails if no such "
7377 "packet has been received, (i.e., B<ioctl>(2) returns -1 with I<errno> set "
7382 #: build/C/man7/socket.7:808
7384 msgid "B<SIOCSPGRP>"
7388 #: build/C/man7/socket.7:827
7390 "Set the process or process group to send B<SIGIO> or B<SIGURG> signals to "
7391 "when an asynchronous I/O operation has finished or urgent data is "
7392 "available. The argument is a pointer to a I<pid_t>. If the argument is "
7393 "positive, send the signals to that process. If the argument is negative, "
7394 "send the signals to the process group with the ID of the absolute value of "
7395 "the argument. The process may only choose itself or its own process group "
7396 "to receive signals unless it has the B<CAP_KILL> capability or an effective "
7401 #: build/C/man7/socket.7:827
7407 #: build/C/man7/socket.7:837
7409 "Change the B<O_ASYNC> flag to enable or disable asynchronous I/O mode of the "
7410 "socket. Asynchronous I/O mode means that the B<SIGIO> signal or the signal "
7411 "set with B<F_SETSIG> is raised when a new I/O event occurs."
7415 #: build/C/man7/socket.7:845
7417 "Argument is an integer boolean flag. (This operation is synonymous with the "
7418 "use of B<fcntl>(2) to set the B<O_ASYNC> flag.)"
7422 #: build/C/man7/socket.7:845
7424 msgid "B<SIOCGPGRP>"
7428 #: build/C/man7/socket.7:854
7430 "Get the current process or process group that receives B<SIGIO> or B<SIGURG> "
7431 "signals, or 0 when none is set."
7435 #: build/C/man7/socket.7:858
7436 msgid "Valid B<fcntl>(2) operations:"
7440 #: build/C/man7/socket.7:858
7442 msgid "B<FIOGETOWN>"
7446 #: build/C/man7/socket.7:863
7447 msgid "The same as the B<SIOCGPGRP> B<ioctl>(2)."
7451 #: build/C/man7/socket.7:863
7453 msgid "B<FIOSETOWN>"
7457 #: build/C/man7/socket.7:868
7458 msgid "The same as the B<SIOCSPGRP> B<ioctl>(2)."
7462 #: build/C/man7/socket.7:882
7464 "B<SO_BINDTODEVICE> was introduced in Linux 2.0.30. B<SO_PASSCRED> is new in "
7465 "Linux 2.2. The I</proc> interfaces was introduced in Linux 2.2. "
7466 "B<SO_RCVTIMEO> and B<SO_SNDTIMEO> are supported since Linux 2.3.41. "
7467 "Earlier, timeouts were fixed to a protocol-specific setting, and could not "
7468 "be read or written."
7472 #: build/C/man7/socket.7:887
7474 "Linux assumes that half of the send/receive buffer is used for internal "
7475 "kernel structures; thus the values in the corresponding I</proc> files are "
7476 "twice what can be observed on the wire."
7480 #: build/C/man7/socket.7:900
7482 "Linux will only allow port reuse with the B<SO_REUSEADDR> option when this "
7483 "option was set both in the previous program that performed a B<bind>(2) to "
7484 "the port and in the program that wants to reuse the port. This differs from "
7485 "some implementations (e.g., FreeBSD) where only the later program needs to "
7486 "set the B<SO_REUSEADDR> option. Typically this difference is invisible, "
7487 "since, for example, a server program is designed to always set this option."
7490 #. FIXME Document SO_ATTACH_FILTER and SO_DETACH_FILTER
7492 #. This man page was written by Andi Kleen.
7494 #: build/C/man7/socket.7:913
7496 "The B<CONFIG_FILTER> socket options B<SO_ATTACH_FILTER> and "
7497 "B<SO_DETACH_FILTER> are not documented. The suggested interface to use them "
7498 "is via the libpcap library."
7502 #: build/C/man7/socket.7:925
7504 "B<getsockopt>(2), B<connect>(2), B<setsockopt>(2), B<socket>(2), "
7505 "B<capabilities>(7), B<ddp>(7), B<ip>(7), B<packet>(7), B<tcp>(7), B<udp>(7), "
7510 #: build/C/man2/socketcall.2:25
7516 #: build/C/man2/socketcall.2:25
7522 #: build/C/man2/socketcall.2:28
7523 msgid "socketcall - socket system calls"
7527 #: build/C/man2/socketcall.2:30
7528 msgid "B<int socketcall(int >I<call>B<, unsigned long *>I<args>B<);>"
7532 #: build/C/man2/socketcall.2:38
7534 "B<socketcall>() is a common kernel entry point for the socket system "
7535 "calls. I<call> determines which socket function to invoke. I<args> points "
7536 "to a block containing the actual arguments, which are passed through to the "
7541 #: build/C/man2/socketcall.2:42
7543 "User programs should call the appropriate functions by their usual names. "
7544 "Only standard library implementors and kernel hackers need to know about "
7549 #: build/C/man2/socketcall.2:45
7551 "This call is specific to Linux, and should not be used in programs intended "
7556 #: build/C/man2/socketcall.2:53
7558 "On a some architectures\\(emfor example, x86-64 and ARM\\(emthere is no "
7559 "B<socketcall>() system call; instead B<socket>(2), B<accept>(2), "
7560 "B<bind>(2), and so on really are implemented as separate system calls."
7564 #: build/C/man2/socketcall.2:71
7566 "B<accept>(2), B<bind>(2), B<connect>(2), B<getpeername>(2), "
7567 "B<getsockname>(2), B<getsockopt>(2), B<listen>(2), B<recv>(2), "
7568 "B<recvfrom>(2), B<recvmsg>(2), B<send>(2), B<sendmsg>(2), B<sendto>(2), "
7569 "B<setsockopt>(2), B<shutdown>(2), B<socket>(2), B<socketpair>(2)"
7573 #: build/C/man2/socketpair.2:42
7579 #: build/C/man2/socketpair.2:42
7585 #: build/C/man2/socketpair.2:45
7586 msgid "socketpair - create a pair of connected sockets"
7590 #: build/C/man2/socketpair.2:52
7592 "B<int socketpair(int >I<domain>B<, int >I<type>B<, int >I<protocol>B<, int "
7597 #: build/C/man2/socketpair.2:63
7599 "The B<socketpair>() call creates an unnamed pair of connected sockets in "
7600 "the specified I<domain>, of the specified I<type>, and using the optionally "
7601 "specified I<protocol>. For further details of these arguments, see "
7606 #: build/C/man2/socketpair.2:69
7608 "The descriptors used in referencing the new sockets are returned in I<sv>[0] "
7609 "and I<sv>[1]. The two sockets are indistinguishable."
7613 #: build/C/man2/socketpair.2:78
7614 msgid "The specified address family is not supported on this machine."
7618 #: build/C/man2/socketpair.2:83
7620 "The address I<sv> does not specify a valid part of the process address "
7625 #: build/C/man2/socketpair.2:86
7626 msgid "Too many descriptors are in use by this process."
7630 #: build/C/man2/socketpair.2:92
7631 msgid "The specified protocol does not support creation of socket pairs."
7635 #: build/C/man2/socketpair.2:95
7636 msgid "The specified protocol is not supported on this machine."
7640 #: build/C/man2/socketpair.2:103
7642 "4.4BSD, POSIX.1-2001. The B<socketpair>() function call appeared in "
7643 "4.2BSD. It is generally portable to/from non-BSD systems supporting clones "
7644 "of the BSD socket layer (including System V variants)."
7648 #: build/C/man2/socketpair.2:109
7650 "On Linux, the only supported domain for this call is B<AF_UNIX> (or "
7651 "synonymously, B<AF_LOCAL>). (Most implementations have the same "
7656 #: build/C/man2/socketpair.2:118
7658 "Since Linux 2.6.27, B<socketpair>() supports the B<SOCK_NONBLOCK> and "
7659 "B<SOCK_CLOEXEC> flags described in B<socket>(2)."
7663 #: build/C/man2/socketpair.2:131
7664 msgid "B<pipe>(2), B<read>(2), B<socket>(2), B<write>(2), B<socket>(7), B<unix>(7)"