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-03-22 01: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:48 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:48 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:49 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:51 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:55 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:393 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:56 build/C/man2/socket.2:319 build/C/man2/socketpair.2:74
250 #: build/C/man2/accept.2:215 build/C/man2/recv.2:398 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:407 build/C/man2/select.2:307 build/C/man2/send.2:304 build/C/man3/sockatmark.3:57
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:416 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:420 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:425 build/C/man2/recvmmsg.2:161 build/C/man2/select.2:316 build/C/man2/send.2:320 build/C/man3/sockatmark.3:61 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:440 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:68 build/C/man7/socket.7:802
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:92 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:445 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:71 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:95 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:455 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:73 build/C/man2/socket.2:366 build/C/man7/socket.7:816 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:490 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:97 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:101 build/C/man2/connect.2:263 build/C/man3/getifaddrs.3:290 build/C/man2/getsockname.2:112 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:495 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:132 build/C/man2/socket.2:390 build/C/man7/socket.7:847 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:104 build/C/man2/connect.2:270 build/C/man3/getifaddrs.3:296 build/C/man2/getsockname.2:119 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:506 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:137 build/C/man2/socket.2:419 build/C/man7/socket.7:859 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:111 build/C/man2/connect.2:277 build/C/man3/getifaddrs.3:303 build/C/man2/getsockname.2:126 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:513 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:144 build/C/man2/socket.2:426 build/C/man7/socket.7:866 build/C/man2/socketcall.2:78 build/C/man2/socketpair.2:138
567 "This page is part of release 3.50 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:429 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 file system."
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:93 build/C/man7/socket.7:834
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/man2/connect.2:67 build/C/man2/getsockname.2:40 build/C/man2/getsockopt.2:44 build/C/man3/sockatmark.3:25
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:95
1061 msgid "Not in POSIX.1-2001. Present on the BSDs, Solaris, and many other systems."
1065 #: build/C/man3/bindresvport.3:101
1067 "Unlike some B<bindresvport>() implementations, the glibc implementation "
1068 "ignores any value that the caller supplies in I<sin-E<gt>sin_port>."
1072 #: build/C/man3/bindresvport.3:104
1073 msgid "B<bind>(2), B<getsockname>(2)"
1077 #: build/C/man2/connect.2:67
1083 #: build/C/man2/connect.2:70
1084 msgid "connect - initiate a connection on a socket"
1088 #: build/C/man2/connect.2:73 build/C/man2/getsockopt.2:50 build/C/man2/listen.2:51
1090 msgid "B<#include E<lt>sys/types.hE<gt>> /* See NOTES */\n"
1094 #: 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
1096 msgid "B<#include E<lt>sys/socket.hE<gt>>\n"
1100 #: build/C/man2/connect.2:78
1103 "B<int connect(int >I<sockfd>B<, const struct sockaddr *>I<addr>B<,>\n"
1104 "B< socklen_t >I<addrlen>B<);>\n"
1108 #: build/C/man2/connect.2:97
1110 "The B<connect>() system call connects the socket referred to by the file "
1111 "descriptor I<sockfd> to the address specified by I<addr>. The I<addrlen> "
1112 "argument specifies the size of I<addr>. The format of the address in "
1113 "I<addr> is determined by the address space of the socket I<sockfd>; see "
1114 "B<socket>(2) for further details."
1118 #: build/C/man2/connect.2:113
1120 "If the socket I<sockfd> is of type B<SOCK_DGRAM> then I<addr> is the address "
1121 "to which datagrams are sent by default, and the only address from which "
1122 "datagrams are received. If the socket is of type B<SOCK_STREAM> or "
1123 "B<SOCK_SEQPACKET>, this call attempts to make a connection to the socket "
1124 "that is bound to the address specified by I<addr>."
1128 #: build/C/man2/connect.2:127
1130 "Generally, connection-based protocol sockets may successfully B<connect>() "
1131 "only once; connectionless protocol sockets may use B<connect>() multiple "
1132 "times to change their association. Connectionless sockets may dissolve the "
1133 "association by connecting to an address with the I<sa_family> member of "
1134 "I<sockaddr> set to B<AF_UNSPEC> (supported on Linux since kernel 2.2)."
1138 #: build/C/man2/connect.2:132
1140 "If the connection or binding succeeds, zero is returned. On error, -1 is "
1141 "returned, and I<errno> is set appropriately."
1145 #: build/C/man2/connect.2:135
1147 "The following are general socket errors only. There may be other "
1148 "domain-specific error codes."
1152 #: build/C/man2/connect.2:143
1154 "For UNIX domain sockets, which are identified by pathname: Write permission "
1155 "is denied on the socket file, or search permission is denied for one of the "
1156 "directories in the path prefix. (See also B<path_resolution>(7).)"
1160 #: build/C/man2/connect.2:143
1162 msgid "B<EACCES>, B<EPERM>"
1166 #: build/C/man2/connect.2:148
1168 "The user tried to connect to a broadcast address without having the socket "
1169 "broadcast flag enabled or the connection request failed because of a local "
1174 #: build/C/man2/connect.2:151
1175 msgid "Local address is already in use."
1179 #: build/C/man2/connect.2:151 build/C/man2/socket.2:324 build/C/man2/socketpair.2:75
1181 msgid "B<EAFNOSUPPORT>"
1185 #: build/C/man2/connect.2:156
1187 "The passed address didn't have the correct address family in its "
1188 "I<sa_family> field."
1192 #: build/C/man2/connect.2:156
1198 #: build/C/man2/connect.2:165
1200 "No more free local ports or insufficient entries in the routing cache. For "
1201 "B<AF_INET> see the description of I</proc/sys/net/ipv4/ip_local_port_range> "
1202 "B<ip>(7) for information on how to increase the number of local ports."
1206 #: build/C/man2/connect.2:165
1212 #: build/C/man2/connect.2:169
1214 "The socket is nonblocking and a previous connection attempt has not yet been "
1219 #: build/C/man2/connect.2:172
1220 msgid "The file descriptor is not a valid index in the descriptor table."
1224 #: build/C/man2/connect.2:172 build/C/man2/recv.2:412
1226 msgid "B<ECONNREFUSED>"
1230 #: build/C/man2/connect.2:175
1231 msgid "No-one listening on the remote address."
1235 #: build/C/man2/connect.2:178
1236 msgid "The socket structure address is outside the user's address space."
1240 #: build/C/man2/connect.2:178
1242 msgid "B<EINPROGRESS>"
1246 #: build/C/man2/connect.2:203
1248 "The socket is nonblocking and the connection cannot be completed "
1249 "immediately. It is possible to B<select>(2) or B<poll>(2) for completion "
1250 "by selecting the socket for writing. After B<select>(2) indicates "
1251 "writability, use B<getsockopt>(2) to read the B<SO_ERROR> option at level "
1252 "B<SOL_SOCKET> to determine whether B<connect>() completed successfully "
1253 "(B<SO_ERROR> is zero) or unsuccessfully (B<SO_ERROR> is one of the usual "
1254 "error codes listed here, explaining the reason for the failure)."
1257 #. For TCP, the connection will complete asynchronously.
1258 #. See http://lkml.org/lkml/2005/7/12/254
1260 #: build/C/man2/connect.2:209
1262 "The system call was interrupted by a signal that was caught; see "
1267 #: build/C/man2/connect.2:209 build/C/man2/send.2:323
1273 #: build/C/man2/connect.2:212
1274 msgid "The socket is already connected."
1278 #: build/C/man2/connect.2:212
1280 msgid "B<ENETUNREACH>"
1284 #: build/C/man2/connect.2:215
1285 msgid "Network is unreachable."
1289 #: build/C/man2/connect.2:218
1290 msgid "The file descriptor is not associated with a socket."
1294 #: build/C/man2/connect.2:218
1296 msgid "B<ETIMEDOUT>"
1300 #: build/C/man2/connect.2:225
1302 "Timeout while attempting connection. The server may be too busy to accept "
1303 "new connections. Note that for IP sockets the timeout may be very long when "
1304 "syncookies are enabled on the server."
1307 #. SVr4 documents the additional
1308 #. general error codes
1309 #. .BR EADDRNOTAVAIL ,
1311 #. .BR EAFNOSUPPORT ,
1318 #. documents many additional error conditions not described here.
1320 #: build/C/man2/connect.2:241
1322 "SVr4, 4.4BSD, (the B<connect>() function first appeared in 4.2BSD), "
1327 #: build/C/man2/connect.2:258
1329 "The third argument of B<connect>() is in reality an I<int> (and this is "
1330 "what 4.x BSD and libc4 and libc5 have). Some POSIX confusion resulted in "
1331 "the present I<socklen_t>, also used by glibc. See also B<accept>(2)."
1335 #: build/C/man2/connect.2:263
1336 msgid "An example of the use of B<connect>() is shown in B<getaddrinfo>(3)."
1340 #: build/C/man2/connect.2:270
1342 "B<accept>(2), B<bind>(2), B<getsockname>(2), B<listen>(2), B<socket>(2), "
1343 "B<path_resolution>(7)"
1347 #: build/C/man3/getifaddrs.3:36
1353 #: build/C/man3/getifaddrs.3:36
1359 #: build/C/man3/getifaddrs.3:36 build/C/man3/if_nameindex.3:26 build/C/man3/if_nametoindex.3:25
1365 #: build/C/man3/getifaddrs.3:39
1366 msgid "getifaddrs, freeifaddrs - get interface addresses"
1370 #: build/C/man3/getifaddrs.3:43
1373 "B<#include E<lt>sys/types.hE<gt>>\n"
1374 "B<#include E<lt>ifaddrs.hE<gt>>\n"
1378 #: build/C/man3/getifaddrs.3:45
1380 msgid "B<int getifaddrs(struct ifaddrs **>I<ifap>B<);>\n"
1384 #: build/C/man3/getifaddrs.3:47
1386 msgid "B<void freeifaddrs(struct ifaddrs *>I<ifa>B<);>\n"
1390 #: build/C/man3/getifaddrs.3:58
1392 "The B<getifaddrs>() function creates a linked list of structures describing "
1393 "the network interfaces of the local system, and stores the address of the "
1394 "first item of the list in I<*ifap>. The list consists of I<ifaddrs> "
1395 "structures, defined as follows:"
1399 #: build/C/man3/getifaddrs.3:77
1402 "struct ifaddrs {\n"
1403 " struct ifaddrs *ifa_next; /* Next item in list */\n"
1404 " char *ifa_name; /* Name of interface */\n"
1405 " unsigned int ifa_flags; /* Flags from SIOCGIFFLAGS */\n"
1406 " struct sockaddr *ifa_addr; /* Address of interface */\n"
1407 " struct sockaddr *ifa_netmask; /* Netmask of interface */\n"
1409 " struct sockaddr *ifu_broadaddr;\n"
1410 " /* Broadcast address of interface */\n"
1411 " struct sockaddr *ifu_dstaddr;\n"
1412 " /* Point-to-point destination address */\n"
1414 "#define ifa_broadaddr ifa_ifu.ifu_broadaddr\n"
1415 "#define ifa_dstaddr ifa_ifu.ifu_dstaddr\n"
1416 " void *ifa_data; /* Address-specific data */\n"
1421 #: build/C/man3/getifaddrs.3:84
1423 "The I<ifa_next> field contains a pointer to the next structure on the list, "
1424 "or NULL if this is the last item of the list."
1429 #. indicates the maximum length of this field.
1431 #: build/C/man3/getifaddrs.3:91
1432 msgid "The I<ifa_name> points to the null-terminated interface name."
1436 #: build/C/man3/getifaddrs.3:100
1438 "The I<ifa_flags> field contains the interface flags, as returned by the "
1439 "B<SIOCGIFFLAGS> B<ioctl>(2) operation (see B<netdevice>(7) for a list of "
1444 #: build/C/man3/getifaddrs.3:109
1446 "The I<ifa_addr> field points to a structure containing the interface "
1447 "address. (The I<sa_family> subfield should be consulted to determine the "
1448 "format of the address structure.) This field may contain a NULL pointer."
1452 #: build/C/man3/getifaddrs.3:116
1454 "The I<ifa_netmask> field points to a structure containing the netmask "
1455 "associated with I<ifa_addr>, if applicable for the address family. This "
1456 "field may contain a NULL pointer."
1460 #: build/C/man3/getifaddrs.3:131
1462 "Depending on whether the bit B<IFF_BROADCAST> or B<IFF_POINTOPOINT> is set "
1463 "in I<ifa_flags> (only one can be set at a time), either I<ifa_broadaddr> "
1464 "will contain the broadcast address associated with I<ifa_addr> (if "
1465 "applicable for the address family) or I<ifa_dstaddr> will contain the "
1466 "destination address of the point-to-point interface."
1470 #: build/C/man3/getifaddrs.3:136
1472 "The I<ifa_data> field points to a buffer containing address-family-specific "
1473 "data; this field may be NULL if there is no such data for this interface."
1477 #: build/C/man3/getifaddrs.3:142
1479 "The data returned by B<getifaddrs>() is dynamically allocated and should be "
1480 "freed using B<freeifaddrs>() when no longer needed."
1484 #: build/C/man3/getifaddrs.3:149
1486 "On success, B<getifaddrs>() returns zero; on error, -1 is returned, and "
1487 "I<errno> is set appropriately."
1491 #: build/C/man3/getifaddrs.3:162
1493 "B<getifaddrs>() may fail and set I<errno> for any of the errors specified "
1494 "for B<socket>(2), B<bind>(2), B<getsockname>(2), B<recvmsg>(2), "
1495 "B<sendto>(2), B<malloc>(3), or B<realloc>(3)."
1499 #: build/C/man3/getifaddrs.3:170
1501 "The B<getifaddrs>() function first appeared in glibc 2.3, but before glibc "
1502 "2.3.3, the implementation only supported IPv4 addresses; IPv6 support was "
1503 "added in glibc 2.3.3. Support of address families other than IPv4 is only "
1504 "available on kernels that support netlink."
1507 #. , but the BSD-derived documentation generally
1508 #. appears to be confused and obsolete on this point.
1509 #. i.e., commonly it still says one of them will be NULL, even if
1510 #. the ifa_ifu union is already present
1512 #: build/C/man3/getifaddrs.3:190
1514 "Not in POSIX.1-2001. This function first appeared in BSDi and is present on "
1515 "the BSD systems, but with slightly different semantics "
1516 "documented\\(emreturning one entry per interface, not per address. This "
1517 "means I<ifa_addr> and other fields can actually be NULL if the interface has "
1518 "no address, and no link-level address is returned if the interface has an IP "
1519 "address assigned. Also, the way of choosing either I<ifa_broadaddr> or "
1520 "I<ifa_dstaddr> differs on various systems."
1524 #: build/C/man3/getifaddrs.3:207
1526 "The addresses returned on Linux will usually be the IPv4 and IPv6 addresses "
1527 "assigned to the interface, but also one B<AF_PACKET> address per interface "
1528 "containing lower-level details about the interface and its physical layer. "
1529 "In this case, the I<ifa_data> field may contain a pointer to a I<struct "
1530 "rtnl_link_stats>, defined in I<E<lt>linux/if_link.hE<gt>> (in Linux 2.4 and "
1531 "earlier, I<struct net_device_stats>, defined in "
1532 "I<E<lt>linux/netdevice.hE<gt>>), which contains various interface attributes "
1537 #: build/C/man3/getifaddrs.3:214
1539 "The program below demonstrates the use of B<getifaddrs>(), B<freeifaddrs>(), "
1540 "and B<getnameinfo>(3). Here is what we see when running this program on one "
1545 #: build/C/man3/getifaddrs.3:228
1549 "lo address family: 17 (AF_PACKET)\n"
1550 "eth0 address family: 17 (AF_PACKET)\n"
1551 "lo address family: 2 (AF_INET)\n"
1552 " address: E<lt>127.0.0.1E<gt>\n"
1553 "eth0 address family: 2 (AF_INET)\n"
1554 " address: E<lt>10.1.1.4E<gt>\n"
1555 "lo address family: 10 (AF_INET6)\n"
1556 " address: E<lt>::1E<gt>\n"
1557 "eth0 address family: 10 (AF_INET6)\n"
1558 " address: E<lt>fe80::2d0:59ff:feda:eb51%eth0E<gt>\n"
1562 #: build/C/man3/getifaddrs.3:230 build/C/man3/if_nameindex.3:120 build/C/man2/recvmmsg.2:206
1564 msgid "Program source"
1568 #: build/C/man3/getifaddrs.3:240
1571 "#include E<lt>arpa/inet.hE<gt>\n"
1572 "#include E<lt>sys/socket.hE<gt>\n"
1573 "#include E<lt>netdb.hE<gt>\n"
1574 "#include E<lt>ifaddrs.hE<gt>\n"
1575 "#include E<lt>stdio.hE<gt>\n"
1576 "#include E<lt>stdlib.hE<gt>\n"
1577 "#include E<lt>unistd.hE<gt>\n"
1581 #: build/C/man3/getifaddrs.3:247
1585 "main(int argc, char *argv[])\n"
1587 " struct ifaddrs *ifaddr, *ifa;\n"
1589 " char host[NI_MAXHOST];\n"
1593 #: build/C/man3/getifaddrs.3:252
1596 " if (getifaddrs(&ifaddr) == -1) {\n"
1597 " perror(\"getifaddrs\");\n"
1598 " exit(EXIT_FAILURE);\n"
1603 #: build/C/man3/getifaddrs.3:255
1606 " /* Walk through linked list, maintaining head pointer so we\n"
1607 " can free list later */\n"
1611 #: build/C/man3/getifaddrs.3:259
1614 " for (ifa = ifaddr; ifa != NULL; ifa = ifa-E<gt>ifa_next) {\n"
1615 " if (ifa-E<gt>ifa_addr == NULL)\n"
1620 #: build/C/man3/getifaddrs.3:261
1622 msgid " family = ifa-E<gt>ifa_addr-E<gt>sa_family;\n"
1626 #: build/C/man3/getifaddrs.3:264
1629 " /* Display interface name and family (including symbolic\n"
1630 " form of the latter for the common families) */\n"
1634 #: build/C/man3/getifaddrs.3:270
1637 " printf(\"%s\\t address family: %d%s\\en\",\n"
1638 " ifa-E<gt>ifa_name, family,\n"
1639 " (family == AF_PACKET) ? \" (AF_PACKET)\" :\n"
1640 " (family == AF_INET) ? \" (AF_INET)\" :\n"
1641 " (family == AF_INET6) ? \" (AF_INET6)\" : \"\");\n"
1645 #: build/C/man3/getifaddrs.3:272
1647 msgid " /* For an AF_INET* interface address, display the address */\n"
1651 #: build/C/man3/getifaddrs.3:285
1654 " if (family == AF_INET || family == AF_INET6) {\n"
1655 " s = getnameinfo(ifa-E<gt>ifa_addr,\n"
1656 " (family == AF_INET) ? sizeof(struct sockaddr_in) :\n"
1657 " sizeof(struct sockaddr_in6),\n"
1658 " host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);\n"
1660 " printf(\"getnameinfo() failed: %s\\en\", gai_strerror(s));\n"
1661 " exit(EXIT_FAILURE);\n"
1663 " printf(\"\\etaddress: E<lt>%sE<gt>\\en\", host);\n"
1669 #: build/C/man3/getifaddrs.3:289
1672 " freeifaddrs(ifaddr);\n"
1673 " exit(EXIT_SUCCESS);\n"
1678 #: build/C/man3/getifaddrs.3:296
1679 msgid "B<bind>(2), B<getsockname>(2), B<socket>(2), B<packet>(7), B<ifconfig>(8)"
1683 #: build/C/man2/getsockname.2:40
1689 #: build/C/man2/getsockname.2:43
1690 msgid "getsockname - get socket name"
1694 #: build/C/man2/getsockname.2:49
1697 "B<int getsockname(int >I<sockfd>B<, struct sockaddr *>I<addr>B<, socklen_t "
1698 "*>I<addrlen>B<);>\n"
1702 #: build/C/man2/getsockname.2:62
1704 "B<getsockname>() returns the current address to which the socket I<sockfd> "
1705 "is bound, in the buffer pointed to by I<addr>. The I<addrlen> argument "
1706 "should be initialized to indicate the amount of space (in bytes) pointed to "
1707 "by I<addr>. On return it contains the actual size of the socket address."
1711 #: build/C/man2/getsockname.2:78 build/C/man2/getsockopt.2:142 build/C/man2/listen.2:96
1712 msgid "The argument I<sockfd> is not a valid descriptor."
1716 #: build/C/man2/getsockname.2:84
1718 "The I<addr> argument points to memory not in a valid part of the process "
1723 #: build/C/man2/getsockname.2:88
1724 msgid "I<addrlen> is invalid (e.g., is negative)."
1728 #: build/C/man2/getsockname.2:88 build/C/man3/if_nameindex.3:83 build/C/man2/send.2:335
1734 #: build/C/man2/getsockname.2:92
1736 "Insufficient resources were available in the system to perform the "
1741 #: build/C/man2/getsockname.2:97 build/C/man2/getsockopt.2:171
1742 msgid "The argument I<sockfd> is a file, not a socket."
1745 #. SVr4 documents additional ENOMEM
1746 #. and ENOSR error codes.
1748 #: build/C/man2/getsockname.2:103
1750 "SVr4, 4.4BSD (the B<getsockname>() function call appeared in 4.2BSD), "
1755 #: build/C/man2/getsockname.2:112
1757 "The third argument of B<getsockname>() is in reality an I<int *> (and this "
1758 "is what 4.x BSD and libc4 and libc5 have). Some POSIX confusion resulted in "
1759 "the present I<socklen_t>, also used by glibc. See also B<accept>(2)."
1763 #: build/C/man2/getsockname.2:119
1765 "B<bind>(2), B<socket>(2), B<getifaddrs>(3), B<ip>(7), B<socket>(7), "
1770 #: build/C/man2/getsockopt.2:44
1776 #: build/C/man2/getsockopt.2:47
1777 msgid "getsockopt, setsockopt - get and set options on sockets"
1781 #: build/C/man2/getsockopt.2:57
1784 "B<int getsockopt(int >I<sockfd>B<, int >I<level>B<, int >I<optname>B<,>\n"
1785 "B< void *>I<optval>B<, socklen_t *>I<optlen>B<);>\n"
1786 "B<int setsockopt(int >I<sockfd>B<, int >I<level>B<, int >I<optname>B<,>\n"
1787 "B< const void *>I<optval>B<, socklen_t >I<optlen>B<);>\n"
1791 #: build/C/man2/getsockopt.2:67
1793 "B<getsockopt>() and B<setsockopt>() manipulate options for the socket "
1794 "referred to by the file descriptor I<sockfd>. Options may exist at multiple "
1795 "protocol levels; they are always present at the uppermost socket level."
1799 #: build/C/man2/getsockopt.2:86
1801 "When manipulating socket options, the level at which the option resides and "
1802 "the name of the option must be specified. To manipulate options at the "
1803 "sockets API level, I<level> is specified as B<SOL_SOCKET>. To manipulate "
1804 "options at any other level the protocol number of the appropriate protocol "
1805 "controlling the option is supplied. For example, to indicate that an option "
1806 "is to be interpreted by the B<TCP> protocol, I<level> should be set to the "
1807 "protocol number of B<TCP>; see B<getprotoent>(3)."
1811 #: build/C/man2/getsockopt.2:108
1813 "The arguments I<optval> and I<optlen> are used to access option values for "
1814 "B<setsockopt>(). For B<getsockopt>() they identify a buffer in which the "
1815 "value for the requested option(s) are to be returned. For B<getsockopt>(), "
1816 "I<optlen> is a value-result argument, initially containing the size of the "
1817 "buffer pointed to by I<optval>, and modified on return to indicate the "
1818 "actual size of the value returned. If no option value is to be supplied or "
1819 "returned, I<optval> may be NULL."
1823 #: build/C/man2/getsockopt.2:118
1825 "I<Optname> and any specified options are passed uninterpreted to the "
1826 "appropriate protocol module for interpretation. The include file "
1827 "I<E<lt>sys/socket.hE<gt>> contains definitions for socket level options, "
1828 "described below. Options at other protocol levels vary in format and name; "
1829 "consult the appropriate entries in section 4 of the manual."
1833 #: build/C/man2/getsockopt.2:127
1835 "Most socket-level options utilize an I<int> argument for I<optval>. For "
1836 "B<setsockopt>(), the argument should be nonzero to enable a boolean option, "
1837 "or zero if the option is to be disabled."
1841 #: build/C/man2/getsockopt.2:131
1843 "For a description of the available socket options see B<socket>(7) and the "
1844 "appropriate protocol man pages."
1848 #: build/C/man2/getsockopt.2:152
1850 "The address pointed to by I<optval> is not in a valid part of the process "
1851 "address space. For B<getsockopt>(), this error may also be returned if "
1852 "I<optlen> is not in a valid part of the process address space."
1856 #: build/C/man2/getsockopt.2:163
1858 "I<optlen> invalid in B<setsockopt>(). In some cases this error can also "
1859 "occur for an invalid value in I<optval> (e.g., for the B<IP_ADD_MEMBERSHIP> "
1860 "option described in B<ip>(7))."
1864 #: build/C/man2/getsockopt.2:163
1866 msgid "B<ENOPROTOOPT>"
1870 #: build/C/man2/getsockopt.2:166
1871 msgid "The option is unknown at the level indicated."
1874 #. SVr4 documents additional ENOMEM and ENOSR error codes, but does
1876 #. .BR SO_SNDLOWAT ", " SO_RCVLOWAT ", " SO_SNDTIMEO ", " SO_RCVTIMEO
1879 #: build/C/man2/getsockopt.2:178
1880 msgid "SVr4, 4.4BSD (these system calls first appeared in 4.2BSD), POSIX.1-2001."
1884 #: build/C/man2/getsockopt.2:199
1886 "The I<optlen> argument of B<getsockopt>() and B<setsockopt>() is in "
1887 "reality an I<int [*]> (and this is what 4.x BSD and libc4 and libc5 have). "
1888 "Some POSIX confusion resulted in the present I<socklen_t>, also used by "
1889 "glibc. See also B<accept>(2)."
1893 #: build/C/man2/getsockopt.2:202
1895 "Several of the socket options should be handled at lower levels of the "
1900 #: build/C/man2/getsockopt.2:210
1902 "B<ioctl>(2), B<socket>(2), B<getprotoent>(3), B<protocols>(5), B<socket>(7), "
1903 "B<tcp>(7), B<unix>(7)"
1907 #: build/C/man3/if_nameindex.3:26
1909 msgid "IF_NAMEINDEX"
1913 #: build/C/man3/if_nameindex.3:26
1919 #: build/C/man3/if_nameindex.3:29
1920 msgid "if_nameindex, if_freenameindex - get network interface names and indexes"
1924 #: build/C/man3/if_nameindex.3:32 build/C/man3/if_nametoindex.3:32
1926 msgid "B<#include E<lt>net/if.hE<gt>>\n"
1930 #: build/C/man3/if_nameindex.3:35
1933 "B<struct if_nameindex *if_nameindex(void);>\n"
1934 "B<void if_freenameindex(struct if_nameindex *>I<ptr>B<);>\n"
1938 #: build/C/man3/if_nameindex.3:46
1940 "The B<if_nameindex>() function returns an array of I<if_nameindex> "
1941 "structures, each containing information about one of the network interfaces "
1942 "on the local system. The I<if_nameindex> structure contains at least the "
1943 "following entries:"
1947 #: build/C/man3/if_nameindex.3:51
1950 " unsigned int if_index; /* Index of interface (1, 2, ...) */\n"
1951 " char *if_name; /* Null-terminated name (\"eth0\", etc.) */\n"
1955 #: build/C/man3/if_nameindex.3:65
1957 "The I<if_index> field contains the interface index. The I<ifa_name> field "
1958 "points to the null-terminated interface name. The end of the array is "
1959 "indicated by entry with I<if_index> set to zero and I<ifa_name> set to NULL."
1963 #: build/C/man3/if_nameindex.3:71
1965 "The data structure returned by B<if_nameindex>() is dynamically allocated "
1966 "and should be freed using B<if_freenameindex>() when no longer needed."
1970 #: build/C/man3/if_nameindex.3:78
1972 "On success, B<if_nameindex>() returns pointer to the array; on error, a "
1973 "NULL pointer is returned, and I<errno> is set appropriately."
1977 #: build/C/man3/if_nameindex.3:83
1978 msgid "B<if_nameindex>() may fail and set I<errno> if:"
1982 #: build/C/man3/if_nameindex.3:86
1983 msgid "Insufficient resources available."
1987 #: build/C/man3/if_nameindex.3:97
1989 "B<if_nameindex>() may also fail for any of the errors specified for "
1990 "B<socket>(2), B<bind>(2), B<ioctl>(2), B<getsockname>(2), B<recvmsg>(2), "
1991 "B<sendto>(2), or B<malloc>(3)."
1995 #: build/C/man3/if_nameindex.3:104
1997 "The B<if_nameindex>() function first appeared in glibc 2.1, but before "
1998 "glibc 2.3.4, the implementation only supported interfaces with IPv4 "
1999 "addresses. Support of interfaces that don't have IPv4 addresses is only "
2000 "available on kernels that support netlink."
2004 #: build/C/man3/if_nameindex.3:106 build/C/man3/if_nametoindex.3:87
2005 msgid "RFC\\ 3493, POSIX.1-2001."
2009 #: build/C/man3/if_nameindex.3:108 build/C/man3/if_nametoindex.3:89
2010 msgid "This function first appeared in BSDi."
2014 #: build/C/man3/if_nameindex.3:112
2016 "The program below demonstrates the use of the functions described on this "
2017 "page. An example of the output this program might produce is the following:"
2021 #: build/C/man3/if_nameindex.3:118
2031 #: build/C/man3/if_nameindex.3:126
2034 "#include E<lt>net/if.hE<gt>\n"
2035 "#include E<lt>stdio.hE<gt>\n"
2036 "#include E<lt>stdlib.hE<gt>\n"
2037 "#include E<lt>unistd.hE<gt>\n"
2041 #: build/C/man3/if_nameindex.3:131
2045 "main(int argc, char *argv[])\n"
2047 " struct if_nameindex *if_ni, *i;\n"
2051 #: build/C/man3/if_nameindex.3:137
2054 " if_ni = if_nameindex();\n"
2055 " if (if_ni == NULL) {\n"
2056 " perror(\"if_nameindex\");\n"
2057 " exit(EXIT_FAILURE);\n"
2062 #: build/C/man3/if_nameindex.3:140
2065 " for (i = if_ni; ! (i-E<gt>if_index == 0 && i-E<gt>if_name == NULL); "
2067 " printf(\"%u: %s\\en\", i-E<gt>if_index, i-E<gt>if_name);\n"
2071 #: build/C/man3/if_nameindex.3:142
2073 msgid " if_freenameindex(if_ni);\n"
2077 #: build/C/man3/if_nameindex.3:145 build/C/man2/select.2:573
2080 " exit(EXIT_SUCCESS);\n"
2085 #: build/C/man3/if_nameindex.3:153
2087 "B<getsockopt>(2), B<setsockopt>(2), B<getifaddrs>(3), B<if_indextoname>(3), "
2088 "B<if_nametoindex>(3), B<ifconfig>(8)"
2092 #: build/C/man3/if_nametoindex.3:25
2094 msgid "IF_NAMETOINDEX"
2098 #: build/C/man3/if_nametoindex.3:25
2104 #: build/C/man3/if_nametoindex.3:29
2106 "if_nametoindex, if_indextoname - mappings between network interface names "
2111 #: build/C/man3/if_nametoindex.3:34
2113 msgid "B<unsigned int if_nametoindex(const char *>I<ifname>B<);>\n"
2117 #: build/C/man3/if_nametoindex.3:36
2119 msgid "B<char *if_indextoname(unsigned int ifindex, char *>I<ifname>B<);>\n"
2123 #: build/C/man3/if_nametoindex.3:43
2125 "The B<if_nametoindex>() function returns the index of the network interface "
2126 "corresponding to the name I<ifname>."
2130 #: build/C/man3/if_nametoindex.3:54
2132 "The B<if_indextoname>() function returns the name of the network interface "
2133 "corresponding to the interface index I<ifindex>. The name is placed in the "
2134 "buffer pointed to by I<ifname>. The buffer must allow for the storage of at "
2135 "least B<IF_NAMESIZE> bytes."
2139 #: build/C/man3/if_nametoindex.3:61
2141 "On success, B<if_nametoindex>() returns the index number of the network "
2142 "interface; on error, 0 is returned and I<errno> is set appropriately."
2146 #: build/C/man3/if_nametoindex.3:69
2148 "On success, B<if_indextoname>() returns I<ifname>; on error, NULL is "
2149 "returned and I<errno> is set appropriately."
2153 #: build/C/man3/if_nametoindex.3:74
2154 msgid "B<if_indextoname>() may fail and set I<errno> if:"
2158 #: build/C/man3/if_nametoindex.3:74
2164 #: build/C/man3/if_nametoindex.3:77
2165 msgid "No interface found for the index."
2169 #: build/C/man3/if_nametoindex.3:85
2171 "B<if_nametoindex>() and B<if_indextoname>() may also fail for any of the "
2172 "errors specified for B<socket>(2) or B<ioctl>(2)."
2176 #: build/C/man3/if_nametoindex.3:93
2177 msgid "B<getifaddrs>(3), B<if_nameindex>(3), B<ifconfig>(8)"
2181 #: build/C/man2/listen.2:45
2187 #: build/C/man2/listen.2:45
2193 #: build/C/man2/listen.2:48
2194 msgid "listen - listen for connections on a socket"
2198 #: build/C/man2/listen.2:55
2200 msgid "B<int listen(int >I<sockfd>B<, int >I<backlog>B<);>\n"
2204 #: build/C/man2/listen.2:63
2206 "B<listen>() marks the socket referred to by I<sockfd> as a passive socket, "
2207 "that is, as a socket that will be used to accept incoming connection "
2208 "requests using B<accept>(2)."
2212 #: build/C/man2/listen.2:70
2214 "The I<sockfd> argument is a file descriptor that refers to a socket of type "
2215 "B<SOCK_STREAM> or B<SOCK_SEQPACKET>."
2219 #: build/C/man2/listen.2:82
2221 "The I<backlog> argument defines the maximum length to which the queue of "
2222 "pending connections for I<sockfd> may grow. If a connection request arrives "
2223 "when the queue is full, the client may receive an error with an indication "
2224 "of B<ECONNREFUSED> or, if the underlying protocol supports retransmission, "
2225 "the request may be ignored so that a later reattempt at connection succeeds."
2229 #: build/C/man2/listen.2:91
2230 msgid "Another socket is already listening on the same port."
2234 #: build/C/man2/listen.2:101 build/C/man2/send.2:354
2235 msgid "The argument I<sockfd> is not a socket."
2239 #: build/C/man2/listen.2:106
2240 msgid "The socket is not of a type that supports the B<listen>() operation."
2244 #: build/C/man2/listen.2:111
2246 "4.4BSD, POSIX.1-2001. The B<listen>() function call first appeared in "
2251 #: build/C/man2/listen.2:113
2252 msgid "To accept connections, the following steps are performed:"
2256 #: build/C/man2/listen.2:114 build/C/man2/select_tut.2:347
2262 #: build/C/man2/listen.2:117
2263 msgid "A socket is created with B<socket>(2)."
2267 #: build/C/man2/listen.2:117 build/C/man2/select_tut.2:356
2273 #: build/C/man2/listen.2:123
2275 "The socket is bound to a local address using B<bind>(2), so that other "
2276 "sockets may be B<connect>(2)ed to it."
2280 #: build/C/man2/listen.2:123 build/C/man2/select_tut.2:360
2286 #: build/C/man2/listen.2:127
2288 "A willingness to accept incoming connections and a queue limit for incoming "
2289 "connections are specified with B<listen>()."
2293 #: build/C/man2/listen.2:127 build/C/man2/select_tut.2:367
2299 #: build/C/man2/listen.2:130
2300 msgid "Connections are accepted with B<accept>(2)."
2304 #: build/C/man2/listen.2:153
2306 "The behavior of the I<backlog> argument on TCP sockets changed with Linux "
2307 "2.2. Now it specifies the queue length for I<completely> established "
2308 "sockets waiting to be accepted, instead of the number of incomplete "
2309 "connection requests. The maximum length of the queue for incomplete sockets "
2310 "can be set using I</proc/sys/net/ipv4/tcp_max_syn_backlog>. When syncookies "
2311 "are enabled there is no logical maximum length and this setting is ignored. "
2312 "See B<tcp>(7) for more information."
2315 #. The following is now rather historic information (MTK, Jun 05)
2316 #. Don't rely on this value in portable applications since BSD
2317 #. (and some BSD-derived systems) limit the backlog to 5.
2319 #: build/C/man2/listen.2:166
2321 "If the I<backlog> argument is greater than the value in "
2322 "I</proc/sys/net/core/somaxconn>, then it is silently truncated to that "
2323 "value; the default value in this file is 128. In kernels before 2.4.25, "
2324 "this limit was a hard coded value, B<SOMAXCONN>, with the value 128."
2328 #: build/C/man2/listen.2:175
2329 msgid "B<accept>(2), B<bind>(2), B<connect>(2), B<socket>(2), B<socket>(7)"
2333 #: build/C/man2/recv.2:41
2339 #: build/C/man2/recv.2:41
2345 #: build/C/man2/recv.2:44
2346 msgid "recv, recvfrom, recvmsg - receive a message from a socket"
2350 #: build/C/man2/recv.2:49 build/C/man2/select.2:53 build/C/man2/select_tut.2:47
2352 msgid "B<#include E<lt>sys/types.hE<gt>>\n"
2356 #: build/C/man2/recv.2:53
2359 "B<ssize_t recv(int >I<sockfd>B<, void *>I<buf>B<, size_t >I<len>B<, int "
2364 #: build/C/man2/recv.2:56
2367 "B<ssize_t recvfrom(int >I<sockfd>B<, void *>I<buf>B<, size_t >I<len>B<, int "
2369 "B< struct sockaddr *>I<src_addr>B<, socklen_t "
2370 "*>I<addrlen>B<);>\n"
2374 #: build/C/man2/recv.2:58
2377 "B<ssize_t recvmsg(int >I<sockfd>B<, struct msghdr *>I<msg>B<, int "
2382 #: build/C/man2/recv.2:66
2384 "The B<recvfrom>() and B<recvmsg>() calls are used to receive messages from "
2385 "a socket, and may be used to receive data on a socket whether or not it is "
2386 "connection-oriented."
2389 #. (Note: for datagram sockets in both the UNIX and Internet domains,
2393 #. is also filled in for stream sockets in the UNIX domain, but is not
2394 #. filled in for stream sockets in the Internet domain.)
2395 #. [The above notes on AF_UNIX and AF_INET sockets apply as at
2396 #. Kernel 2.4.18. (MTK, 22 Jul 02)]
2398 #: build/C/man2/recv.2:95
2400 "If I<src_addr> is not NULL, and the underlying protocol provides the source "
2401 "address, this source address is filled in. When I<src_addr> is NULL, "
2402 "nothing is filled in; in this case, I<addrlen> is not used, and should also "
2403 "be NULL. The argument I<addrlen> is a value-result argument, which the "
2404 "caller should initialize before the call to the size of the buffer "
2405 "associated with I<src_addr>, and modified on return to indicate the actual "
2406 "size of the source address. The returned address is truncated if the buffer "
2407 "provided is too small; in this case, I<addrlen> will return a value greater "
2408 "than was supplied to the call."
2412 #: build/C/man2/recv.2:107
2414 "The B<recv>() call is normally used only on a I<connected> socket (see "
2415 "B<connect>(2)) and is identical to B<recvfrom>() with a NULL I<src_addr> "
2420 #: build/C/man2/recv.2:113
2422 "All three routines return the length of the message on successful "
2423 "completion. If a message is too long to fit in the supplied buffer, excess "
2424 "bytes may be discarded depending on the type of socket the message is "
2429 #: build/C/man2/recv.2:123
2431 "If no messages are available at the socket, the receive calls wait for a "
2432 "message to arrive, unless the socket is nonblocking (see B<fcntl>(2)), in "
2433 "which case the value -1 is returned and the external variable I<errno> is "
2434 "set to B<EAGAIN> or B<EWOULDBLOCK>. The receive calls normally return any "
2435 "data available, up to the requested amount, rather than waiting for receipt "
2436 "of the full amount requested."
2440 #: build/C/man2/recv.2:129
2442 "The B<select>(2) or B<poll>(2) call may be used to determine when more "
2447 #: build/C/man2/recv.2:135
2449 "The I<flags> argument to a B<recv>() call is formed by ORing one or more of "
2450 "the following values:"
2454 #: build/C/man2/recv.2:135
2456 msgid "B<MSG_CMSG_CLOEXEC> (B<recvmsg>() only; since Linux 2.6.23)"
2460 #: build/C/man2/recv.2:146
2462 "Set the close-on-exec flag for the file descriptor received via a UNIX "
2463 "domain file descriptor using the B<SCM_RIGHTS> operation (described in "
2464 "B<unix>(7)). This flag is useful for the same reasons as the B<O_CLOEXEC> "
2465 "flag of B<open>(2)."
2469 #: build/C/man2/recv.2:146 build/C/man2/send.2:188
2471 msgid "B<MSG_DONTWAIT> (since Linux 2.2)"
2475 #: build/C/man2/recv.2:156
2477 "Enables nonblocking operation; if the operation would block, the call fails "
2478 "with the error B<EAGAIN> or B<EWOULDBLOCK> (this can also be enabled using "
2479 "the B<O_NONBLOCK> flag with the B<F_SETFL> B<fcntl>(2))."
2483 #: build/C/man2/recv.2:156
2485 msgid "B<MSG_ERRQUEUE> (since Linux 2.2)"
2489 #: build/C/man2/recv.2:175
2491 "This flag specifies that queued errors should be received from the socket "
2492 "error queue. The error is passed in an ancillary message with a type "
2493 "dependent on the protocol (for IPv4 B<IP_RECVERR>). The user should supply "
2494 "a buffer of sufficient size. See B<cmsg>(3) and B<ip>(7) for more "
2495 "information. The payload of the original packet that caused the error is "
2496 "passed as normal data via I<msg_iovec>. The original destination address of "
2497 "the datagram that caused the error is supplied via I<msg_name>."
2501 #: build/C/man2/recv.2:187 build/C/man2/recv.2:250
2503 "For local errors, no address is passed (this can be checked with the "
2504 "I<cmsg_len> member of the I<cmsghdr>). For error receives, the "
2505 "B<MSG_ERRQUEUE> is set in the I<msghdr>. After an error has been passed, "
2506 "the pending socket error is regenerated based on the next queued error and "
2507 "will be passed on the next socket operation."
2511 #: build/C/man2/recv.2:191
2512 msgid "The error is supplied in a I<sock_extended_err> structure:"
2516 #: build/C/man2/recv.2:198
2519 "#define SO_EE_ORIGIN_NONE 0\n"
2520 "#define SO_EE_ORIGIN_LOCAL 1\n"
2521 "#define SO_EE_ORIGIN_ICMP 2\n"
2522 "#define SO_EE_ORIGIN_ICMP6 3\n"
2526 #: build/C/man2/recv.2:210
2529 "struct sock_extended_err\n"
2531 " uint32_t ee_errno; /* error number */\n"
2532 " uint8_t ee_origin; /* where the error originated */\n"
2533 " uint8_t ee_type; /* type */\n"
2534 " uint8_t ee_code; /* code */\n"
2535 " uint8_t ee_pad; /* padding */\n"
2536 " uint32_t ee_info; /* additional information */\n"
2537 " uint32_t ee_data; /* other data */\n"
2538 " /* More data may follow */\n"
2543 #: build/C/man2/recv.2:212
2545 msgid "struct sockaddr *SO_EE_OFFENDER(struct sock_extended_err *);\n"
2549 #: build/C/man2/recv.2:236
2551 "I<ee_errno> contains the I<errno> number of the queued error. I<ee_origin> "
2552 "is the origin code of where the error originated. The other fields are "
2553 "protocol-specific. The macro B<SOCK_EE_OFFENDER> returns a pointer to the "
2554 "address of the network object where the error originated from given a "
2555 "pointer to the ancillary message. If this address is not known, the "
2556 "I<sa_family> member of the I<sockaddr> contains B<AF_UNSPEC> and the other "
2557 "fields of the I<sockaddr> are undefined. The payload of the packet that "
2558 "caused the error is passed as normal data."
2562 #: build/C/man2/recv.2:250 build/C/man2/recv.2:381 build/C/man2/send.2:230
2568 #: build/C/man2/recv.2:257
2570 "This flag requests receipt of out-of-band data that would not be received in "
2571 "the normal data stream. Some protocols place expedited data at the head of "
2572 "the normal data queue, and thus this flag cannot be used with such "
2577 #: build/C/man2/recv.2:257
2583 #: build/C/man2/recv.2:264
2585 "This flag causes the receive operation to return data from the beginning of "
2586 "the receive queue without removing that data from the queue. Thus, a "
2587 "subsequent receive call will return the same data."
2591 #: build/C/man2/recv.2:264
2593 msgid "B<MSG_TRUNC> (since Linux 2.2)"
2597 #: build/C/man2/recv.2:275
2599 "For raw (B<AF_PACKET>), Internet datagram (since Linux 2.4.27/2.6.8), "
2600 "netlink (since Linux 2.6.22) and UNIX datagram (since Linux 3.4) sockets: "
2601 "return the real length of the packet or datagram, even when it was longer "
2602 "than the passed buffer. Not implemented for UNIX domain (B<unix>(7)) "
2607 #: build/C/man2/recv.2:278
2608 msgid "For use with Internet stream sockets, see B<tcp>(7)."
2612 #: build/C/man2/recv.2:278
2614 msgid "B<MSG_WAITALL> (since Linux 2.2)"
2618 #: build/C/man2/recv.2:285
2620 "This flag requests that the operation block until the full request is "
2621 "satisfied. However, the call may still return less data than requested if a "
2622 "signal is caught, an error or disconnect occurs, or the next data to be "
2623 "received is of a different type than that returned."
2627 #: build/C/man2/recv.2:293
2629 "The B<recvmsg>() call uses a I<msghdr> structure to minimize the number of "
2630 "directly supplied arguments. This structure is defined as follows in "
2631 "I<E<lt>sys/socket.hE<gt>>:"
2635 #: build/C/man2/recv.2:300
2638 "struct iovec { /* Scatter/gather array items */\n"
2639 " void *iov_base; /* Starting address */\n"
2640 " size_t iov_len; /* Number of bytes to transfer */\n"
2645 #: build/C/man2/recv.2:310 build/C/man2/send.2:258
2649 " void *msg_name; /* optional address */\n"
2650 " socklen_t msg_namelen; /* size of address */\n"
2651 " struct iovec *msg_iov; /* scatter/gather array */\n"
2652 " size_t msg_iovlen; /* # elements in msg_iov */\n"
2653 " void *msg_control; /* ancillary data, see below */\n"
2654 " size_t msg_controllen; /* ancillary data buffer len */\n"
2655 " int msg_flags; /* flags on received message */\n"
2660 #: build/C/man2/recv.2:340
2662 "Here I<msg_name> and I<msg_namelen> specify the source address if the socket "
2663 "is unconnected; I<msg_name> may be given as a NULL pointer if no names are "
2664 "desired or required. The fields I<msg_iov> and I<msg_iovlen> describe "
2665 "scatter-gather locations, as discussed in B<readv>(2). The field "
2666 "I<msg_control>, which has length I<msg_controllen>, points to a buffer for "
2667 "other protocol control-related messages or miscellaneous ancillary data. "
2668 "When B<recvmsg>() is called, I<msg_controllen> should contain the length of "
2669 "the available buffer in I<msg_control>; upon return from a successful call "
2670 "it will contain the length of the control message sequence."
2674 #: build/C/man2/recv.2:342
2675 msgid "The messages are of the form:"
2679 #: build/C/man2/recv.2:352
2682 "struct cmsghdr {\n"
2683 " socklen_t cmsg_len; /* data byte count, including hdr */\n"
2684 " int cmsg_level; /* originating protocol */\n"
2685 " int cmsg_type; /* protocol-specific type */\n"
2687 " unsigned char cmsg_data[]; */\n"
2692 #: build/C/man2/recv.2:357
2693 msgid "Ancillary data should only be accessed by the macros defined in B<cmsg>(3)."
2697 #: build/C/man2/recv.2:360
2699 "As an example, Linux uses this ancillary data mechanism to pass extended "
2700 "errors, IP options, or file descriptors over UNIX domain sockets."
2704 #: build/C/man2/recv.2:368
2706 "The I<msg_flags> field in the I<msghdr> is set on return of B<recvmsg>(). "
2707 "It can contain several flags:"
2711 #: build/C/man2/recv.2:368
2717 #: build/C/man2/recv.2:373
2719 "indicates end-of-record; the data returned completed a record (generally "
2720 "used with sockets of type B<SOCK_SEQPACKET>)."
2724 #: build/C/man2/recv.2:373
2726 msgid "B<MSG_TRUNC>"
2730 #: build/C/man2/recv.2:377
2732 "indicates that the trailing portion of a datagram was discarded because the "
2733 "datagram was larger than the buffer supplied."
2737 #: build/C/man2/recv.2:377
2739 msgid "B<MSG_CTRUNC>"
2743 #: build/C/man2/recv.2:381
2745 "indicates that some control data were discarded due to lack of space in the "
2746 "buffer for ancillary data."
2750 #: build/C/man2/recv.2:384
2751 msgid "is returned to indicate that expedited or out-of-band data were received."
2755 #: build/C/man2/recv.2:384
2757 msgid "B<MSG_ERRQUEUE>"
2761 #: build/C/man2/recv.2:388
2763 "indicates that no data was received but an extended error from the socket "
2768 #: build/C/man2/recv.2:393
2770 "These calls return the number of bytes received, or -1 if an error "
2771 "occurred. The return value will be 0 when the peer has performed an orderly "
2776 #: build/C/man2/recv.2:398
2778 "These are some standard errors generated by the socket layer. Additional "
2779 "errors may be generated and returned from the underlying protocol modules; "
2780 "see their manual pages."
2783 #. Actually EAGAIN on Linux
2785 #: build/C/man2/recv.2:407
2787 "The socket is marked nonblocking and the receive operation would block, or a "
2788 "receive timeout had been set and the timeout expired before data was "
2789 "received. POSIX.1-2001 allows either error to be returned for this case, "
2790 "and does not require these constants to have the same value, so a portable "
2791 "application should check for both possibilities."
2795 #: build/C/man2/recv.2:412
2796 msgid "The argument I<sockfd> is an invalid descriptor."
2800 #: build/C/man2/recv.2:416
2802 "A remote host refused to allow the network connection (typically because it "
2803 "is not running the requested service)."
2807 #: build/C/man2/recv.2:420
2808 msgid "The receive buffer pointer(s) point outside the process's address space."
2812 #: build/C/man2/recv.2:425
2814 "The receive was interrupted by delivery of a signal before any data were "
2815 "available; see B<signal>(7)."
2819 #: build/C/man2/recv.2:429 build/C/man2/send.2:323
2820 msgid "Invalid argument passed."
2824 #: build/C/man2/recv.2:433
2825 msgid "Could not allocate memory for B<recvmsg>()."
2829 #: build/C/man2/recv.2:433 build/C/man2/send.2:346
2835 #: build/C/man2/recv.2:440
2837 "The socket is associated with a connection-oriented protocol and has not "
2838 "been connected (see B<connect>(2) and B<accept>(2))."
2842 #: build/C/man2/recv.2:445
2843 msgid "The argument I<sockfd> does not refer to a socket."
2847 #: build/C/man2/recv.2:448
2848 msgid "4.4BSD (these function calls first appeared in 4.2BSD), POSIX.1-2001."
2852 #: build/C/man2/recv.2:455
2854 "POSIX.1-2001 only describes the B<MSG_OOB>, B<MSG_PEEK>, and B<MSG_WAITALL> "
2859 #: build/C/man2/recv.2:471
2861 "The prototypes given above follow glibc2. The Single UNIX Specification "
2862 "agrees, except that it has return values of type I<ssize_t> (while 4.x BSD "
2863 "and libc4 and libc5 all have I<int>). The I<flags> argument is I<int> in "
2864 "4.x BSD, but I<unsigned int> in libc4 and libc5. The I<len> argument is "
2865 "I<int> in 4.x BSD, but I<size_t> in libc4 and libc5. The I<addrlen> "
2866 "argument is I<int\\ *> in 4.x BSD, libc4 and libc5. The present "
2867 "I<socklen_t\\ *> was invented by POSIX. See also B<accept>(2)."
2870 #. glibc bug raised 12 Mar 2006
2871 #. http://sourceware.org/bugzilla/show_bug.cgi?id=2448
2872 #. The problem is an underlying kernel issue: the size of the
2873 #. __kernel_size_t type used to type this field varies
2874 #. across architectures, but socklen_t is always 32 bits.
2876 #: build/C/man2/recv.2:485 build/C/man2/send.2:409
2878 "According to POSIX.1-2001, the I<msg_controllen> field of the I<msghdr> "
2879 "structure should be typed as I<socklen_t>, but glibc currently types it as "
2884 #: build/C/man2/recv.2:490
2886 "See B<recvmmsg>(2) for information about a Linux-specific system call that "
2887 "can be used to receive multiple datagrams in a single call."
2891 #: build/C/man2/recv.2:495
2892 msgid "An example of the use of B<recvfrom>() is shown in B<getaddrinfo>(3)."
2896 #: build/C/man2/recv.2:506
2898 "B<fcntl>(2), B<getsockopt>(2), B<read>(2), B<recvmmsg>(2), B<select>(2), "
2899 "B<shutdown>(2), B<socket>(2), B<cmsg>(3), B<sockatmark>(3), B<socket>(7)"
2903 #: build/C/man2/recvmmsg.2:31
2909 #: build/C/man2/recvmmsg.2:31
2915 #: build/C/man2/recvmmsg.2:34
2916 msgid "recvmmsg - receive multiple messages on a socket"
2920 #: build/C/man2/recvmmsg.2:38 build/C/man2/sendmmsg.2:35
2923 "B<#define _GNU_SOURCE>\n"
2924 "B<#include E<lt>sys/socket.hE<gt>>\n"
2928 #: build/C/man2/recvmmsg.2:41
2931 "B<int recvmmsg(int >I<sockfd>B<, struct mmsghdr *>I<msgvec>B<, unsigned int "
2936 #: build/C/man2/recvmmsg.2:43
2938 msgid "B< unsigned int >I<flags>B<, struct timespec *>I<timeout>B<);>\n"
2942 #: build/C/man2/recvmmsg.2:55
2944 "The B<recvmmsg>() system call is an extension of B<recvmsg>(2) that allows "
2945 "the caller to receive multiple messages from a socket using a single system "
2946 "call. (This has performance benefits for some applications.) A further "
2947 "extension over B<recvmsg>(2) is support for a timeout on the receive "
2952 #: build/C/man2/recvmmsg.2:59
2954 "The I<sockfd> argument is the file descriptor of the socket to receive data "
2959 #: build/C/man2/recvmmsg.2:67 build/C/man2/sendmmsg.2:62
2961 "The I<msgvec> argument is a pointer to an array of I<mmsghdr> structures. "
2962 "The size of this array is specified in I<vlen>."
2966 #: build/C/man2/recvmmsg.2:73 build/C/man2/sendmmsg.2:68
2967 msgid "The I<mmsghdr> structure is defined in I<E<lt>sys/socket.hE<gt>> as:"
2971 #: build/C/man2/recvmmsg.2:80
2974 "struct mmsghdr {\n"
2975 " struct msghdr msg_hdr; /* Message header */\n"
2976 " unsigned int msg_len; /* Number of received bytes for header */\n"
2981 #: build/C/man2/recvmmsg.2:95
2983 "The I<msg_hdr> field is a I<msghdr> structure, as described in "
2984 "B<recvmsg>(2). The I<msg_len> field is the number of bytes returned for the "
2985 "message in the entry. This field has the same value as the return value of "
2986 "a single B<recvmsg>(2) on the header."
2990 #: build/C/man2/recvmmsg.2:102
2992 "The I<flags> argument contains flags ORed together. The flags are the same "
2993 "as documented for B<recvmsg>(2), with the following addition:"
2997 #: build/C/man2/recvmmsg.2:102
2999 msgid "B<MSG_WAITFORONE> (since Linux 2.6.34)"
3003 #: build/C/man2/recvmmsg.2:107
3004 msgid "Turns on B<MSG_DONTWAIT> after the first message has been received."
3008 #: build/C/man2/recvmmsg.2:123
3010 "The I<timeout> argument points to a I<struct timespec> (see "
3011 "B<clock_gettime>(2)) defining a timeout (seconds plus nanoseconds) for the "
3012 "receive operation. (This interval will be rounded up to the system clock "
3013 "granularity, and kernel scheduling delays mean that the blocking interval "
3014 "may overrun by a small amount.) If I<timeout> is I<NULL> then the operation "
3015 "blocks indefinitely."
3019 #: build/C/man2/recvmmsg.2:134
3021 "A blocking B<recvmmsg>() call blocks until I<vlen> messages have been "
3022 "received or until the timeout expires. A nonblocking call reads as many "
3023 "messages as are available (up to the limit specified by I<vlen>) and "
3024 "returns immediately."
3028 #: build/C/man2/recvmmsg.2:149
3030 "On return from B<recvmmsg>(), successive elements of I<msgvec> are updated "
3031 "to contain information about each received message: I<msg_len> contains the "
3032 "size of the received message; the subfields of I<msg_hdr> are updated as "
3033 "described in B<recvmsg>(2). The return value of the call indicates the "
3034 "number of elements of I<msgvec> that have been updated."
3038 #: build/C/man2/recvmmsg.2:157
3040 "On success, B<recvmmsg>() returns the number of messages received in "
3041 "I<msgvec>; on error, -1 is returned, and I<errno> is set to indicate the "
3046 #: build/C/man2/recvmmsg.2:161
3048 "Errors are as for B<recvmsg>(2). In addition, the following error can "
3053 #: build/C/man2/recvmmsg.2:165
3054 msgid "I<timeout> is invalid."
3058 #: build/C/man2/recvmmsg.2:170
3060 "The B<recvmmsg>() system call was added in Linux 2.6.33. Support in glibc "
3061 "was added in version 2.12."
3065 #: build/C/man2/recvmmsg.2:173
3066 msgid "B<recvmmsg>() is Linux-specific."
3070 #: build/C/man2/recvmmsg.2:181
3072 "The following program uses B<recvmmsg>() to receive multiple messages on a "
3073 "socket and stores them in multiple buffers. The call returns if all buffers "
3074 "are filled or if the timeout specified has expired."
3078 #: build/C/man2/recvmmsg.2:184
3080 "The following snippet periodically generates UDP datagrams containing a "
3085 #: build/C/man2/recvmmsg.2:189
3088 "$B< while true; do echo $RANDOM E<gt> /dev/udp/127.0.0.1/1234; >\n"
3089 "B<sleep 0.25; done>\n"
3093 #: build/C/man2/recvmmsg.2:194
3095 "These datagrams are read by the example application, which can give the "
3100 #: build/C/man2/recvmmsg.2:204
3104 "5 messages received\n"
3113 #: build/C/man2/recvmmsg.2:215
3116 "#define _GNU_SOURCE\n"
3117 "#include E<lt>netinet/ip.hE<gt>\n"
3118 "#include E<lt>stdio.hE<gt>\n"
3119 "#include E<lt>stdlib.hE<gt>\n"
3120 "#include E<lt>string.hE<gt>\n"
3121 "#include E<lt>sys/socket.hE<gt>\n"
3125 #: build/C/man2/recvmmsg.2:228
3132 "#define BUFSIZE 200\n"
3133 "#define TIMEOUT 1\n"
3134 " int sockfd, retval, i;\n"
3135 " struct sockaddr_in sa;\n"
3136 " struct mmsghdr msgs[VLEN];\n"
3137 " struct iovec iovecs[VLEN];\n"
3138 " char bufs[VLEN][BUFSIZE+1];\n"
3139 " struct timespec timeout;\n"
3143 #: build/C/man2/recvmmsg.2:234 build/C/man2/sendmmsg.2:201
3146 " sockfd = socket(AF_INET, SOCK_DGRAM, 0);\n"
3147 " if (sockfd == -1) {\n"
3148 " perror(\"socket()\");\n"
3149 " exit(EXIT_FAILURE);\n"
3154 #: build/C/man2/recvmmsg.2:242
3157 " sa.sin_family = AF_INET;\n"
3158 " sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);\n"
3159 " sa.sin_port = htons(1234);\n"
3160 " if (bind(sockfd, (struct sockaddr *) &sa, sizeof(sa)) == -1) {\n"
3161 " perror(\"bind()\");\n"
3162 " exit(EXIT_FAILURE);\n"
3167 #: build/C/man2/recvmmsg.2:250
3170 " memset(msgs, 0, sizeof(msgs));\n"
3171 " for (i = 0; i E<lt> VLEN; i++) {\n"
3172 " iovecs[i].iov_base = bufs[i];\n"
3173 " iovecs[i].iov_len = BUFSIZE;\n"
3174 " msgs[i].msg_hdr.msg_iov = &iovecs[i];\n"
3175 " msgs[i].msg_hdr.msg_iovlen = 1;\n"
3180 #: build/C/man2/recvmmsg.2:253
3183 " timeout.tv_sec = TIMEOUT;\n"
3184 " timeout.tv_nsec = 0;\n"
3188 #: build/C/man2/recvmmsg.2:259
3191 " retval = recvmmsg(sockfd, msgs, VLEN, 0, &timeout);\n"
3192 " if (retval == -1) {\n"
3193 " perror(\"recvmmsg()\");\n"
3194 " exit(EXIT_FAILURE);\n"
3199 #: build/C/man2/recvmmsg.2:267
3202 " printf(\"%d messages received\\en\", retval);\n"
3203 " for (i = 0; i E<lt> retval; i++) {\n"
3204 " bufs[i][msgs[i].msg_len] = 0;\n"
3205 " printf(\"%d %s\", i+1, bufs[i]);\n"
3207 " exit(EXIT_SUCCESS);\n"
3212 #: build/C/man2/recvmmsg.2:275
3214 "B<clock_gettime>(2), B<recvmsg>(2), B<sendmmsg>(2), B<sendmsg>(2), "
3215 "B<socket>(2), B<socket>(7)"
3219 #: build/C/man2/select.2:38
3225 #: build/C/man2/select.2:38
3231 #: build/C/man2/select.2:42 build/C/man2/select_tut.2:36
3233 "select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO - synchronous I/O "
3238 #: build/C/man2/select.2:45 build/C/man2/select_tut.2:39
3240 msgid "/* According to POSIX.1-2001 */\n"
3244 #: 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
3246 msgid "B<#include E<lt>sys/select.hE<gt>>\n"
3250 #: build/C/man2/select.2:49 build/C/man2/select_tut.2:43
3252 msgid "/* According to earlier standards */\n"
3256 #: build/C/man2/select.2:51 build/C/man2/select_tut.2:45
3258 msgid "B<#include E<lt>sys/time.hE<gt>>\n"
3262 #: build/C/man2/select.2:55 build/C/man2/select_tut.2:49
3264 msgid "B<#include E<lt>unistd.hE<gt>>\n"
3268 #: build/C/man2/select.2:58
3271 "B<int select(int >I<nfds>B<, fd_set *>I<readfds>B<, fd_set "
3272 "*>I<writefds>B<,>\n"
3273 "B< fd_set *>I<exceptfds>B<, struct timeval *>I<timeout>B<);>\n"
3277 #: build/C/man2/select.2:60 build/C/man2/select_tut.2:54
3279 msgid "B<void FD_CLR(int >I<fd>B<, fd_set *>I<set>B<);>\n"
3283 #: build/C/man2/select.2:62 build/C/man2/select_tut.2:56
3285 msgid "B<int FD_ISSET(int >I<fd>B<, fd_set *>I<set>B<);>\n"
3289 #: build/C/man2/select.2:64 build/C/man2/select_tut.2:58
3291 msgid "B<void FD_SET(int >I<fd>B<, fd_set *>I<set>B<);>\n"
3295 #: build/C/man2/select.2:66 build/C/man2/select_tut.2:60
3297 msgid "B<void FD_ZERO(fd_set *>I<set>B<);>\n"
3301 #: build/C/man2/select.2:72
3304 "B<int pselect(int >I<nfds>B<, fd_set *>I<readfds>B<, fd_set "
3305 "*>I<writefds>B<,>\n"
3306 "B< fd_set *>I<exceptfds>B<, const struct timespec "
3307 "*>I<timeout>B<,>\n"
3308 "B< const sigset_t *>I<sigmask>B<);>\n"
3312 #: build/C/man2/select.2:77 build/C/man2/select_tut.2:71 build/C/man3/sockatmark.3:36
3313 msgid "Feature Test Macro Requirements for glibc (see B<feature_test_macros>(7)):"
3317 #: build/C/man2/select.2:81 build/C/man2/select_tut.2:75
3319 "B<pselect>(): _POSIX_C_SOURCE\\ E<gt>=\\ 200112L || _XOPEN_SOURCE\\ E<gt>=\\ "
3324 #: build/C/man2/select.2:92
3326 "B<select>() and B<pselect>() allow a program to monitor multiple file "
3327 "descriptors, waiting until one or more of the file descriptors become "
3328 "\"ready\" for some class of I/O operation (e.g., input possible). A file "
3329 "descriptor is considered ready if it is possible to perform the "
3330 "corresponding I/O operation (e.g., B<read>(2)) without blocking."
3334 #: build/C/man2/select.2:98
3336 "The operation of B<select>() and B<pselect>() is identical, other than "
3337 "these three differences:"
3341 #: build/C/man2/select.2:98
3347 #: build/C/man2/select.2:108
3349 "B<select>() uses a timeout that is a I<struct timeval> (with seconds and "
3350 "microseconds), while B<pselect>() uses a I<struct timespec> (with seconds "
3355 #: build/C/man2/select.2:108
3361 #: build/C/man2/select.2:116
3363 "B<select>() may update the I<timeout> argument to indicate how much time "
3364 "was left. B<pselect>() does not change this argument."
3368 #: build/C/man2/select.2:116
3374 #: build/C/man2/select.2:125
3376 "B<select>() has no I<sigmask> argument, and behaves as B<pselect>() called "
3377 "with NULL I<sigmask>."
3381 #: build/C/man2/select.2:143
3383 "Three independent sets of file descriptors are watched. Those listed in "
3384 "I<readfds> will be watched to see if characters become available for reading "
3385 "(more precisely, to see if a read will not block; in particular, a file "
3386 "descriptor is also ready on end-of-file), those in I<writefds> will be "
3387 "watched to see if a write will not block, and those in I<exceptfds> will be "
3388 "watched for exceptions. On exit, the sets are modified in place to indicate "
3389 "which file descriptors actually changed status. Each of the three file "
3390 "descriptor sets may be specified as NULL if no file descriptors are to be "
3391 "watched for the corresponding class of events."
3395 #: build/C/man2/select.2:156
3397 "Four macros are provided to manipulate the sets. B<FD_ZERO>() clears a "
3398 "set. B<FD_SET>() and B<FD_CLR>() respectively add and remove a given file "
3399 "descriptor from a set. B<FD_ISSET>() tests to see if a file descriptor is "
3400 "part of the set; this is useful after B<select>() returns."
3404 #: build/C/man2/select.2:159
3406 "I<nfds> is the highest-numbered file descriptor in any of the three sets, "
3411 #: build/C/man2/select.2:179
3413 "The I<timeout> argument specifies the minimum interval that B<select>() "
3414 "should block waiting for a file descriptor to become ready. (This interval "
3415 "will be rounded up to the system clock granularity, and kernel scheduling "
3416 "delays mean that the blocking interval may overrun by a small amount.) If "
3417 "both fields of the I<timeval> structure are zero, then B<select>() returns "
3418 "immediately. (This is useful for polling.) If I<timeout> is NULL (no "
3419 "timeout), B<select>() can block indefinitely."
3423 #: build/C/man2/select.2:189
3425 "I<sigmask> is a pointer to a signal mask (see B<sigprocmask>(2)); if it is "
3426 "not NULL, then B<pselect>() first replaces the current signal mask by the "
3427 "one pointed to by I<sigmask>, then does the \"select\" function, and then "
3428 "restores the original signal mask."
3432 #: build/C/man2/select.2:195
3434 "Other than the difference in the precision of the I<timeout> argument, the "
3435 "following B<pselect>() call:"
3439 #: build/C/man2/select.2:199
3442 " ready = pselect(nfds, &readfds, &writefds, &exceptfds,\n"
3443 " timeout, &sigmask);\n"
3447 #: build/C/man2/select.2:204
3448 msgid "is equivalent to I<atomically> executing the following calls:"
3452 #: build/C/man2/select.2:207
3454 msgid " sigset_t origmask;\n"
3458 #: build/C/man2/select.2:211
3461 " pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);\n"
3462 " ready = select(nfds, &readfds, &writefds, &exceptfds, timeout);\n"
3463 " pthread_sigmask(SIG_SETMASK, &origmask, NULL);\n"
3467 #: build/C/man2/select.2:232
3469 "The reason that B<pselect>() is needed is that if one wants to wait for "
3470 "either a signal or for a file descriptor to become ready, then an atomic "
3471 "test is needed to prevent race conditions. (Suppose the signal handler sets "
3472 "a global flag and returns. Then a test of this global flag followed by a "
3473 "call of B<select>() could hang indefinitely if the signal arrived just "
3474 "after the test but just before the call. By contrast, B<pselect>() allows "
3475 "one to first block signals, handle the signals that have come in, then call "
3476 "B<pselect>() with the desired I<sigmask>, avoiding the race.)"
3480 #: build/C/man2/select.2:232
3486 #: build/C/man2/select.2:236
3488 "The time structures involved are defined in I<E<lt>sys/time.hE<gt>> and look "
3493 #: build/C/man2/select.2:243
3496 "struct timeval {\n"
3497 " long tv_sec; /* seconds */\n"
3498 " long tv_usec; /* microseconds */\n"
3503 #: build/C/man2/select.2:247
3508 #: build/C/man2/select.2:254
3511 "struct timespec {\n"
3512 " long tv_sec; /* seconds */\n"
3513 " long tv_nsec; /* nanoseconds */\n"
3518 #: build/C/man2/select.2:258
3519 msgid "(However, see below on the POSIX.1-2001 versions.)"
3523 #: build/C/man2/select.2:266
3525 "Some code calls B<select>() with all three sets empty, I<nfds> zero, and a "
3526 "non-NULL I<timeout> as a fairly portable way to sleep with subsecond "
3530 #. .PP - it is rumored that:
3531 #. On BSD, when a timeout occurs, the file descriptor bits are not changed.
3532 #. - it is certainly true that:
3533 #. Linux follows SUSv2 and sets the bit masks to zero upon a timeout.
3535 #: build/C/man2/select.2:289
3537 "On Linux, B<select>() modifies I<timeout> to reflect the amount of time not "
3538 "slept; most other implementations do not do this. (POSIX.1-2001 permits "
3539 "either behavior.) This causes problems both when Linux code which reads "
3540 "I<timeout> is ported to other operating systems, and when code is ported to "
3541 "Linux that reuses a I<struct timeval> for multiple B<select>()s in a loop "
3542 "without reinitializing it. Consider I<timeout> to be undefined after "
3543 "B<select>() returns."
3547 #: build/C/man2/select.2:306
3549 "On success, B<select>() and B<pselect>() return the number of file "
3550 "descriptors contained in the three returned descriptor sets (that is, the "
3551 "total number of bits that are set in I<readfds>, I<writefds>, I<exceptfds>) "
3552 "which may be zero if the timeout expires before anything interesting "
3553 "happens. On error, -1 is returned, and I<errno> is set appropriately; the "
3554 "sets and I<timeout> become undefined, so do not rely on their contents after "
3559 #: build/C/man2/select.2:312
3561 "An invalid file descriptor was given in one of the sets. (Perhaps a file "
3562 "descriptor that was already closed, or one on which an error has occurred.)"
3566 #: build/C/man2/select.2:316
3567 msgid "A signal was caught; see B<signal>(7)."
3571 #: build/C/man2/select.2:322
3572 msgid "I<nfds> is negative or the value contained within I<timeout> is invalid."
3576 #: build/C/man2/select.2:325
3577 msgid "unable to allocate memory for internal tables."
3581 #: build/C/man2/select.2:331
3583 "B<pselect>() was added to Linux in kernel 2.6.16. Prior to this, "
3584 "B<pselect>() was emulated in glibc (but see BUGS)."
3588 #: build/C/man2/select.2:342
3590 "B<select>() conforms to POSIX.1-2001 and 4.4BSD (B<select>() first "
3591 "appeared in 4.2BSD). Generally portable to/from non-BSD systems supporting "
3592 "clones of the BSD socket layer (including System V variants). However, note "
3593 "that the System V variant typically sets the timeout variable before exit, "
3594 "but the BSD variant does not."
3598 #: build/C/man2/select.2:346
3599 msgid "B<pselect>() is defined in POSIX.1g, and in POSIX.1-2001."
3603 #: build/C/man2/select.2:363
3605 "An I<fd_set> is a fixed size buffer. Executing B<FD_CLR>() or B<FD_SET>() "
3606 "with a value of I<fd> that is negative or is equal to or larger than "
3607 "B<FD_SETSIZE> will result in undefined behavior. Moreover, POSIX requires "
3608 "I<fd> to be a valid file descriptor."
3612 #: build/C/man2/select.2:372
3614 "Concerning the types involved, the classical situation is that the two "
3615 "fields of a I<timeval> structure are typed as I<long> (as shown above), and "
3616 "the structure is defined in I<E<lt>sys/time.hE<gt>>. The POSIX.1-2001 "
3621 #: build/C/man2/select.2:379
3624 "struct timeval {\n"
3625 " time_t tv_sec; /* seconds */\n"
3626 " suseconds_t tv_usec; /* microseconds */\n"
3631 #: build/C/man2/select.2:390
3633 "where the structure is defined in I<E<lt>sys/select.hE<gt>> and the data "
3634 "types I<time_t> and I<suseconds_t> are defined in I<E<lt>sys/types.hE<gt>>."
3638 #: build/C/man2/select.2:402
3640 "Concerning prototypes, the classical situation is that one should include "
3641 "I<E<lt>time.hE<gt>> for B<select>(). The POSIX.1-2001 situation is that one "
3642 "should include I<E<lt>sys/select.hE<gt>> for B<select>() and B<pselect>()."
3646 #: build/C/man2/select.2:414
3648 "Libc4 and libc5 do not have a I<E<lt>sys/select.hE<gt>> header; under glibc "
3649 "2.0 and later this header exists. Under glibc 2.0 it unconditionally gives "
3650 "the wrong prototype for B<pselect>(). Under glibc 2.1 to 2.2.1 it gives "
3651 "B<pselect>() when B<_GNU_SOURCE> is defined. Since glibc 2.2.2 the "
3652 "requirements are as shown in the SYNOPSIS."
3656 #: build/C/man2/select.2:414
3658 msgid "Multithreaded applications"
3662 #: build/C/man2/select.2:430
3664 "If a file descriptor being monitored by B<select>() is closed in another "
3665 "thread, the result is unspecified. On some UNIX systems, B<select>() "
3666 "unblocks and returns, with an indication that the file descriptor is ready "
3667 "(a subsequent I/O operation will likely fail with an error, unless another "
3668 "the file descriptor reopened between the time B<select>() returned and the "
3669 "I/O operations was performed). On Linux (and some other systems), closing "
3670 "the file descriptor in another thread has no effect on B<select>(). In "
3671 "summary, any application that relies on a particular behavior in this "
3672 "scenario must be considered buggy."
3676 #: build/C/man2/select.2:430
3682 #: build/C/man2/select.2:438
3684 "The B<pselect>() interface described in this page is implemented by glibc. "
3685 "The underlying Linux system call is named B<pselect6>(). This system call "
3686 "has somewhat different behavior from the glibc wrapper function."
3690 #: build/C/man2/select.2:453
3692 "The Linux B<pselect6>() system call modifies its I<timeout> argument. "
3693 "However, the glibc wrapper function hides this behavior by using a local "
3694 "variable for the timeout argument that is passed to the system call. Thus, "
3695 "the glibc B<pselect>() function does not modify its I<timeout> argument; "
3696 "this is the behavior required by POSIX.1-2001."
3700 #: build/C/man2/select.2:459
3702 "The final argument of the B<pselect6>() system call is not a I<sigset_t\\ "
3703 "*> pointer, but is instead a structure of the form:"
3707 #: build/C/man2/select.2:467
3711 " const sigset_t *ss; /* Pointer to signal set */\n"
3712 " size_t ss_len; /* Size (in bytes) of object pointed\n"
3718 #: build/C/man2/select.2:474
3720 "This allows the system call to obtain both a pointer to the signal set and "
3721 "its size, while allowing for the fact that most architectures support a "
3722 "maximum of 6 arguments to a system call."
3726 #: build/C/man2/select.2:480
3728 "Glibc 2.0 provided a version of B<pselect>() that did not take a I<sigmask> "
3733 #: build/C/man2/select.2:493
3735 "Starting with version 2.1, glibc provided an emulation of B<pselect>() that "
3736 "was implemented using B<sigprocmask>(2) and B<select>(). This "
3737 "implementation remained vulnerable to the very race condition that "
3738 "B<pselect>() was designed to prevent. Modern versions of glibc use the "
3739 "(race-free) B<pselect>() system call on kernels where it is provided."
3743 #: build/C/man2/select.2:506
3745 "On systems that lack B<pselect>(), reliable (and more portable) signal "
3746 "trapping can be achieved using the self-pipe trick. In this technique, a "
3747 "signal handler writes a byte to a pipe whose other end is monitored by "
3748 "B<select>() in the main program. (To avoid possibly blocking when writing "
3749 "to a pipe that may be full or reading from a pipe that may be empty, "
3750 "nonblocking I/O is used when reading from and writing to the pipe.)"
3753 #. Stevens discusses a case where accept can block after select
3754 #. returns successfully because of an intervening RST from the client.
3755 #. Maybe the kernel should have returned EIO in such a situation?
3757 #: build/C/man2/select.2:522
3759 "Under Linux, B<select>() may report a socket file descriptor as \"ready for "
3760 "reading\", while nevertheless a subsequent read blocks. This could for "
3761 "example happen when data has arrived but upon examination has wrong checksum "
3762 "and is discarded. There may be other circumstances in which a file "
3763 "descriptor is spuriously reported as ready. Thus it may be safer to use "
3764 "B<O_NONBLOCK> on sockets that should not block."
3768 #: build/C/man2/select.2:537
3770 "On Linux, B<select>() also modifies I<timeout> if the call is interrupted "
3771 "by a signal handler (i.e., the B<EINTR> error return). This is not "
3772 "permitted by POSIX.1-2001. The Linux B<pselect>() system call has the same "
3773 "behavior, but the glibc wrapper hides this behavior by internally copying "
3774 "the I<timeout> to a local variable and passing that variable to the system "
3779 #: build/C/man2/select.2:544
3782 "#include E<lt>stdio.hE<gt>\n"
3783 "#include E<lt>stdlib.hE<gt>\n"
3784 "#include E<lt>sys/time.hE<gt>\n"
3785 "#include E<lt>sys/types.hE<gt>\n"
3786 "#include E<lt>unistd.hE<gt>\n"
3790 #: build/C/man2/select.2:551
3797 " struct timeval tv;\n"
3802 #: build/C/man2/select.2:555
3805 " /* Watch stdin (fd 0) to see when it has input. */\n"
3806 " FD_ZERO(&rfds);\n"
3807 " FD_SET(0, &rfds);\n"
3811 #: build/C/man2/select.2:559
3814 " /* Wait up to five seconds. */\n"
3816 " tv.tv_usec = 0;\n"
3820 #: build/C/man2/select.2:562
3823 " retval = select(1, &rfds, NULL, NULL, &tv);\n"
3824 " /* Don't rely on the value of tv now! */\n"
3828 #: build/C/man2/select.2:570
3831 " if (retval == -1)\n"
3832 " perror(\"select()\");\n"
3833 " else if (retval)\n"
3834 " printf(\"Data is available now.\\en\");\n"
3835 " /* FD_ISSET(0, &rfds) will be true. */\n"
3837 " printf(\"No data within five seconds.\\en\");\n"
3841 #: build/C/man2/select.2:585
3843 "B<accept>(2), B<connect>(2), B<poll>(2), B<read>(2), B<recv>(2), B<send>(2), "
3844 "B<sigprocmask>(2), B<write>(2), B<epoll>(7), B<time>(7)"
3848 #: build/C/man2/select.2:588
3849 msgid "For a tutorial with discussion and examples, see B<select_tut>(2)."
3853 #: build/C/man2/select_tut.2:32
3859 #: build/C/man2/select_tut.2:32
3865 #: build/C/man2/select_tut.2:52
3868 "B<int select(int >I<nfds>B<, fd_set *>I<readfds>B<, fd_set "
3869 "*>I<writefds>B<,>\n"
3870 "B< fd_set *>I<exceptfds>B<, struct timeval *>I<utimeout>B<);>\n"
3874 #: build/C/man2/select_tut.2:66
3877 "B<int pselect(int >I<nfds>B<, fd_set *>I<readfds>B<, fd_set "
3878 "*>I<writefds>B<,>\n"
3879 "B< fd_set *>I<exceptfds>B<, const struct timespec "
3880 "*>I<ntimeout>B<,>\n"
3881 "B< const sigset_t *>I<sigmask>B<);>\n"
3885 #: build/C/man2/select_tut.2:83
3887 "B<select>() (or B<pselect>()) is used to efficiently monitor multiple file "
3888 "descriptors, to see if any of them is, or becomes, \"ready\"; that is, to "
3889 "see whether I/O becomes possible, or an \"exceptional condition\" has "
3890 "occurred on any of the descriptors."
3894 #: build/C/man2/select_tut.2:108
3896 "Its principal arguments are three \"sets\" of file descriptors: I<readfds>, "
3897 "I<writefds>, and I<exceptfds>. Each set is declared as type I<fd_set>, and "
3898 "its contents can be manipulated with the macros B<FD_CLR>(), B<FD_ISSET>(), "
3899 "B<FD_SET>(), and B<FD_ZERO>(). A newly declared set should first be cleared "
3900 "using B<FD_ZERO>(). B<select>() modifies the contents of the sets "
3901 "according to the rules described below; after calling B<select>() you can "
3902 "test if a file descriptor is still present in a set with the B<FD_ISSET>() "
3903 "macro. B<FD_ISSET>() returns nonzero if a specified file descriptor is "
3904 "present in a set and zero if it is not. B<FD_CLR>() removes a file "
3905 "descriptor from a set."
3909 #: build/C/man2/select_tut.2:108
3915 #: build/C/man2/select_tut.2:109
3921 #: build/C/man2/select_tut.2:118
3923 "This set is watched to see if data is available for reading from any of its "
3924 "file descriptors. After B<select>() has returned, I<readfds> will be "
3925 "cleared of all file descriptors except for those that are immediately "
3926 "available for reading."
3930 #: build/C/man2/select_tut.2:118
3936 #: build/C/man2/select_tut.2:127
3938 "This set is watched to see if there is space to write data to any of its "
3939 "file descriptors. After B<select>() has returned, I<writefds> will be "
3940 "cleared of all file descriptors except for those that are immediately "
3941 "available for writing."
3945 #: build/C/man2/select_tut.2:127
3947 msgid "I<exceptfds>"
3951 #: build/C/man2/select_tut.2:149
3953 "This set is watched for \"exceptional conditions\". In practice, only one "
3954 "such exceptional condition is common: the availability of I<out-of-band> "
3955 "(OOB) data for reading from a TCP socket. See B<recv>(2), B<send>(2), and "
3956 "B<tcp>(7) for more details about OOB data. (One other less common case "
3957 "where B<select>(2) indicates an exceptional condition occurs with "
3958 "pseudoterminals in packet mode; see B<tty_ioctl>(4).) After B<select>() "
3959 "has returned, I<exceptfds> will be cleared of all file descriptors except "
3960 "for those for which an exceptional condition has occurred."
3964 #: build/C/man2/select_tut.2:149
3970 #: build/C/man2/select_tut.2:156
3972 "This is an integer one more than the maximum of any file descriptor in any "
3973 "of the sets. In other words, while adding file descriptors to each of the "
3974 "sets, you must calculate the maximum integer value of all of them, then "
3975 "increment this value by one, and then pass this as I<nfds>."
3979 #: build/C/man2/select_tut.2:156
3985 #: build/C/man2/select_tut.2:169
3987 "This is the longest time B<select>() may wait before returning, even if "
3988 "nothing interesting happened. If this value is passed as NULL, then "
3989 "B<select>() blocks indefinitely waiting for a file descriptor to become "
3990 "ready. I<utimeout> can be set to zero seconds, which causes B<select>() to "
3991 "return immediately, with information about the readiness of file descriptors "
3992 "at the time of the call. The structure I<struct timeval> is defined as:"
3996 #: build/C/man2/select_tut.2:176
3999 "struct timeval {\n"
4000 " time_t tv_sec; /* seconds */\n"
4001 " long tv_usec; /* microseconds */\n"
4006 #: build/C/man2/select_tut.2:178
4012 #: build/C/man2/select_tut.2:187
4014 "This argument for B<pselect>() has the same meaning as I<utimeout>, but "
4015 "I<struct timespec> has nanosecond precision as follows:"
4019 #: build/C/man2/select_tut.2:194
4022 "struct timespec {\n"
4023 " long tv_sec; /* seconds */\n"
4024 " long tv_nsec; /* nanoseconds */\n"
4029 #: build/C/man2/select_tut.2:196
4035 #: build/C/man2/select_tut.2:213
4037 "This argument holds a set of signals that the kernel should unblock (i.e., "
4038 "remove from the signal mask of the calling thread), while the caller is "
4039 "blocked inside the B<pselect>() call (see B<sigaddset>(3) and "
4040 "B<sigprocmask>(2)). It may be NULL, in which case the call does not modify "
4041 "the signal mask on entry and exit to the function. In this case, "
4042 "B<pselect>() will then behave just like B<select>()."
4046 #: build/C/man2/select_tut.2:213
4048 msgid "Combining signal and data events"
4052 #: build/C/man2/select_tut.2:257
4054 "B<pselect>() is useful if you are waiting for a signal as well as for file "
4055 "descriptor(s) to become ready for I/O. Programs that receive signals "
4056 "normally use the signal handler only to raise a global flag. The global "
4057 "flag will indicate that the event must be processed in the main loop of the "
4058 "program. A signal will cause the B<select>() (or B<pselect>()) call to "
4059 "return with I<errno> set to B<EINTR>. This behavior is essential so that "
4060 "signals can be processed in the main loop of the program, otherwise "
4061 "B<select>() would block indefinitely. Now, somewhere in the main loop will "
4062 "be a conditional to check the global flag. So we must ask: what if a signal "
4063 "arrives after the conditional, but before the B<select>() call? The answer "
4064 "is that B<select>() would block indefinitely, even though an event is "
4065 "actually pending. This race condition is solved by the B<pselect>() call. "
4066 "This call can be used to set the signal mask to a set of signals that are "
4067 "only to be received within the B<pselect>() call. For instance, let us say "
4068 "that the event in question was the exit of a child process. Before the "
4069 "start of the main loop, we would block B<SIGCHLD> using B<sigprocmask>(2). "
4070 "Our B<pselect>() call would enable B<SIGCHLD> by using an empty signal "
4071 "mask. Our program would look like:"
4075 #: build/C/man2/select_tut.2:260
4077 msgid "static volatile sig_atomic_t got_SIGCHLD = 0;\n"
4081 #: build/C/man2/select_tut.2:266
4085 "child_sig_handler(int sig)\n"
4087 " got_SIGCHLD = 1;\n"
4092 #: build/C/man2/select_tut.2:274
4096 "main(int argc, char *argv[])\n"
4098 " sigset_t sigmask, empty_mask;\n"
4099 " struct sigaction sa;\n"
4100 " fd_set readfds, writefds, exceptfds;\n"
4105 #: build/C/man2/select_tut.2:281
4108 " sigemptyset(&sigmask);\n"
4109 " sigaddset(&sigmask, SIGCHLD);\n"
4110 " if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) {\n"
4111 " perror(\"sigprocmask\");\n"
4112 " exit(EXIT_FAILURE);\n"
4117 #: build/C/man2/select_tut.2:289
4120 " sa.sa_flags = 0;\n"
4121 " sa.sa_handler = child_sig_handler;\n"
4122 " sigemptyset(&sa.sa_mask);\n"
4123 " if (sigaction(SIGCHLD, &sa, NULL) == -1) {\n"
4124 " perror(\"sigaction\");\n"
4125 " exit(EXIT_FAILURE);\n"
4130 #: build/C/man2/select_tut.2:291
4132 msgid " sigemptyset(&empty_mask);\n"
4136 #: build/C/man2/select_tut.2:295
4139 " for (;;) { /* main loop */\n"
4140 " /* Initialize readfds, writefds, and exceptfds\n"
4141 " before the pselect() call. (Code omitted.) */\n"
4145 #: build/C/man2/select_tut.2:301
4148 " r = pselect(nfds, &readfds, &writefds, &exceptfds,\n"
4149 " NULL, &empty_mask);\n"
4150 " if (r == -1 && errno != EINTR) {\n"
4151 " /* Handle error */\n"
4156 #: build/C/man2/select_tut.2:304
4159 " if (got_SIGCHLD) {\n"
4160 " got_SIGCHLD = 0;\n"
4164 #: build/C/man2/select_tut.2:308
4167 " /* Handle signalled event here; e.g., wait() for all\n"
4168 " terminated children. (Code omitted.) */\n"
4173 #: build/C/man2/select_tut.2:312
4176 " /* main body of program */\n"
4182 #: build/C/man2/select_tut.2:313
4188 #: build/C/man2/select_tut.2:334
4190 "So what is the point of B<select>()? Can't I just read and write to my "
4191 "descriptors whenever I want? The point of B<select>() is that it watches "
4192 "multiple descriptors at the same time and properly puts the process to sleep "
4193 "if there is no activity. UNIX programmers often find themselves in a "
4194 "position where they have to handle I/O from more than one file descriptor "
4195 "where the data flow may be intermittent. If you were to merely create a "
4196 "sequence of B<read>(2) and B<write>(2) calls, you would find that one of "
4197 "your calls may block waiting for data from/to a file descriptor, while "
4198 "another file descriptor is unused though ready for I/O. B<select>() "
4199 "efficiently copes with this situation."
4203 #: build/C/man2/select_tut.2:334
4209 #: build/C/man2/select_tut.2:347
4211 "Many people who try to use B<select>() come across behavior that is "
4212 "difficult to understand and produces nonportable or borderline results. For "
4213 "instance, the above program is carefully written not to block at any point, "
4214 "even though it does not set its file descriptors to nonblocking mode. It is "
4215 "easy to introduce subtle errors that will remove the advantage of using "
4216 "B<select>(), so here is a list of essentials to watch for when using "
4221 #: build/C/man2/select_tut.2:356
4223 "You should always try to use B<select>() without a timeout. Your program "
4224 "should have nothing to do if there is no data available. Code that depends "
4225 "on timeouts is not usually portable and is difficult to debug."
4229 #: build/C/man2/select_tut.2:360
4231 "The value I<nfds> must be properly calculated for efficiency as explained "
4236 #: build/C/man2/select_tut.2:367
4238 "No file descriptor must be added to any set if you do not intend to check "
4239 "its result after the B<select>() call, and respond appropriately. See next "
4244 #: build/C/man2/select_tut.2:373
4246 "After B<select>() returns, all file descriptors in all sets should be "
4247 "checked to see if they are ready."
4251 #: build/C/man2/select_tut.2:373
4257 #: build/C/man2/select_tut.2:388
4259 "The functions B<read>(2), B<recv>(2), B<write>(2), and B<send>(2) do I<not> "
4260 "necessarily read/write the full amount of data that you have requested. If "
4261 "they do read/write the full amount, it's because you have a low traffic load "
4262 "and a fast stream. This is not always going to be the case. You should "
4263 "cope with the case of your functions only managing to send or receive a "
4268 #: build/C/man2/select_tut.2:388
4274 #: build/C/man2/select_tut.2:396
4276 "Never read/write only in single bytes at a time unless you are really sure "
4277 "that you have a small amount of data to process. It is extremely "
4278 "inefficient not to read/write as much data as you can buffer each time. The "
4279 "buffers in the example below are 1024 bytes although they could easily be "
4284 #: build/C/man2/select_tut.2:396
4289 #. Nonetheless, you should still cope with these errors for completeness.
4291 #: build/C/man2/select_tut.2:418
4293 "The functions B<read>(2), B<recv>(2), B<write>(2), and B<send>(2) as well "
4294 "as the B<select>() call can return -1 with I<errno> set to B<EINTR>, or "
4295 "with I<errno> set to B<EAGAIN> (B<EWOULDBLOCK>). These results must be "
4296 "properly managed (not done properly above). If your program is not going to "
4297 "receive any signals, then it is unlikely you will get B<EINTR>. If your "
4298 "program does not set nonblocking I/O, you will not get B<EAGAIN>."
4302 #: build/C/man2/select_tut.2:418
4308 #: build/C/man2/select_tut.2:427
4310 "Never call B<read>(2), B<recv>(2), B<write>(2), or B<send>(2) with a buffer "
4315 #: build/C/man2/select_tut.2:427
4321 #: build/C/man2/select_tut.2:443
4323 "If the functions B<read>(2), B<recv>(2), B<write>(2), and B<send>(2) fail "
4324 "with errors other than those listed in B<7.>, or one of the input functions "
4325 "returns 0, indicating end of file, then you should I<not> pass that "
4326 "descriptor to B<select>() again. In the example below, I close the "
4327 "descriptor immediately, and then set it to -1 to prevent it being included "
4332 #: build/C/man2/select_tut.2:443
4338 #: build/C/man2/select_tut.2:450
4340 "The timeout value must be initialized with each new call to B<select>(), "
4341 "since some operating systems modify the structure. B<pselect>() however "
4342 "does not modify its timeout structure."
4346 #: build/C/man2/select_tut.2:450
4351 #. "I have heard" does not fill me with confidence, and doesn't
4352 #. belong in a man page, so I've commented this point out.
4355 #. I have heard that the Windows socket layer does not cope with OOB data
4357 #. It also does not cope with
4359 #. calls when no file descriptors are set at all.
4360 #. Having no file descriptors set is a useful
4361 #. way to sleep the process with subsecond precision by using the timeout.
4362 #. (See further on.)
4364 #: build/C/man2/select_tut.2:469
4366 "Since B<select>() modifies its file descriptor sets, if the call is being "
4367 "used in a loop, then the sets must be reinitialized before each call."
4371 #: build/C/man2/select_tut.2:469
4373 msgid "Usleep emulation"
4377 #: build/C/man2/select_tut.2:476
4379 "On systems that do not have a B<usleep>(3) function, you can call "
4380 "B<select>() with a finite timeout and no file descriptors as follows:"
4384 #: build/C/man2/select_tut.2:482
4387 " struct timeval tv;\n"
4389 " tv.tv_usec = 200000; /* 0.2 seconds */\n"
4390 " select(0, NULL, NULL, NULL, &tv);\n"
4394 #: build/C/man2/select_tut.2:485
4395 msgid "This is only guaranteed to work on UNIX systems, however."
4399 #: build/C/man2/select_tut.2:490
4401 "On success, B<select>() returns the total number of file descriptors still "
4402 "present in the file descriptor sets."
4406 #: build/C/man2/select_tut.2:496
4408 "If B<select>() timed out, then the return value will be zero. The file "
4409 "descriptors set should be all empty (but may not be on some systems)."
4413 #: build/C/man2/select_tut.2:503
4415 "A return value of -1 indicates an error, with I<errno> being set "
4416 "appropriately. In the case of an error, the contents of the returned sets "
4417 "and the I<struct timeout> contents are undefined and should not be used. "
4418 "B<pselect>() however never modifies I<ntimeout>."
4422 #: build/C/man2/select_tut.2:512
4424 "Generally speaking, all operating systems that support sockets also support "
4425 "B<select>(). B<select>() can be used to solve many problems in a portable "
4426 "and efficient way that naive programmers try to solve in a more complicated "
4427 "manner using threads, forking, IPCs, signals, memory sharing, and so on."
4431 #: build/C/man2/select_tut.2:521
4433 "The B<poll>(2) system call has the same functionality as B<select>(), and "
4434 "is somewhat more efficient when monitoring sparse file descriptor sets. It "
4435 "is nowadays widely available, but historically was less portable than "
4440 #: build/C/man2/select_tut.2:529
4442 "The Linux-specific B<epoll>(7) API provides an interface that is more "
4443 "efficient than B<select>(2) and B<poll>(2) when monitoring large numbers "
4444 "of file descriptors."
4448 #: build/C/man2/select_tut.2:534
4450 "Here is an example that better demonstrates the true utility of "
4451 "B<select>(). The listing below is a TCP forwarding program that forwards "
4452 "from one TCP port to another."
4456 #: build/C/man2/select_tut.2:547
4459 "#include E<lt>stdlib.hE<gt>\n"
4460 "#include E<lt>stdio.hE<gt>\n"
4461 "#include E<lt>unistd.hE<gt>\n"
4462 "#include E<lt>sys/time.hE<gt>\n"
4463 "#include E<lt>sys/types.hE<gt>\n"
4464 "#include E<lt>string.hE<gt>\n"
4465 "#include E<lt>signal.hE<gt>\n"
4466 "#include E<lt>sys/socket.hE<gt>\n"
4467 "#include E<lt>netinet/in.hE<gt>\n"
4468 "#include E<lt>arpa/inet.hE<gt>\n"
4469 "#include E<lt>errno.hE<gt>\n"
4473 #: build/C/man2/select_tut.2:549
4475 msgid "static int forward_port;\n"
4479 #: build/C/man2/select_tut.2:552
4483 "#define max(x,y) ((x) E<gt> (y) ? (x) : (y))\n"
4487 #: build/C/man2/select_tut.2:559
4491 "listen_socket(int listen_port)\n"
4493 " struct sockaddr_in a;\n"
4499 #: build/C/man2/select_tut.2:583
4502 " if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) {\n"
4503 " perror(\"socket\");\n"
4507 " if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,\n"
4508 " &yes, sizeof(yes)) == -1) {\n"
4509 " perror(\"setsockopt\");\n"
4513 " memset(&a, 0, sizeof(a));\n"
4514 " a.sin_port = htons(listen_port);\n"
4515 " a.sin_family = AF_INET;\n"
4516 " if (bind(s, (struct sockaddr *) &a, sizeof(a)) == -1) {\n"
4517 " perror(\"bind\");\n"
4521 " printf(\"accepting connections on port %d\\en\", listen_port);\n"
4528 #: build/C/man2/select_tut.2:589
4532 "connect_socket(int connect_port, char *address)\n"
4534 " struct sockaddr_in a;\n"
4539 #: build/C/man2/select_tut.2:595
4542 " if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) {\n"
4543 " perror(\"socket\");\n"
4550 #: build/C/man2/select_tut.2:599
4553 " memset(&a, 0, sizeof(a));\n"
4554 " a.sin_port = htons(connect_port);\n"
4555 " a.sin_family = AF_INET;\n"
4559 #: build/C/man2/select_tut.2:605
4562 " if (!inet_aton(address, (struct in_addr *) &a.sin_addr.s_addr)) {\n"
4563 " perror(\"bad IP address format\");\n"
4570 #: build/C/man2/select_tut.2:614
4573 " if (connect(s, (struct sockaddr *) &a, sizeof(a)) == -1) {\n"
4574 " perror(\"connect()\");\n"
4575 " shutdown(s, SHUT_RDWR);\n"
4584 #: build/C/man2/select_tut.2:622
4587 "#define SHUT_FD1 do { \\e\n"
4588 " if (fd1 E<gt>= 0) { \\e\n"
4589 " shutdown(fd1, SHUT_RDWR); \\e\n"
4590 " close(fd1); \\e\n"
4597 #: build/C/man2/select_tut.2:630
4600 "#define SHUT_FD2 do { \\e\n"
4601 " if (fd2 E<gt>= 0) { \\e\n"
4602 " shutdown(fd2, SHUT_RDWR); \\e\n"
4603 " close(fd2); \\e\n"
4610 #: build/C/man2/select_tut.2:632
4612 msgid "#define BUF_SIZE 1024\n"
4616 #: build/C/man2/select_tut.2:641
4620 "main(int argc, char *argv[])\n"
4623 " int fd1 = -1, fd2 = -1;\n"
4624 " char buf1[BUF_SIZE], buf2[BUF_SIZE];\n"
4625 " int buf1_avail, buf1_written;\n"
4626 " int buf2_avail, buf2_written;\n"
4630 #: build/C/man2/select_tut.2:647
4633 " if (argc != 4) {\n"
4634 " fprintf(stderr, \"Usage\\en\\etfwd E<lt>listen-portE<gt> \"\n"
4635 " \"E<lt>forward-to-portE<gt> "
4636 "E<lt>forward-to-ip-addressE<gt>\\en\");\n"
4637 " exit(EXIT_FAILURE);\n"
4642 #: build/C/man2/select_tut.2:649
4644 msgid " signal(SIGPIPE, SIG_IGN);\n"
4648 #: build/C/man2/select_tut.2:651
4650 msgid " forward_port = atoi(argv[2]);\n"
4654 #: build/C/man2/select_tut.2:655
4657 " h = listen_socket(atoi(argv[1]));\n"
4659 " exit(EXIT_FAILURE);\n"
4663 #: build/C/man2/select_tut.2:659
4667 " int r, nfds = 0;\n"
4668 " fd_set rd, wr, er;\n"
4672 #: build/C/man2/select_tut.2:689
4678 " FD_SET(h, &rd);\n"
4679 " nfds = max(nfds, h);\n"
4680 " if (fd1 E<gt> 0 && buf1_avail E<lt> BUF_SIZE) {\n"
4681 " FD_SET(fd1, &rd);\n"
4682 " nfds = max(nfds, fd1);\n"
4684 " if (fd2 E<gt> 0 && buf2_avail E<lt> BUF_SIZE) {\n"
4685 " FD_SET(fd2, &rd);\n"
4686 " nfds = max(nfds, fd2);\n"
4688 " if (fd1 E<gt> 0 && buf2_avail - buf2_written E<gt> 0) {\n"
4689 " FD_SET(fd1, &wr);\n"
4690 " nfds = max(nfds, fd1);\n"
4692 " if (fd2 E<gt> 0 && buf1_avail - buf1_written E<gt> 0) {\n"
4693 " FD_SET(fd2, &wr);\n"
4694 " nfds = max(nfds, fd2);\n"
4696 " if (fd1 E<gt> 0) {\n"
4697 " FD_SET(fd1, &er);\n"
4698 " nfds = max(nfds, fd1);\n"
4700 " if (fd2 E<gt> 0) {\n"
4701 " FD_SET(fd2, &er);\n"
4702 " nfds = max(nfds, fd2);\n"
4707 #: build/C/man2/select_tut.2:691
4709 msgid " r = select(nfds + 1, &rd, &wr, &er, NULL);\n"
4713 #: build/C/man2/select_tut.2:694
4716 " if (r == -1 && errno == EINTR)\n"
4721 #: build/C/man2/select_tut.2:699
4725 " perror(\"select()\");\n"
4726 " exit(EXIT_FAILURE);\n"
4731 #: build/C/man2/select_tut.2:703
4734 " if (FD_ISSET(h, &rd)) {\n"
4735 " unsigned int l;\n"
4736 " struct sockaddr_in client_address;\n"
4740 #: build/C/man2/select_tut.2:722
4743 " memset(&client_address, 0, l = sizeof(client_address));\n"
4744 " r = accept(h, (struct sockaddr *) &client_address, &l);\n"
4746 " perror(\"accept()\");\n"
4750 " buf1_avail = buf1_written = 0;\n"
4751 " buf2_avail = buf2_written = 0;\n"
4753 " fd2 = connect_socket(forward_port, argv[3]);\n"
4757 " printf(\"connect from %s\\en\",\n"
4758 " inet_ntoa(client_address.sin_addr));\n"
4764 #: build/C/man2/select_tut.2:724
4766 msgid " /* NB: read oob data before normal reads */\n"
4770 #: build/C/man2/select_tut.2:728
4773 " if (fd1 E<gt> 0)\n"
4774 " if (FD_ISSET(fd1, &er)) {\n"
4779 #: build/C/man2/select_tut.2:738
4782 " r = recv(fd1, &c, 1, MSG_OOB);\n"
4786 " send(fd2, &c, 1, MSG_OOB);\n"
4788 " if (fd2 E<gt> 0)\n"
4789 " if (FD_ISSET(fd2, &er)) {\n"
4794 #: build/C/man2/select_tut.2:781
4797 " r = recv(fd2, &c, 1, MSG_OOB);\n"
4801 " send(fd1, &c, 1, MSG_OOB);\n"
4803 " if (fd1 E<gt> 0)\n"
4804 " if (FD_ISSET(fd1, &rd)) {\n"
4805 " r = read(fd1, buf1 + buf1_avail,\n"
4806 " BUF_SIZE - buf1_avail);\n"
4810 " buf1_avail += r;\n"
4812 " if (fd2 E<gt> 0)\n"
4813 " if (FD_ISSET(fd2, &rd)) {\n"
4814 " r = read(fd2, buf2 + buf2_avail,\n"
4815 " BUF_SIZE - buf2_avail);\n"
4819 " buf2_avail += r;\n"
4821 " if (fd1 E<gt> 0)\n"
4822 " if (FD_ISSET(fd1, &wr)) {\n"
4823 " r = write(fd1, buf2 + buf2_written,\n"
4824 " buf2_avail - buf2_written);\n"
4828 " buf2_written += r;\n"
4830 " if (fd2 E<gt> 0)\n"
4831 " if (FD_ISSET(fd2, &wr)) {\n"
4832 " r = write(fd2, buf1 + buf1_written,\n"
4833 " buf1_avail - buf1_written);\n"
4837 " buf1_written += r;\n"
4842 #: build/C/man2/select_tut.2:783
4844 msgid " /* check if write data has caught read data */\n"
4848 #: build/C/man2/select_tut.2:788
4851 " if (buf1_written == buf1_avail)\n"
4852 " buf1_written = buf1_avail = 0;\n"
4853 " if (buf2_written == buf2_avail)\n"
4854 " buf2_written = buf2_avail = 0;\n"
4858 #: build/C/man2/select_tut.2:791
4861 " /* one side has closed the connection, keep\n"
4862 " writing to the other side until empty */\n"
4866 #: build/C/man2/select_tut.2:799
4869 " if (fd1 E<lt> 0 && buf1_avail - buf1_written == 0)\n"
4871 " if (fd2 E<lt> 0 && buf2_avail - buf2_written == 0)\n"
4874 " exit(EXIT_SUCCESS);\n"
4879 #: build/C/man2/select_tut.2:813
4881 "The above program properly forwards most kinds of TCP connections including "
4882 "OOB signal data transmitted by B<telnet> servers. It handles the tricky "
4883 "problem of having data flow in both directions simultaneously. You might "
4884 "think it more efficient to use a B<fork>(2) call and devote a thread to "
4885 "each stream. This becomes more tricky than you might suspect. Another idea "
4886 "is to set nonblocking I/O using B<fcntl>(2). This also has its problems "
4887 "because you end up using inefficient timeouts."
4891 #: build/C/man2/select_tut.2:819
4893 "The program does not handle more than one simultaneous connection at a time, "
4894 "although it could easily be extended to do this with a linked list of "
4895 "buffers\\(emone for each connection. At the moment, new connections cause "
4896 "the current connection to be dropped."
4900 #. This man page was written by Paul Sheer.
4902 #: build/C/man2/select_tut.2:838
4904 "B<accept>(2), B<connect>(2), B<ioctl>(2), B<poll>(2), B<read>(2), "
4905 "B<recv>(2), B<select>(2), B<send>(2), B<sigprocmask>(2), B<write>(2), "
4906 "B<sigaddset>(3), B<sigdelset>(3), B<sigemptyset>(3), B<sigfillset>(3), "
4907 "B<sigismember>(3), B<epoll>(7)"
4911 #: build/C/man2/send.2:40
4917 #: build/C/man2/send.2:40
4923 #: build/C/man2/send.2:43
4924 msgid "send, sendto, sendmsg - send a message on a socket"
4928 #: build/C/man2/send.2:47
4931 "B<#include E<lt>sys/types.hE<gt>>\n"
4932 "B<#include E<lt>sys/socket.hE<gt>>\n"
4936 #: build/C/man2/send.2:50
4939 "B<ssize_t send(int >I<sockfd>B<, const void *>I<buf>B<, size_t >I<len>B<, "
4940 "int >I<flags>B<);>\n"
4944 #: build/C/man2/send.2:54
4947 "B<ssize_t sendto(int >I<sockfd>B<, const void *>I<buf>B<, size_t >I<len>B<, "
4948 "int >I<flags>B<,>\n"
4949 "B< const struct sockaddr *>I<dest_addr>B<, socklen_t "
4950 ">I<addrlen>B<);>\n"
4954 #: build/C/man2/send.2:57
4957 "B<ssize_t sendmsg(int >I<sockfd>B<, const struct msghdr *>I<msg>B<, int "
4962 #: build/C/man2/send.2:65
4964 "The system calls B<send>(), B<sendto>(), and B<sendmsg>() are used to "
4965 "transmit a message to another socket."
4969 #: build/C/man2/send.2:84
4971 "The B<send>() call may be used only when the socket is in a I<connected> "
4972 "state (so that the intended recipient is known). The only difference "
4973 "between B<send>() and B<write>(2) is the presence of I<flags>. With a "
4974 "zero I<flags> argument, B<send>() is equivalent to B<write>(2). Also, the "
4979 #: build/C/man2/send.2:86
4981 msgid " send(sockfd, buf, len, flags);\n"
4985 #: build/C/man2/send.2:88
4986 msgid "is equivalent to"
4990 #: build/C/man2/send.2:90
4992 msgid " sendto(sockfd, buf, len, flags, NULL, 0);\n"
4996 #: build/C/man2/send.2:94
4997 msgid "The argument I<sockfd> is the file descriptor of the sending socket."
5001 #: build/C/man2/send.2:122
5003 "If B<sendto>() is used on a connection-mode (B<SOCK_STREAM>, "
5004 "B<SOCK_SEQPACKET>) socket, the arguments I<dest_addr> and I<addrlen> are "
5005 "ignored (and the error B<EISCONN> may be returned when they are not NULL and "
5006 "0), and the error B<ENOTCONN> is returned when the socket was not actually "
5007 "connected. Otherwise, the address of the target is given by I<dest_addr> "
5008 "with I<addrlen> specifying its size. For B<sendmsg>(), the address of the "
5009 "target is given by I<msg.msg_name>, with I<msg.msg_namelen> specifying its "
5014 #: build/C/man2/send.2:138
5016 "For B<send>() and B<sendto>(), the message is found in I<buf> and has "
5017 "length I<len>. For B<sendmsg>(), the message is pointed to by the elements "
5018 "of the array I<msg.msg_iov>. The B<sendmsg>() call also allows sending "
5019 "ancillary data (also known as control information)."
5023 #: build/C/man2/send.2:143
5025 "If the message is too long to pass atomically through the underlying "
5026 "protocol, the error B<EMSGSIZE> is returned, and the message is not "
5031 #: build/C/man2/send.2:147
5033 "No indication of failure to deliver is implicit in a B<send>(). Locally "
5034 "detected errors are indicated by a return value of -1."
5038 #: build/C/man2/send.2:160
5040 "When the message does not fit into the send buffer of the socket, B<send>() "
5041 "normally blocks, unless the socket has been placed in nonblocking I/O mode. "
5042 "In nonblocking mode it would fail with the error B<EAGAIN> or B<EWOULDBLOCK> "
5043 "in this case. The B<select>(2) call may be used to determine when it is "
5044 "possible to send more data."
5047 #. FIXME ? document MSG_PROXY (which went away in 2.3.15)
5049 #: build/C/man2/send.2:166
5051 "The I<flags> argument is the bitwise OR of zero or more of the following "
5056 #: build/C/man2/send.2:166
5058 msgid "B<MSG_CONFIRM> (Since Linux 2.3.15)"
5062 #: build/C/man2/send.2:180
5064 "Tell the link layer that forward progress happened: you got a successful "
5065 "reply from the other side. If the link layer doesn't get this it will "
5066 "regularly reprobe the neighbor (e.g., via a unicast ARP). Only valid on "
5067 "B<SOCK_DGRAM> and B<SOCK_RAW> sockets and currently only implemented for "
5068 "IPv4 and IPv6. See B<arp>(7) for details."
5072 #: build/C/man2/send.2:180
5074 msgid "B<MSG_DONTROUTE>"
5078 #: build/C/man2/send.2:188
5080 "Don't use a gateway to send out the packet, only send to hosts on directly "
5081 "connected networks. This is usually used only by diagnostic or routing "
5082 "programs. This is only defined for protocol families that route; packet "
5087 #: build/C/man2/send.2:199
5089 "Enables nonblocking operation; if the operation would block, B<EAGAIN> or "
5090 "B<EWOULDBLOCK> is returned (this can also be enabled using the B<O_NONBLOCK> "
5091 "flag with the B<F_SETFL> B<fcntl>(2))."
5095 #: build/C/man2/send.2:199
5097 msgid "B<MSG_EOR> (since Linux 2.2)"
5101 #: build/C/man2/send.2:203
5103 "Terminates a record (when this notion is supported, as for sockets of type "
5104 "B<SOCK_SEQPACKET>)."
5108 #: build/C/man2/send.2:203
5110 msgid "B<MSG_MORE> (Since Linux 2.4.4)"
5114 #: build/C/man2/send.2:212
5116 "The caller has more data to send. This flag is used with TCP sockets to "
5117 "obtain the same effect as the B<TCP_CORK> socket option (see B<tcp>(7)), "
5118 "with the difference that this flag can be set on a per-call basis."
5122 #: build/C/man2/send.2:221
5124 "Since Linux 2.6, this flag is also supported for UDP sockets, and informs "
5125 "the kernel to package all of the data sent in calls with this flag set into "
5126 "a single datagram which is only transmitted when a call is performed that "
5127 "does not specify this flag. (See also the B<UDP_CORK> socket option "
5128 "described in B<udp>(7).)"
5132 #: build/C/man2/send.2:221
5134 msgid "B<MSG_NOSIGNAL> (since Linux 2.2)"
5138 #: build/C/man2/send.2:230
5140 "Requests not to send B<SIGPIPE> on errors on stream oriented sockets when "
5141 "the other end breaks the connection. The B<EPIPE> error is still returned."
5145 #: build/C/man2/send.2:239
5147 "Sends I<out-of-band> data on sockets that support this notion (e.g., of type "
5148 "B<SOCK_STREAM>); the underlying protocol must also support I<out-of-band> "
5153 #: build/C/man2/send.2:246
5155 "The definition of the I<msghdr> structure follows. See B<recv>(2) and "
5156 "below for an exact description of its fields."
5159 #. Still to be documented:
5160 #. Send file descriptors and user credentials using the
5161 #. msg_control* fields.
5162 #. The flags returned in msg_flags.
5164 #: build/C/man2/send.2:275
5166 "You may send control information using the I<msg_control> and "
5167 "I<msg_controllen> members. The maximum control buffer length the kernel can "
5168 "process is limited per socket by the value in "
5169 "I</proc/sys/net/core/optmem_max>; see B<socket>(7)."
5173 #: build/C/man2/send.2:280
5175 "On success, these calls return the number of characters sent. On error, -1 "
5176 "is returned, and I<errno> is set appropriately."
5180 #: build/C/man2/send.2:285
5182 "These are some standard errors generated by the socket layer. Additional "
5183 "errors may be generated and returned from the underlying protocol modules; "
5184 "see their respective manual pages."
5188 #: build/C/man2/send.2:293
5190 "(For UNIX domain sockets, which are identified by pathname) Write "
5191 "permission is denied on the destination socket file, or search permission is "
5192 "denied for one of the directories the path prefix. (See "
5193 "B<path_resolution>(7).)"
5197 #: build/C/man2/send.2:296
5199 "(For UDP sockets) An attempt was made to send to a network/broadcast address "
5200 "as though it was a unicast address."
5203 #. Actually EAGAIN on Linux
5205 #: build/C/man2/send.2:304
5207 "The socket is marked nonblocking and the requested operation would block. "
5208 "POSIX.1-2001 allows either error to be returned for this case, and does not "
5209 "require these constants to have the same value, so a portable application "
5210 "should check for both possibilities."
5214 #: build/C/man2/send.2:307
5215 msgid "An invalid descriptor was specified."
5219 #: build/C/man2/send.2:307
5221 msgid "B<ECONNRESET>"
5225 #: build/C/man2/send.2:310
5226 msgid "Connection reset by peer."
5230 #: build/C/man2/send.2:310
5232 msgid "B<EDESTADDRREQ>"
5236 #: build/C/man2/send.2:313
5237 msgid "The socket is not connection-mode, and no peer address is set."
5241 #: build/C/man2/send.2:316
5242 msgid "An invalid user space address was specified for an argument."
5246 #: build/C/man2/send.2:320
5247 msgid "A signal occurred before any data was transmitted; see B<signal>(7)."
5251 #: build/C/man2/send.2:329
5253 "The connection-mode socket was connected already but a recipient was "
5254 "specified. (Now either this error is returned, or the recipient "
5255 "specification is ignored.)"
5259 #: build/C/man2/send.2:329
5264 #. (e.g., SOCK_DGRAM )
5266 #: build/C/man2/send.2:335
5268 "The socket type requires that message be sent atomically, and the size of "
5269 "the message to be sent made this impossible."
5273 #: build/C/man2/send.2:343
5275 "The output queue for a network interface was full. This generally indicates "
5276 "that the interface has stopped sending, but may be caused by transient "
5277 "congestion. (Normally, this does not occur in Linux. Packets are just "
5278 "silently dropped when a device queue overflows.)"
5282 #: build/C/man2/send.2:346
5283 msgid "No memory available."
5287 #: build/C/man2/send.2:349
5288 msgid "The socket is not connected, and no target has been given."
5292 #: build/C/man2/send.2:359
5293 msgid "Some bit in the I<flags> argument is inappropriate for the socket type."
5297 #: build/C/man2/send.2:359
5303 #: build/C/man2/send.2:368
5305 "The local end has been shut down on a connection oriented socket. In this "
5306 "case the process will also receive a B<SIGPIPE> unless B<MSG_NOSIGNAL> is "
5311 #: build/C/man2/send.2:371
5312 msgid "4.4BSD, SVr4, POSIX.1-2001. These function calls appeared in 4.2BSD."
5316 #: build/C/man2/send.2:382
5318 "POSIX.1-2001 only describes the B<MSG_OOB> and B<MSG_EOR> flags. "
5319 "POSIX.1-2008 adds a specification of B<MSG_NOSIGNAL>. The B<MSG_CONFIRM> "
5320 "flag is a Linux extension."
5324 #: build/C/man2/send.2:395
5326 "The prototypes given above follow the Single UNIX Specification, as glibc2 "
5327 "also does; the I<flags> argument was I<int> in 4.x BSD, but I<unsigned int> "
5328 "in libc4 and libc5; the I<len> argument was I<int> in 4.x BSD and libc4, but "
5329 "I<size_t> in libc5; the I<addrlen> argument was I<int> in 4.x BSD and libc4 "
5330 "and libc5. See also B<accept>(2)."
5334 #: build/C/man2/send.2:414
5336 "See B<sendmmsg>(2) for information about a Linux-specific system call that "
5337 "can be used to transmit multiple datagrams in a single call."
5341 #: build/C/man2/send.2:419
5342 msgid "Linux may return B<EPIPE> instead of B<ENOTCONN>."
5346 #: build/C/man2/send.2:424
5347 msgid "An example of the use of B<sendto>() is shown in B<getaddrinfo>(3)."
5351 #: build/C/man2/send.2:439
5353 "B<fcntl>(2), B<getsockopt>(2), B<recv>(2), B<select>(2), B<sendfile>(2), "
5354 "B<sendmmsg>(2), B<shutdown>(2), B<socket>(2), B<write>(2), B<cmsg>(3), "
5355 "B<ip>(7), B<socket>(7), B<tcp>(7), B<udp>(7)"
5359 #: build/C/man2/sendmmsg.2:28
5365 #: build/C/man2/sendmmsg.2:28
5371 #: build/C/man2/sendmmsg.2:31
5372 msgid "sendmmsg - send multiple messages on a socket"
5376 #: build/C/man2/sendmmsg.2:39
5379 "B<int sendmmsg(int >I<sockfd>B<, struct mmsghdr *>I<msgvec>B<, unsigned int "
5381 "B< unsigned int >I<flags>B<);>\n"
5384 #. See commit 228e548e602061b08ee8e8966f567c12aa079682
5386 #: build/C/man2/sendmmsg.2:49
5388 "The B<sendmmsg>() system call is an extension of B<sendmsg>(2) that allows "
5389 "the caller to transmit multiple messages on a socket using a single system "
5390 "call. (This has performance benefits for some applications.)"
5394 #: build/C/man2/sendmmsg.2:54
5396 "The I<sockfd> argument is the file descriptor of the socket on which data is "
5397 "to be transmitted."
5401 #: build/C/man2/sendmmsg.2:75
5404 "struct mmsghdr {\n"
5405 " struct msghdr msg_hdr; /* Message header */\n"
5406 " unsigned int msg_len; /* Number of bytes transmitted */\n"
5411 #: build/C/man2/sendmmsg.2:91
5413 "The I<msg_hdr> field is a I<msghdr> structure, as described in "
5414 "B<sendmsg>(2). The I<msg_len> field is used to return the number of bytes "
5415 "sent from the message in I<msg_hdr> (i.e., the same as the return value from "
5416 "a single B<sendmsg>(2) call)."
5420 #: build/C/man2/sendmmsg.2:97
5422 "The I<flags> argument contains flags ORed together. The flags are the same "
5423 "as for B<sendmsg>(2)."
5427 #: build/C/man2/sendmmsg.2:107
5429 "A blocking B<sendmmsg>() call blocks until I<vlen> messages have been "
5430 "sent. A nonblocking call sends as many messages as possible (up to the "
5431 "limit specified by I<vlen>) and returns immediately."
5435 #: build/C/man2/sendmmsg.2:119
5437 "On return from B<sendmmsg>(), the I<msg_len> fields of successive elements "
5438 "of I<msgvec> are updated to contain the number of bytes transmitted from the "
5439 "corresponding I<msg_hdr>. The return value of the call indicates the number "
5440 "of elements of I<msgvec> that have been updated."
5444 #: build/C/man2/sendmmsg.2:129
5446 "On success, B<sendmmsg>() returns the number of messages sent from "
5447 "I<msgvec>; if this is less than I<vlen>, the caller can retry with a further "
5448 "B<sendmmsg>() call to send the remaining messages."
5452 #: build/C/man2/sendmmsg.2:133
5453 msgid "On error, -1 is returned, and I<errno> is set to indicate the error."
5456 #. commit 728ffb86f10873aaf4abd26dde691ee40ae731fe
5457 #. ... only return an error if no datagrams could be sent.
5458 #. If less than the requested number of messages were sent, the application
5459 #. must retry starting at the first failed one and if the problem is
5460 #. persistent the error will be returned.
5462 #. This matches the behaviour of other syscalls like read/write - it
5463 #. is not an error if less than the requested number of elements are sent.
5465 #: build/C/man2/sendmmsg.2:145
5467 "Errors are as for B<sendmsg>(2). An error is returned only if no datagrams "
5472 #: build/C/man2/sendmmsg.2:150
5474 "The B<sendmmsg>() system call was added in Linux 3.0. Support in glibc was "
5475 "added in version 2.14."
5479 #: build/C/man2/sendmmsg.2:153
5480 msgid "B<sendmmsg>() is Linux-specific."
5483 #. commit 98382f419f32d2c12d021943b87dea555677144b
5484 #. net: Cap number of elements for sendmmsg
5486 #. To limit the amount of time we can spend in sendmmsg, cap the
5487 #. number of elements to UIO_MAXIOV (currently 1024).
5489 #. For error handling an application using sendmmsg needs to retry at
5490 #. the first unsent message, so capping is simpler and requires less
5491 #. application logic than returning EINVAL.
5493 #: build/C/man2/sendmmsg.2:168
5494 msgid "The value specified in I<vlen> is capped to B<UIO_MAXIOV> (1024)."
5498 #: build/C/man2/sendmmsg.2:177
5500 "The example below uses B<sendmmsg>() to send I<onetwo> and I<three> in two "
5501 "distinct UDP datagrams using one system call. The contents of the first "
5502 "datagram originates from a pair of buffers."
5506 #: build/C/man2/sendmmsg.2:186
5509 "#define _GNU_SOURCE\n"
5510 "#include E<lt>netinet/ip.hE<gt>\n"
5511 "#include E<lt>stdio.hE<gt>\n"
5512 "#include E<lt>stdlib.hE<gt>\n"
5513 "#include E<lt>string.hE<gt>\n"
5514 "#include E<lt>sys/types.hE<gt>\n"
5515 "#include E<lt>sys/socket.hE<gt>\n"
5519 #: build/C/man2/sendmmsg.2:195
5526 " struct sockaddr_in sa;\n"
5527 " struct mmsghdr msg[2];\n"
5528 " struct iovec msg1[2], msg2;\n"
5533 #: build/C/man2/sendmmsg.2:209
5536 " sa.sin_family = AF_INET;\n"
5537 " sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);\n"
5538 " sa.sin_port = htons(1234);\n"
5539 " if (connect(sockfd, (struct sockaddr *) &sa, sizeof(sa)) == -1) {\n"
5540 " perror(\"connect()\");\n"
5541 " exit(EXIT_FAILURE);\n"
5546 #: build/C/man2/sendmmsg.2:215
5549 " memset(msg1, 0, sizeof(msg1));\n"
5550 " msg1[0].iov_base = \"one\";\n"
5551 " msg1[0].iov_len = 3;\n"
5552 " msg1[1].iov_base = \"two\";\n"
5553 " msg1[1].iov_len = 3;\n"
5557 #: build/C/man2/sendmmsg.2:219
5560 " memset(&msg2, 0, sizeof(msg2));\n"
5561 " msg2.iov_base = \"three\";\n"
5562 " msg2.iov_len = 5;\n"
5566 #: build/C/man2/sendmmsg.2:223
5569 " memset(msg, 0, sizeof(msg));\n"
5570 " msg[0].msg_hdr.msg_iov = msg1;\n"
5571 " msg[0].msg_hdr.msg_iovlen = 2;\n"
5575 #: build/C/man2/sendmmsg.2:226
5578 " msg[1].msg_hdr.msg_iov = &msg2;\n"
5579 " msg[1].msg_hdr.msg_iovlen = 1;\n"
5583 #: build/C/man2/sendmmsg.2:232
5586 " retval = sendmmsg(sockfd, msg, 2, 0);\n"
5587 " if (retval == -1)\n"
5588 " perror(\"sendmmsg()\");\n"
5590 " printf(\"%d messages sent\\en\", retval);\n"
5594 #: build/C/man2/sendmmsg.2:235
5602 #: build/C/man2/sendmmsg.2:241
5603 msgid "B<recvmmsg>(2), B<sendmsg>(2), B<socket>(2), B<socket>(7)"
5607 #: build/C/man3/sockatmark.3:25
5613 #: build/C/man3/sockatmark.3:28
5614 msgid "sockatmark - determine whether socket is at out-of-band mark"
5618 #: build/C/man3/sockatmark.3:30 build/C/man2/socket.2:50 build/C/man7/socket.7:53 build/C/man2/socketpair.2:49
5619 msgid "B<#include E<lt>sys/socket.hE<gt>>"
5623 #: build/C/man3/sockatmark.3:32
5624 msgid "B<int sockatmark(int >I<sockfd>B<);>"
5628 #: build/C/man3/sockatmark.3:41
5630 "B<sockatmark>(): _POSIX_C_SOURCE\\ E<gt>=\\ 200112L || _XOPEN_SOURCE\\ "
5635 #: build/C/man3/sockatmark.3:51
5637 "B<sockatmark>() returns a value indicating whether or not the socket "
5638 "referred to by the file descriptor I<sockfd> is at the out-of-band mark. If "
5639 "the socket is at the mark, then 1 is returned; if the socket is not at the "
5640 "mark, 0 is returned. This function does not remove the out-of-band mark."
5644 #: build/C/man3/sockatmark.3:56
5646 "A successful call to B<sockatmark>() returns 1 if the socket is at the "
5647 "out-of-band mark, or 0 if it is not. On error, -1 is returned and I<errno> "
5648 "is set to indicate the error."
5652 #: build/C/man3/sockatmark.3:61
5653 msgid "I<sockfd> is not a valid file descriptor."
5656 #. POSIX.1 says ENOTTY for this case
5658 #: build/C/man3/sockatmark.3:68
5659 msgid "I<sockfd> is not a file descriptor to which B<sockatmark>() can be applied."
5663 #: build/C/man3/sockatmark.3:71
5664 msgid "B<sockatmark>() was added to glibc in version 2.2.4."
5668 #: build/C/man3/sockatmark.3:73
5669 msgid "POSIX.1-2001."
5673 #: build/C/man3/sockatmark.3:80
5675 "If B<sockatmark>() returns 1, then the out-of-band data can be read using "
5676 "the B<MSG_OOB> flag of B<recv>(2)."
5680 #: build/C/man3/sockatmark.3:82
5681 msgid "Out-of-band data is only supported on some stream socket protocols."
5685 #: build/C/man3/sockatmark.3:87
5687 "B<sockatmark>() can safely be called from a handler for the B<SIGURG> "
5692 #: build/C/man3/sockatmark.3:93
5694 "B<sockatmark>() is implemented using the B<SIOCATMARK> B<ioctl>(2) "
5699 #: build/C/man3/sockatmark.3:97
5700 msgid "Prior to glibc 2.4, B<sockatmark>() did not work."
5704 #: build/C/man3/sockatmark.3:102
5706 "The following code can be used after receipt of a B<SIGURG> signal to read "
5707 "(and discard) all data up to the mark, and then read the byte of data at the "
5712 #: build/C/man3/sockatmark.3:107
5715 " char buf[BUF_LEN];\n"
5721 #: build/C/man3/sockatmark.3:114
5725 " atmark = sockatmark(sockfd);\n"
5726 " if (atmark == -1) {\n"
5727 " perror(\"sockatmark\");\n"
5733 #: build/C/man3/sockatmark.3:117
5741 #: build/C/man3/sockatmark.3:124
5744 " s = read(sockfd, buf, BUF_LEN) E<lt>= 0);\n"
5746 " perror(\"read\");\n"
5747 " if (s E<lt>= 0)\n"
5753 #: build/C/man3/sockatmark.3:131
5756 " if (atmark == 1) {\n"
5757 " if (recv(sockfd, &oobdata, 1, MSG_OOB) == -1) {\n"
5758 " perror(\"recv\");\n"
5765 #: build/C/man3/sockatmark.3:137
5766 msgid "B<fcntl>(2), B<recv>(2), B<send>(2), B<tcp>(7)"
5770 #: build/C/man2/socket.2:43 build/C/man7/socket.7:48
5776 #: build/C/man2/socket.2:43
5782 #: build/C/man2/socket.2:46
5783 msgid "socket - create an endpoint for communication"
5787 #: build/C/man2/socket.2:48 build/C/man2/socketpair.2:47
5788 msgid "B<#include E<lt>sys/types.hE<gt>> /* See NOTES */"
5792 #: build/C/man2/socket.2:52
5793 msgid "B<int socket(int >I<domain>B<, int >I<type>B<, int >I<protocol>B<);>"
5797 #: build/C/man2/socket.2:55
5798 msgid "B<socket>() creates an endpoint for communication and returns a descriptor."
5802 #: build/C/man2/socket.2:63
5804 "The I<domain> argument specifies a communication domain; this selects the "
5805 "protocol family which will be used for communication. These families are "
5806 "defined in I<E<lt>sys/socket.hE<gt>>. The currently understood formats "
5811 #: build/C/man2/socket.2:66
5813 msgid "Name:Purpose:Man page\n"
5817 #: 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
5823 #: build/C/man2/socket.2:68
5825 msgid "B<AF_UNIX>, B<AF_LOCAL>\n"
5829 #: 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:184
5835 #: build/C/man2/socket.2:70
5837 msgid "Local communication\n"
5841 #: build/C/man2/socket.2:72
5843 msgid "B<unix>(7)\n"
5847 #: 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:163 build/C/man7/socket.7:167 build/C/man7/socket.7:170 build/C/man7/socket.7:176 build/C/man7/socket.7:179 build/C/man7/socket.7:188 build/C/man7/socket.7:195
5853 #: build/C/man2/socket.2:75
5855 msgid "B<AF_INET>\n"
5859 #: build/C/man2/socket.2:76
5861 msgid "T}:IPv4 Internet protocols:T{\n"
5865 #: build/C/man2/socket.2:77
5871 #: build/C/man2/socket.2:80
5873 msgid "B<AF_INET6>\n"
5877 #: build/C/man2/socket.2:81
5879 msgid "T}:IPv6 Internet protocols:T{\n"
5883 #: build/C/man2/socket.2:82
5885 msgid "B<ipv6>(7)\n"
5889 #: build/C/man2/socket.2:85
5895 #: build/C/man2/socket.2:86
5897 msgid "T}:IPX - Novell protocols:\n"
5901 #: build/C/man2/socket.2:88
5903 msgid "B<AF_NETLINK>\n"
5907 #: build/C/man2/socket.2:90
5909 msgid "Kernel user interface device\n"
5913 #: build/C/man2/socket.2:92
5915 msgid "B<netlink>(7)\n"
5919 #: build/C/man2/socket.2:95
5925 #: build/C/man2/socket.2:96
5927 msgid "T}:ITU-T X.25 / ISO-8208 protocol:T{\n"
5931 #: build/C/man2/socket.2:97
5937 #: build/C/man2/socket.2:100
5939 msgid "B<AF_AX25>\n"
5943 #: build/C/man2/socket.2:102
5945 msgid "Amateur radio AX.25 protocol\n"
5949 #: build/C/man2/socket.2:103
5955 #: build/C/man2/socket.2:105
5957 msgid "B<AF_ATMPVC>\n"
5961 #: build/C/man2/socket.2:106
5963 msgid "T}:Access to raw ATM PVCs:\n"
5967 #: build/C/man2/socket.2:108
5969 msgid "B<AF_APPLETALK>\n"
5973 #: build/C/man2/socket.2:109
5975 msgid "T}:Appletalk:T{\n"
5979 #: build/C/man2/socket.2:110
5985 #: build/C/man2/socket.2:113
5987 msgid "B<AF_PACKET>\n"
5991 #: build/C/man2/socket.2:115
5993 msgid "Low level packet interface\n"
5997 #: build/C/man2/socket.2:117
5999 msgid "B<packet>(7)\n"
6003 #: build/C/man2/socket.2:126
6005 "The socket has the indicated I<type>, which specifies the communication "
6006 "semantics. Currently defined types are:"
6010 #: build/C/man2/socket.2:126
6012 msgid "B<SOCK_STREAM>"
6016 #: build/C/man2/socket.2:130
6018 "Provides sequenced, reliable, two-way, connection-based byte streams. An "
6019 "out-of-band data transmission mechanism may be supported."
6023 #: build/C/man2/socket.2:130
6025 msgid "B<SOCK_DGRAM>"
6029 #: build/C/man2/socket.2:134
6031 "Supports datagrams (connectionless, unreliable messages of a fixed maximum "
6036 #: build/C/man2/socket.2:134
6038 msgid "B<SOCK_SEQPACKET>"
6042 #: build/C/man2/socket.2:139
6044 "Provides a sequenced, reliable, two-way connection-based data transmission "
6045 "path for datagrams of fixed maximum length; a consumer is required to read "
6046 "an entire packet with each input system call."
6050 #: build/C/man2/socket.2:139
6056 #: build/C/man2/socket.2:142
6057 msgid "Provides raw network protocol access."
6061 #: build/C/man2/socket.2:142
6067 #: build/C/man2/socket.2:145
6068 msgid "Provides a reliable datagram layer that does not guarantee ordering."
6072 #: build/C/man2/socket.2:145
6074 msgid "B<SOCK_PACKET>"
6078 #: build/C/man2/socket.2:150
6079 msgid "Obsolete and should not be used in new programs; see B<packet>(7)."
6083 #: build/C/man2/socket.2:156
6085 "Some socket types may not be implemented by all protocol families; for "
6086 "example, B<SOCK_SEQPACKET> is not implemented for B<AF_INET>."
6090 #: build/C/man2/socket.2:164
6092 "Since Linux 2.6.27, the I<type> argument serves a second purpose: in "
6093 "addition to specifying a socket type, it may include the bitwise OR of any "
6094 "of the following values, to modify the behavior of B<socket>():"
6098 #: build/C/man2/socket.2:198
6100 "The I<protocol> specifies a particular protocol to be used with the socket. "
6101 "Normally only a single protocol exists to support a particular socket type "
6102 "within a given protocol family, in which case I<protocol> can be specified "
6103 "as 0. However, it is possible that many protocols may exist, in which case "
6104 "a particular protocol must be specified in this manner. The protocol number "
6105 "to use is specific to the ``communication domain'' in which communication is "
6106 "to take place; see B<protocols>(5). See B<getprotoent>(3) on how to map "
6107 "protocol name strings to protocol numbers."
6111 #: build/C/man2/socket.2:228
6113 "Sockets of type B<SOCK_STREAM> are full-duplex byte streams, similar to "
6114 "pipes. They do not preserve record boundaries. A stream socket must be in "
6115 "a I<connected> state before any data may be sent or received on it. A "
6116 "connection to another socket is created with a B<connect>(2) call. Once "
6117 "connected, data may be transferred using B<read>(2) and B<write>(2) calls "
6118 "or some variant of the B<send>(2) and B<recv>(2) calls. When a session "
6119 "has been completed a B<close>(2) may be performed. Out-of-band data may "
6120 "also be transmitted as described in B<send>(2) and received as described in "
6125 #: build/C/man2/socket.2:254
6127 "The communications protocols which implement a B<SOCK_STREAM> ensure that "
6128 "data is not lost or duplicated. If a piece of data for which the peer "
6129 "protocol has buffer space cannot be successfully transmitted within a "
6130 "reasonable length of time, then the connection is considered to be dead. "
6131 "When B<SO_KEEPALIVE> is enabled on the socket the protocol checks in a "
6132 "protocol-specific manner if the other end is still alive. A B<SIGPIPE> "
6133 "signal is raised if a process sends or receives on a broken stream; this "
6134 "causes naive processes, which do not handle the signal, to exit. "
6135 "B<SOCK_SEQPACKET> sockets employ the same system calls as B<SOCK_STREAM> "
6136 "sockets. The only difference is that B<read>(2) calls will return only the "
6137 "amount of data requested, and any data remaining in the arriving packet will "
6138 "be discarded. Also all message boundaries in incoming datagrams are "
6143 #: build/C/man2/socket.2:264
6145 "B<SOCK_DGRAM> and B<SOCK_RAW> sockets allow sending of datagrams to "
6146 "correspondents named in B<sendto>(2) calls. Datagrams are generally "
6147 "received with B<recvfrom>(2), which returns the next datagram along with the "
6148 "address of its sender."
6152 #: build/C/man2/socket.2:271
6154 "B<SOCK_PACKET> is an obsolete socket type to receive raw packets directly "
6155 "from the device driver. Use B<packet>(7) instead."
6159 #: build/C/man2/socket.2:294
6161 "An B<fcntl>(2) B<F_SETOWN> operation can be used to specify a process or "
6162 "process group to receive a B<SIGURG> signal when the out-of-band data "
6163 "arrives or B<SIGPIPE> signal when a B<SOCK_STREAM> connection breaks "
6164 "unexpectedly. This operation may also be used to set the process or process "
6165 "group that receives the I/O and asynchronous notification of I/O events via "
6166 "B<SIGIO>. Using B<F_SETOWN> is equivalent to an B<ioctl>(2) call with the "
6167 "B<FIOSETOWN> or B<SIOCSPGRP> argument."
6171 #: build/C/man2/socket.2:304
6173 "When the network signals an error condition to the protocol module (e.g., "
6174 "using a ICMP message for IP) the pending error flag is set for the socket. "
6175 "The next operation on this socket will return the error code of the pending "
6176 "error. For some protocols it is possible to enable a per-socket error queue "
6177 "to retrieve detailed information about the error; see B<IP_RECVERR> in "
6182 #: build/C/man2/socket.2:314
6184 "The operation of sockets is controlled by socket level I<options>. These "
6185 "options are defined in I<E<lt>sys/socket.hE<gt>>. The functions "
6186 "B<setsockopt>(2) and B<getsockopt>(2) are used to set and get options, "
6191 #: build/C/man2/socket.2:319
6193 "On success, a file descriptor for the new socket is returned. On error, -1 "
6194 "is returned, and I<errno> is set appropriately."
6198 #: build/C/man2/socket.2:324
6200 "Permission to create a socket of the specified type and/or protocol is "
6205 #: build/C/man2/socket.2:327
6206 msgid "The implementation does not support the specified address family."
6210 #: build/C/man2/socket.2:330
6211 msgid "Unknown protocol, or protocol family not available."
6214 #. Since Linux 2.6.27
6216 #: build/C/man2/socket.2:335
6217 msgid "Invalid flags in I<type>."
6221 #: build/C/man2/socket.2:338
6222 msgid "Process file table overflow."
6226 #: build/C/man2/socket.2:341
6228 msgid "B<ENOBUFS> or B<ENOMEM>"
6232 #: build/C/man2/socket.2:346
6234 "Insufficient memory is available. The socket cannot be created until "
6235 "sufficient resources are freed."
6239 #: build/C/man2/socket.2:346 build/C/man2/socketpair.2:92
6241 msgid "B<EPROTONOSUPPORT>"
6245 #: build/C/man2/socket.2:350
6247 "The protocol type or the specified protocol is not supported within this "
6252 #: build/C/man2/socket.2:352
6253 msgid "Other errors may be generated by the underlying protocol modules."
6257 #: build/C/man2/socket.2:354
6258 msgid "4.4BSD, POSIX.1-2001."
6262 #: build/C/man2/socket.2:360
6263 msgid "The B<SOCK_NONBLOCK> and B<SOCK_CLOEXEC> flags are Linux-specific."
6267 #: build/C/man2/socket.2:366
6269 "B<socket>() appeared in 4.2BSD. It is generally portable to/from non-BSD "
6270 "systems supporting clones of the BSD socket layer (including System V "
6275 #: build/C/man2/socket.2:385
6277 "The manifest constants used under 4.x BSD for protocol families are "
6278 "B<PF_UNIX>, B<PF_INET>, and so on, while B<AF_UNIX>, B<AF_INET>, and so on "
6279 "are used for address families. However, already the BSD man page promises: "
6280 "\"The protocol family generally is the same as the address family\", and "
6281 "subsequent standards use AF_* everywhere."
6285 #: build/C/man2/socket.2:390
6286 msgid "An example of the use of B<socket>() is shown in B<getaddrinfo>(3)."
6290 #: build/C/man2/socket.2:413
6292 "B<accept>(2), B<bind>(2), B<connect>(2), B<fcntl>(2), B<getpeername>(2), "
6293 "B<getsockname>(2), B<getsockopt>(2), B<ioctl>(2), B<listen>(2), B<read>(2), "
6294 "B<recv>(2), B<select>(2), B<send>(2), B<shutdown>(2), B<socketpair>(2), "
6295 "B<write>(2), B<getprotoent>(3), B<ip>(7), B<socket>(7), B<tcp>(7), "
6296 "B<udp>(7), B<unix>(7)"
6300 #: build/C/man2/socket.2:419
6302 "\\(lqAn Introductory 4.3BSD Interprocess Communication Tutorial\\(rq and "
6303 "\\(lqBSD Interprocess Communication Tutorial\\(rq, reprinted in I<UNIX "
6304 "Programmer's Supplementary Documents Volume 1.>"
6308 #: build/C/man7/socket.7:48
6314 #: build/C/man7/socket.7:51
6315 msgid "socket - Linux socket interface"
6319 #: build/C/man7/socket.7:55
6321 "I<sockfd>B< = socket(int >I<socket_family>B<, int >I<socket_type>B<, int "
6326 #: build/C/man7/socket.7:74
6328 "This manual page describes the Linux networking socket layer user "
6329 "interface. The BSD compatible sockets are the uniform interface between the "
6330 "user process and the network protocol stacks in the kernel. The protocol "
6331 "modules are grouped into I<protocol families> like B<AF_INET>, B<AF_IPX>, "
6332 "B<AF_PACKET> and I<socket types> like B<SOCK_STREAM> or B<SOCK_DGRAM>. See "
6333 "B<socket>(2) for more information on families and types."
6337 #: build/C/man7/socket.7:74
6339 msgid "Socket-layer functions"
6343 #: build/C/man7/socket.7:78
6345 "These functions are used by the user process to send or receive packets and "
6346 "to do other socket operations. For more information see their respective "
6351 #: build/C/man7/socket.7:94
6353 "B<socket>(2) creates a socket, B<connect>(2) connects a socket to a remote "
6354 "socket address, the B<bind>(2) function binds a socket to a local socket "
6355 "address, B<listen>(2) tells the socket that new connections shall be "
6356 "accepted, and B<accept>(2) is used to get a new socket with a new incoming "
6357 "connection. B<socketpair>(2) returns two connected anonymous sockets (only "
6358 "implemented for a few local families like B<AF_UNIX>)"
6362 #: build/C/man7/socket.7:116
6364 "B<send>(2), B<sendto>(2), and B<sendmsg>(2) send data over a socket, and "
6365 "B<recv>(2), B<recvfrom>(2), B<recvmsg>(2) receive data from a socket. "
6366 "B<poll>(2) and B<select>(2) wait for arriving data or a readiness to send "
6367 "data. In addition, the standard I/O operations like B<write>(2), "
6368 "B<writev>(2), B<sendfile>(2), B<read>(2), and B<readv>(2) can be used to "
6369 "read and write data."
6373 #: build/C/man7/socket.7:127
6375 "B<getsockname>(2) returns the local socket address and B<getpeername>(2) "
6376 "returns the remote socket address. B<getsockopt>(2) and B<setsockopt>(2) "
6377 "are used to set or get socket layer or protocol options. B<ioctl>(2) can "
6378 "be used to set or read some other options."
6382 #: build/C/man7/socket.7:132
6384 "B<close>(2) is used to close a socket. B<shutdown>(2) closes parts of a "
6385 "full-duplex socket connection."
6389 #: build/C/man7/socket.7:138
6391 "Seeking, or calling B<pread>(2) or B<pwrite>(2) with a nonzero position is "
6392 "not supported on sockets."
6396 #: build/C/man7/socket.7:155
6398 "It is possible to do nonblocking I/O on sockets by setting the B<O_NONBLOCK> "
6399 "flag on a socket file descriptor using B<fcntl>(2). Then all operations "
6400 "that would block will (usually) return with B<EAGAIN> (operation should be "
6401 "retried later); B<connect>(2) will return B<EINPROGRESS> error. The user "
6402 "can then wait for various events via B<poll>(2) or B<select>(2)."
6406 #: build/C/man7/socket.7:159
6408 msgid "I/O events\n"
6412 #: build/C/man7/socket.7:160
6414 msgid "Event:Poll flag:Occurrence\n"
6418 #: build/C/man7/socket.7:161 build/C/man7/socket.7:164
6420 msgid "Read:POLLIN:T{\n"
6424 #: build/C/man7/socket.7:162
6426 msgid "New data arrived.\n"
6430 #: build/C/man7/socket.7:165
6432 msgid "A connection setup has been completed\n"
6436 #: build/C/man7/socket.7:166
6438 msgid "(for connection-oriented sockets)\n"
6442 #: build/C/man7/socket.7:168 build/C/man7/socket.7:171
6444 msgid "Read:POLLHUP:T{\n"
6448 #: build/C/man7/socket.7:169
6450 msgid "A disconnection request has been initiated by the other end.\n"
6454 #: build/C/man7/socket.7:172
6456 msgid "A connection is broken (only for connection-oriented protocols).\n"
6460 #: build/C/man7/socket.7:173
6462 msgid "When the socket is written\n"
6466 #: build/C/man7/socket.7:174
6468 msgid "B<SIGPIPE>\n"
6472 #: build/C/man7/socket.7:175
6474 msgid "is also sent.\n"
6478 #: build/C/man7/socket.7:177
6480 msgid "Write:POLLOUT:T{\n"
6484 #: build/C/man7/socket.7:178
6486 msgid "Socket has enough send buffer space for writing new data.\n"
6490 #: build/C/man7/socket.7:180
6492 msgid "Read/Write:T{\n"
6496 #: build/C/man7/socket.7:181
6502 #: build/C/man7/socket.7:182
6508 #: build/C/man7/socket.7:183
6514 #: build/C/man7/socket.7:185
6516 msgid "An outgoing\n"
6520 #: build/C/man7/socket.7:186
6522 msgid "B<connect>(2)\n"
6526 #: build/C/man7/socket.7:187
6532 #: build/C/man7/socket.7:189
6534 msgid "Read/Write:POLLERR:An asynchronous error occurred.\n"
6538 #: build/C/man7/socket.7:190
6540 msgid "Read/Write:POLLHUP:The other end has shut down one direction.\n"
6544 #: build/C/man7/socket.7:191
6546 msgid "Exception:POLLPRI:T{\n"
6550 #: build/C/man7/socket.7:192
6552 msgid "Urgent data arrived.\n"
6556 #: build/C/man7/socket.7:193
6562 #: build/C/man7/socket.7:194
6564 msgid "is sent then.\n"
6568 #: build/C/man7/socket.7:223
6570 "An alternative to B<poll>(2) and B<select>(2) is to let the kernel inform "
6571 "the application about events via a B<SIGIO> signal. For that the B<O_ASYNC> "
6572 "flag must be set on a socket file descriptor via B<fcntl>(2) and a valid "
6573 "signal handler for B<SIGIO> must be installed via B<sigaction>(2). See the "
6574 "I<Signals> discussion below."
6578 #: build/C/man7/socket.7:223
6580 msgid "Socket address structures"
6584 #: build/C/man7/socket.7:239
6586 "Each socket domain has its own format for socket addresses, with a "
6587 "domain-specific address structure. Each of these structures begins with an "
6588 "integer \"family\" field (typed as I<sa_family_t>) that indicates the type "
6589 "of the address structure. This allows the various system calls (e.g., "
6590 "B<connect>(2), B<bind>(2), B<accept>(2), B<getsockname>(2), "
6591 "B<getpeername>(2)), which are generic to all socket domains, to determine "
6592 "the domain of a particular socket address."
6596 #: build/C/man7/socket.7:249
6598 "To allow any type of socket address to be passed to interfaces in the "
6599 "sockets API, the type I<struct sockaddr> is defined. The purpose of this "
6600 "type is purely to allow casting of domain-specific socket address types to a "
6601 "\"generic\" type, so as to avoid compiler warnings about type mismatches in "
6602 "calls to the sockets API."
6606 #: build/C/man7/socket.7:259
6608 "In addition, the sockets API provides the data type I<struct "
6609 "sockaddr_storage>. This type is suitable to accommodate all supported "
6610 "domain-specific socket address structures; it is large enough and is aligned "
6611 "properly. (In particular, it is large enough to hold IPv6 socket "
6612 "addresses.) The structure includes the following field, which can be used "
6613 "to identify the type of socket address actually stored in the structure:"
6617 #: build/C/man7/socket.7:263
6619 msgid " sa_family_t ss_family;\n"
6623 #: build/C/man7/socket.7:271
6625 "The I<sockaddr_storage> structure is useful in programs that must handle "
6626 "socket addresses in a generic way (e.g., programs that must deal with both "
6627 "IPv4 and IPv6 socket addresses)."
6631 #: build/C/man7/socket.7:271
6633 msgid "Socket options"
6637 #. In the list below, the text used to describe argument types
6638 #. for each socket option should be more consistent
6640 #. SO_ACCEPTCONN is in POSIX.1-2001, and its origin is explained in
6641 #. W R Stevens, UNPv1
6643 #: build/C/man7/socket.7:285
6645 "These socket options can be set by using B<setsockopt>(2) and read with "
6646 "B<getsockopt>(2) with the socket level set to B<SOL_SOCKET> for all "
6651 #: build/C/man7/socket.7:285
6653 msgid "B<SO_ACCEPTCONN>"
6657 #: build/C/man7/socket.7:293
6659 "Returns a value indicating whether or not this socket has been marked to "
6660 "accept connections with B<listen>(2). The value 0 indicates that this is "
6661 "not a listening socket, the value 1 indicates that this is a listening "
6662 "socket. This socket option is read-only."
6666 #: build/C/man7/socket.7:293
6668 msgid "B<SO_BINDTODEVICE>"
6672 #: build/C/man7/socket.7:312
6674 "Bind this socket to a particular device like \\(lqeth0\\(rq, as specified in "
6675 "the passed interface name. If the name is an empty string or the option "
6676 "length is zero, the socket device binding is removed. The passed option is "
6677 "a variable-length null-terminated interface name string with the maximum "
6678 "size of B<IFNAMSIZ>. If a socket is bound to an interface, only packets "
6679 "received from that particular interface are processed by the socket. Note "
6680 "that this only works for some socket types, particularly B<AF_INET> "
6681 "sockets. It is not supported for packet sockets (use normal B<bind>(2) "
6686 #: build/C/man7/socket.7:326
6688 "Before Linux 3.8, this socket option could be set, but could not retrieved "
6689 "with B<getsockopt>(2). Since Linux 3.8, it is readable. The I<optlen> "
6690 "argument should contain the buffer size available to receive the device name "
6691 "and is recommended to be B<IFNAMSZ> bytes. The real device name length is "
6692 "reported back in the I<optlen> argument."
6696 #: build/C/man7/socket.7:326
6698 msgid "B<SO_BROADCAST>"
6702 #: build/C/man7/socket.7:332
6704 "Set or get the broadcast flag. When enabled, datagram sockets are allowed "
6705 "to send packets to a broadcast address. This option has no effect on "
6706 "stream-oriented sockets."
6710 #: build/C/man7/socket.7:332
6712 msgid "B<SO_BSDCOMPAT>"
6716 #: build/C/man7/socket.7:344
6718 "Enable BSD bug-to-bug compatibility. This is used by the UDP protocol "
6719 "module in Linux 2.0 and 2.2. If enabled ICMP errors received for a UDP "
6720 "socket will not be passed to the user program. In later kernel versions, "
6721 "support for this option has been phased out: Linux 2.4 silently ignores it, "
6722 "and Linux 2.6 generates a kernel warning (printk()) if a program uses this "
6723 "option. Linux 2.0 also enabled BSD bug-to-bug compatibility options (random "
6724 "header changing, skipping of the broadcast flag) for raw sockets with this "
6725 "option, but that was removed in Linux 2.2."
6729 #: build/C/man7/socket.7:344
6735 #: build/C/man7/socket.7:350
6737 "Enable socket debugging. Only allowed for processes with the "
6738 "B<CAP_NET_ADMIN> capability or an effective user ID of 0."
6742 #: build/C/man7/socket.7:350
6744 msgid "B<SO_DOMAIN> (since Linux 2.6.32)"
6748 #: build/C/man7/socket.7:358
6750 "Retrieves the socket domain as an integer, returning a value such as "
6751 "B<AF_INET6>. See B<socket>(2) for details. This socket option is "
6756 #: build/C/man7/socket.7:358
6762 #: build/C/man7/socket.7:363
6764 "Get and clear the pending socket error. This socket option is read-only. "
6765 "Expects an integer."
6769 #: build/C/man7/socket.7:363
6771 msgid "B<SO_DONTROUTE>"
6775 #: build/C/man7/socket.7:372
6777 "Don't send via a gateway, only send to directly connected hosts. The same "
6778 "effect can be achieved by setting the B<MSG_DONTROUTE> flag on a socket "
6779 "B<send>(2) operation. Expects an integer boolean flag."
6783 #: build/C/man7/socket.7:372
6785 msgid "B<SO_KEEPALIVE>"
6789 #: build/C/man7/socket.7:376
6791 "Enable sending of keep-alive messages on connection-oriented sockets. "
6792 "Expects an integer boolean flag."
6796 #: build/C/man7/socket.7:376
6798 msgid "B<SO_LINGER>"
6802 #: build/C/man7/socket.7:384
6804 "Sets or gets the B<SO_LINGER> option. The argument is a I<linger> "
6809 #: build/C/man7/socket.7:391
6813 " int l_onoff; /* linger active */\n"
6814 " int l_linger; /* how many seconds to linger for */\n"
6819 #: build/C/man7/socket.7:405
6821 "When enabled, a B<close>(2) or B<shutdown>(2) will not return until all "
6822 "queued messages for the socket have been successfully sent or the linger "
6823 "timeout has been reached. Otherwise, the call returns immediately and the "
6824 "closing is done in the background. When the socket is closed as part of "
6825 "B<exit>(2), it always lingers in the background."
6829 #: build/C/man7/socket.7:405
6831 msgid "B<SO_MARK> (since Linux 2.6.25)"
6834 #. commit 4a19ec5800fc3bb64e2d87c4d9fdd9e636086fe0
6835 #. and 914a9ab386a288d0f22252fc268ecbc048cdcbd5
6837 #: build/C/man7/socket.7:416
6839 "Set the mark for each packet sent through this socket (similar to the "
6840 "netfilter MARK target but socket-based). Changing the mark can be used for "
6841 "mark-based routing without netfilter or for packet filtering. Setting this "
6842 "option requires the B<CAP_NET_ADMIN> capability."
6846 #: build/C/man7/socket.7:416
6848 msgid "B<SO_OOBINLINE>"
6851 #. don't document it because it can do too much harm.
6854 #: build/C/man7/socket.7:425
6856 "If this option is enabled, out-of-band data is directly placed into the "
6857 "receive data stream. Otherwise out-of-band data is only passed when the "
6858 "B<MSG_OOB> flag is set during receiving."
6862 #: build/C/man7/socket.7:425
6864 msgid "B<SO_PASSCRED>"
6867 #. FIXME Document SO_PASSSEC, added in 2.6.18; there is some info
6868 #. in the 2.6.18 ChangeLog
6870 #: build/C/man7/socket.7:434
6872 "Enable or disable the receiving of the B<SCM_CREDENTIALS> control message. "
6873 "For more information see B<unix>(7)."
6877 #: build/C/man7/socket.7:434
6879 msgid "B<SO_PEERCRED>"
6883 #: build/C/man7/socket.7:457
6885 "Return the credentials of the foreign process connected to this socket. "
6886 "This is only possible for connected B<AF_UNIX> stream sockets and B<AF_UNIX> "
6887 "stream and datagram socket pairs created using B<socketpair>(2); see "
6888 "B<unix>(7). The returned credentials are those that were in effect at the "
6889 "time of the call to B<connect>(2) or B<socketpair>(2). The argument is a "
6890 "I<ucred> structure; define the B<GNU_SOURCE> feature test macro to obtain "
6891 "the definition of that structure from I<E<lt>sys/socket.hE<gt>>. This "
6892 "socket option is read-only."
6896 #: build/C/man7/socket.7:457
6898 msgid "B<SO_PRIORITY>"
6902 #: build/C/man7/socket.7:470
6904 "Set the protocol-defined priority for all packets to be sent on this "
6905 "socket. Linux uses this value to order the networking queues: packets with "
6906 "a higher priority may be processed first depending on the selected device "
6907 "queueing discipline. For B<ip>(7), this also sets the IP type-of-service "
6908 "(TOS) field for outgoing packets. Setting a priority outside the range 0 to "
6909 "6 requires the B<CAP_NET_ADMIN> capability."
6913 #: build/C/man7/socket.7:470
6915 msgid "B<SO_PROTOCOL> (since Linux 2.6.32)"
6919 #: build/C/man7/socket.7:478
6921 "Retrieves the socket protocol as an integer, returning a value such as "
6922 "B<IPPROTO_SCTP>. See B<socket>(2) for details. This socket option is "
6927 #: build/C/man7/socket.7:478
6929 msgid "B<SO_RCVBUF>"
6932 #. Most (all?) other implementations do not do this -- MTK, Dec 05
6933 #. The following thread on LMKL is quite informative:
6934 #. getsockopt/setsockopt with SO_RCVBUF and SO_SNDBUF "non-standard" behaviour
6936 #. http://thread.gmane.org/gmane.linux.kernel/1328935
6938 #: build/C/man7/socket.7:497
6940 "Sets or gets the maximum socket receive buffer in bytes. The kernel doubles "
6941 "this value (to allow space for bookkeeping overhead) when it is set using "
6942 "B<setsockopt>(2), and this doubled value is returned by B<getsockopt>(2). "
6943 "The default value is set by the I</proc/sys/net/core/rmem_default> file, and "
6944 "the maximum allowed value is set by the I</proc/sys/net/core/rmem_max> "
6945 "file. The minimum (doubled) value for this option is 256."
6949 #: build/C/man7/socket.7:497
6951 msgid "B<SO_RCVBUFFORCE> (since Linux 2.6.14)"
6955 #: build/C/man7/socket.7:506
6957 "Using this socket option, a privileged (B<CAP_NET_ADMIN>) process can "
6958 "perform the same task as B<SO_RCVBUF>, but the I<rmem_max> limit can be "
6963 #: build/C/man7/socket.7:506
6965 msgid "B<SO_RCVLOWAT> and B<SO_SNDLOWAT>"
6968 #. See http://marc.theaimsgroup.com/?l=linux-kernel&m=111049368106984&w=2
6969 #. Tested on kernel 2.6.14 -- mtk, 30 Nov 05
6971 #: build/C/man7/socket.7:535
6973 "Specify the minimum number of bytes in the buffer until the socket layer "
6974 "will pass the data to the protocol (B<SO_SNDLOWAT>) or the user on "
6975 "receiving (B<SO_RCVLOWAT>). These two values are initialized to 1. "
6976 "B<SO_SNDLOWAT> is not changeable on Linux (B<setsockopt>(2) fails with the "
6977 "error B<ENOPROTOOPT>). B<SO_RCVLOWAT> is changeable only since Linux 2.4. "
6978 "The B<select>(2) and B<poll>(2) system calls currently do not respect the "
6979 "B<SO_RCVLOWAT> setting on Linux, and mark a socket readable when even a "
6980 "single byte of data is available. A subsequent read from the socket will "
6981 "block until B<SO_RCVLOWAT> bytes are available."
6985 #: build/C/man7/socket.7:535
6987 msgid "B<SO_RCVTIMEO> and B<SO_SNDTIMEO>"
6990 #. Not implemented in 2.0.
6991 #. Implemented in 2.1.11 for getsockopt: always return a zero struct.
6992 #. Implemented in 2.3.41 for setsockopt, and actually used.
6993 #. in fact to EAGAIN
6995 #: build/C/man7/socket.7:570
6997 "Specify the receiving or sending timeouts until reporting an error. The "
6998 "argument is a I<struct timeval>. If an input or output function blocks for "
6999 "this period of time, and data has been sent or received, the return value of "
7000 "that function will be the amount of data transferred; if no data has been "
7001 "transferred and the timeout has been reached then -1 is returned with "
7002 "I<errno> set to B<EAGAIN> or B<EWOULDBLOCK>, or B<EINPROGRESS> (for "
7003 "B<connect>(2)) just as if the socket was specified to be nonblocking. If "
7004 "the timeout is set to zero (the default) then the operation will never "
7005 "timeout. Timeouts only have effect for system calls that perform socket I/O "
7006 "(e.g., B<read>(2), B<recvmsg>(2), B<send>(2), B<sendmsg>(2)); timeouts have "
7007 "no effect for B<select>(2), B<poll>(2), B<epoll_wait>(2), and so on."
7011 #: build/C/man7/socket.7:570
7013 msgid "B<SO_REUSEADDR>"
7017 #: build/C/man7/socket.7:585
7019 "Indicates that the rules used in validating addresses supplied in a "
7020 "B<bind>(2) call should allow reuse of local addresses. For B<AF_INET> "
7021 "sockets this means that a socket may bind, except when there is an active "
7022 "listening socket bound to the address. When the listening socket is bound "
7023 "to B<INADDR_ANY> with a specific port then it is not possible to bind to "
7024 "this port for any local address. Argument is an integer boolean flag."
7028 #: build/C/man7/socket.7:585
7030 msgid "B<SO_SNDBUF>"
7033 #. Most (all?) other implementations do not do this -- MTK, Dec 05
7034 #. See also the comment to SO_RCVBUF (17 Jul 2012 LKML mail)
7036 #: build/C/man7/socket.7:601
7038 "Sets or gets the maximum socket send buffer in bytes. The kernel doubles "
7039 "this value (to allow space for bookkeeping overhead) when it is set using "
7040 "B<setsockopt>(2), and this doubled value is returned by B<getsockopt>(2). "
7041 "The default value is set by the I</proc/sys/net/core/wmem_default> file and "
7042 "the maximum allowed value is set by the I</proc/sys/net/core/wmem_max> "
7043 "file. The minimum (doubled) value for this option is 2048."
7047 #: build/C/man7/socket.7:601
7049 msgid "B<SO_SNDBUFFORCE> (since Linux 2.6.14)"
7053 #: build/C/man7/socket.7:610
7055 "Using this socket option, a privileged (B<CAP_NET_ADMIN>) process can "
7056 "perform the same task as B<SO_SNDBUF>, but the I<wmem_max> limit can be "
7061 #: build/C/man7/socket.7:610
7063 msgid "B<SO_TIMESTAMP>"
7067 #: build/C/man7/socket.7:626
7069 "Enable or disable the receiving of the B<SO_TIMESTAMP> control message. The "
7070 "timestamp control message is sent with level B<SOL_SOCKET> and the "
7071 "I<cmsg_data> field is a I<struct timeval> indicating the reception time of "
7072 "the last packet passed to the user in this call. See B<cmsg>(3) for "
7073 "details on control messages."
7077 #: build/C/man7/socket.7:626
7083 #: build/C/man7/socket.7:631
7085 "Gets the socket type as an integer (e.g., B<SOCK_STREAM>). This socket "
7086 "option is read-only."
7090 #: build/C/man7/socket.7:631
7096 #: build/C/man7/socket.7:642
7098 "When writing onto a connection-oriented socket that has been shut down (by "
7099 "the local or the remote end) B<SIGPIPE> is sent to the writing process and "
7100 "B<EPIPE> is returned. The signal is not sent when the write call specified "
7101 "the B<MSG_NOSIGNAL> flag."
7105 #: build/C/man7/socket.7:667
7107 "When requested with the B<FIOSETOWN> B<fcntl>(2) or B<SIOCSPGRP> "
7108 "B<ioctl>(2), B<SIGIO> is sent when an I/O event occurs. It is possible to "
7109 "use B<poll>(2) or B<select>(2) in the signal handler to find out which "
7110 "socket the event occurred on. An alternative (in Linux 2.2) is to set a "
7111 "real-time signal using the B<F_SETSIG> B<fcntl>(2); the handler of the real "
7112 "time signal will be called with the file descriptor in the I<si_fd> field of "
7113 "its I<siginfo_t>. See B<fcntl>(2) for more information."
7116 #. .SS Ancillary messages
7118 #: build/C/man7/socket.7:675
7120 "Under some circumstances (e.g., multiple processes accessing a single "
7121 "socket), the condition that caused the B<SIGIO> may have already disappeared "
7122 "when the process reacts to the signal. If this happens, the process should "
7123 "wait again because Linux will resend the signal later."
7127 #: build/C/man7/socket.7:675
7129 msgid "/proc interfaces"
7133 #: build/C/man7/socket.7:679
7135 "The core socket networking parameters can be accessed via files in the "
7136 "directory I</proc/sys/net/core/>."
7140 #: build/C/man7/socket.7:679
7142 msgid "I<rmem_default>"
7146 #: build/C/man7/socket.7:682
7147 msgid "contains the default setting in bytes of the socket receive buffer."
7151 #: build/C/man7/socket.7:682
7157 #: build/C/man7/socket.7:688
7159 "contains the maximum socket receive buffer size in bytes which a user may "
7160 "set by using the B<SO_RCVBUF> socket option."
7164 #: build/C/man7/socket.7:688
7166 msgid "I<wmem_default>"
7170 #: build/C/man7/socket.7:691
7171 msgid "contains the default setting in bytes of the socket send buffer."
7175 #: build/C/man7/socket.7:691
7181 #: build/C/man7/socket.7:697
7183 "contains the maximum socket send buffer size in bytes which a user may set "
7184 "by using the B<SO_SNDBUF> socket option."
7188 #: build/C/man7/socket.7:697
7190 msgid "I<message_cost> and I<message_burst>"
7194 #: build/C/man7/socket.7:701
7196 "configure the token bucket filter used to load limit warning messages caused "
7197 "by external network events."
7201 #: build/C/man7/socket.7:701
7203 msgid "I<netdev_max_backlog>"
7207 #: build/C/man7/socket.7:704
7208 msgid "Maximum number of packets in the global input queue."
7212 #: build/C/man7/socket.7:704
7214 msgid "I<optmem_max>"
7217 #. netdev_fastroute is not documented because it is experimental
7219 #: build/C/man7/socket.7:709
7221 "Maximum length of ancillary data and user control data like the iovecs per "
7226 #: build/C/man7/socket.7:709
7232 #: build/C/man7/socket.7:712
7233 msgid "These operations can be accessed using B<ioctl>(2):"
7237 #: build/C/man7/socket.7:716
7240 "I<error>B< = ioctl(>I<ip_socket>B<, >I<ioctl_type>B<, "
7241 ">I<&value_result>B<);>\n"
7245 #: build/C/man7/socket.7:718
7247 msgid "B<SIOCGSTAMP>"
7251 #: build/C/man7/socket.7:742
7253 "Return a I<struct timeval> with the receive timestamp of the last packet "
7254 "passed to the user. This is useful for accurate round trip time "
7255 "measurements. See B<setitimer>(2) for a description of I<struct timeval>. "
7256 "This ioctl should only be used if the socket option B<SO_TIMESTAMP> is not "
7257 "set on the socket. Otherwise, it returns the timestamp of the last packet "
7258 "that was received while B<SO_TIMESTAMP> was not set, or it fails if no such "
7259 "packet has been received, (i.e., B<ioctl>(2) returns -1 with I<errno> set "
7264 #: build/C/man7/socket.7:742
7266 msgid "B<SIOCSPGRP>"
7270 #: build/C/man7/socket.7:761
7272 "Set the process or process group to send B<SIGIO> or B<SIGURG> signals to "
7273 "when an asynchronous I/O operation has finished or urgent data is "
7274 "available. The argument is a pointer to a I<pid_t>. If the argument is "
7275 "positive, send the signals to that process. If the argument is negative, "
7276 "send the signals to the process group with the ID of the absolute value of "
7277 "the argument. The process may only choose itself or its own process group "
7278 "to receive signals unless it has the B<CAP_KILL> capability or an effective "
7283 #: build/C/man7/socket.7:761
7289 #: build/C/man7/socket.7:771
7291 "Change the B<O_ASYNC> flag to enable or disable asynchronous I/O mode of the "
7292 "socket. Asynchronous I/O mode means that the B<SIGIO> signal or the signal "
7293 "set with B<F_SETSIG> is raised when a new I/O event occurs."
7297 #: build/C/man7/socket.7:779
7299 "Argument is an integer boolean flag. (This operation is synonymous with the "
7300 "use of B<fcntl>(2) to set the B<O_ASYNC> flag.)"
7304 #: build/C/man7/socket.7:779
7306 msgid "B<SIOCGPGRP>"
7310 #: build/C/man7/socket.7:788
7312 "Get the current process or process group that receives B<SIGIO> or B<SIGURG> "
7313 "signals, or 0 when none is set."
7317 #: build/C/man7/socket.7:792
7318 msgid "Valid B<fcntl>(2) operations:"
7322 #: build/C/man7/socket.7:792
7324 msgid "B<FIOGETOWN>"
7328 #: build/C/man7/socket.7:797
7329 msgid "The same as the B<SIOCGPGRP> B<ioctl>(2)."
7333 #: build/C/man7/socket.7:797
7335 msgid "B<FIOSETOWN>"
7339 #: build/C/man7/socket.7:802
7340 msgid "The same as the B<SIOCSPGRP> B<ioctl>(2)."
7344 #: build/C/man7/socket.7:816
7346 "B<SO_BINDTODEVICE> was introduced in Linux 2.0.30. B<SO_PASSCRED> is new in "
7347 "Linux 2.2. The I</proc> interfaces was introduced in Linux 2.2. "
7348 "B<SO_RCVTIMEO> and B<SO_SNDTIMEO> are supported since Linux 2.3.41. "
7349 "Earlier, timeouts were fixed to a protocol-specific setting, and could not "
7350 "be read or written."
7354 #: build/C/man7/socket.7:821
7356 "Linux assumes that half of the send/receive buffer is used for internal "
7357 "kernel structures; thus the values in the corresponding I</proc> files are "
7358 "twice what can be observed on the wire."
7362 #: build/C/man7/socket.7:834
7364 "Linux will only allow port reuse with the B<SO_REUSEADDR> option when this "
7365 "option was set both in the previous program that performed a B<bind>(2) to "
7366 "the port and in the program that wants to reuse the port. This differs from "
7367 "some implementations (e.g., FreeBSD) where only the later program needs to "
7368 "set the B<SO_REUSEADDR> option. Typically this difference is invisible, "
7369 "since, for example, a server program is designed to always set this option."
7372 #. FIXME Document SO_ATTACH_FILTER and SO_DETACH_FILTER
7374 #. This man page was written by Andi Kleen.
7376 #: build/C/man7/socket.7:847
7378 "The B<CONFIG_FILTER> socket options B<SO_ATTACH_FILTER> and "
7379 "B<SO_DETACH_FILTER> are not documented. The suggested interface to use them "
7380 "is via the libpcap library."
7384 #: build/C/man7/socket.7:859
7386 "B<getsockopt>(2), B<connect>(2), B<setsockopt>(2), B<socket>(2), "
7387 "B<capabilities>(7), B<ddp>(7), B<ip>(7), B<packet>(7), B<tcp>(7), B<udp>(7), "
7392 #: build/C/man2/socketcall.2:25
7398 #: build/C/man2/socketcall.2:25
7404 #: build/C/man2/socketcall.2:28
7405 msgid "socketcall - socket system calls"
7409 #: build/C/man2/socketcall.2:30
7410 msgid "B<int socketcall(int >I<call>B<, unsigned long *>I<args>B<);>"
7414 #: build/C/man2/socketcall.2:38
7416 "B<socketcall>() is a common kernel entry point for the socket system "
7417 "calls. I<call> determines which socket function to invoke. I<args> points "
7418 "to a block containing the actual arguments, which are passed through to the "
7423 #: build/C/man2/socketcall.2:42
7425 "User programs should call the appropriate functions by their usual names. "
7426 "Only standard library implementors and kernel hackers need to know about "
7431 #: build/C/man2/socketcall.2:45
7433 "This call is specific to Linux, and should not be used in programs intended "
7438 #: build/C/man2/socketcall.2:53
7440 "On a some architectures\\(emfor example, x86-64 and ARM\\(emthere is no "
7441 "B<socketcall>() system call; instead B<socket>(2), B<accept>(2), "
7442 "B<bind>(2), and so on really are implemented as separate system calls."
7446 #: build/C/man2/socketcall.2:71
7448 "B<accept>(2), B<bind>(2), B<connect>(2), B<getpeername>(2), "
7449 "B<getsockname>(2), B<getsockopt>(2), B<listen>(2), B<recv>(2), "
7450 "B<recvfrom>(2), B<recvmsg>(2), B<send>(2), B<sendmsg>(2), B<sendto>(2), "
7451 "B<setsockopt>(2), B<shutdown>(2), B<socket>(2), B<socketpair>(2)"
7455 #: build/C/man2/socketpair.2:42
7461 #: build/C/man2/socketpair.2:42
7467 #: build/C/man2/socketpair.2:45
7468 msgid "socketpair - create a pair of connected sockets"
7472 #: build/C/man2/socketpair.2:52
7474 "B<int socketpair(int >I<domain>B<, int >I<type>B<, int >I<protocol>B<, int "
7479 #: build/C/man2/socketpair.2:63
7481 "The B<socketpair>() call creates an unnamed pair of connected sockets in "
7482 "the specified I<domain>, of the specified I<type>, and using the optionally "
7483 "specified I<protocol>. For further details of these arguments, see "
7488 #: build/C/man2/socketpair.2:69
7490 "The descriptors used in referencing the new sockets are returned in I<sv>[0] "
7491 "and I<sv>[1]. The two sockets are indistinguishable."
7495 #: build/C/man2/socketpair.2:78
7496 msgid "The specified address family is not supported on this machine."
7500 #: build/C/man2/socketpair.2:83
7502 "The address I<sv> does not specify a valid part of the process address "
7507 #: build/C/man2/socketpair.2:86
7508 msgid "Too many descriptors are in use by this process."
7512 #: build/C/man2/socketpair.2:92
7513 msgid "The specified protocol does not support creation of socket pairs."
7517 #: build/C/man2/socketpair.2:95
7518 msgid "The specified protocol is not supported on this machine."
7522 #: build/C/man2/socketpair.2:103
7524 "4.4BSD, POSIX.1-2001. The B<socketpair>() function call appeared in "
7525 "4.2BSD. It is generally portable to/from non-BSD systems supporting clones "
7526 "of the BSD socket layer (including System V variants)."
7530 #: build/C/man2/socketpair.2:109
7532 "On Linux, the only supported domain for this call is B<AF_UNIX> (or "
7533 "synonymously, B<AF_LOCAL>). (Most implementations have the same "
7538 #: build/C/man2/socketpair.2:118
7540 "Since Linux 2.6.27, B<socketpair>() supports the B<SOCK_NONBLOCK> and "
7541 "B<SOCK_CLOEXEC> flags described in B<socket>(2)."
7545 #: build/C/man2/socketpair.2:131
7546 msgid "B<pipe>(2), B<read>(2), B<socket>(2), B<write>(2), B<socket>(7), B<unix>(7)"