1 | /* $NetBSD: socket.h,v 1.129 2018/11/04 16:30:29 christos Exp $ */ |
2 | |
3 | /* |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
5 | * All rights reserved. |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions |
9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. Neither the name of the project nor the names of its contributors |
16 | * may be used to endorse or promote products derived from this software |
17 | * without specific prior written permission. |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. |
30 | */ |
31 | |
32 | /* |
33 | * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 |
34 | * The Regents of the University of California. All rights reserved. |
35 | * |
36 | * Redistribution and use in source and binary forms, with or without |
37 | * modification, are permitted provided that the following conditions |
38 | * are met: |
39 | * 1. Redistributions of source code must retain the above copyright |
40 | * notice, this list of conditions and the following disclaimer. |
41 | * 2. Redistributions in binary form must reproduce the above copyright |
42 | * notice, this list of conditions and the following disclaimer in the |
43 | * documentation and/or other materials provided with the distribution. |
44 | * 3. Neither the name of the University nor the names of its contributors |
45 | * may be used to endorse or promote products derived from this software |
46 | * without specific prior written permission. |
47 | * |
48 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
49 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 | * SUCH DAMAGE. |
59 | * |
60 | * @(#)socket.h 8.6 (Berkeley) 5/3/95 |
61 | */ |
62 | |
63 | #ifndef _SYS_SOCKET_H_ |
64 | #define _SYS_SOCKET_H_ |
65 | |
66 | #include <sys/featuretest.h> |
67 | |
68 | /* |
69 | * Definitions related to sockets: types, address families, options. |
70 | */ |
71 | |
72 | /* |
73 | * Data types. |
74 | */ |
75 | #include <sys/ansi.h> |
76 | |
77 | #ifndef sa_family_t |
78 | typedef __sa_family_t sa_family_t; |
79 | #define sa_family_t __sa_family_t |
80 | #endif |
81 | |
82 | #ifndef socklen_t |
83 | typedef __socklen_t socklen_t; |
84 | #define socklen_t __socklen_t |
85 | #endif |
86 | |
87 | #include <machine/ansi.h> |
88 | |
89 | #ifdef _BSD_SIZE_T_ |
90 | typedef _BSD_SIZE_T_ size_t; |
91 | #undef _BSD_SIZE_T_ |
92 | #endif |
93 | |
94 | #ifdef _BSD_SSIZE_T_ |
95 | typedef _BSD_SSIZE_T_ ssize_t; |
96 | #undef _BSD_SSIZE_T_ |
97 | #endif |
98 | |
99 | #include <sys/uio.h> |
100 | #include <sys/sigtypes.h> |
101 | |
102 | /* |
103 | * Socket types. |
104 | */ |
105 | #define SOCK_STREAM 1 /* stream socket */ |
106 | #define SOCK_DGRAM 2 /* datagram socket */ |
107 | #define SOCK_RAW 3 /* raw-protocol interface */ |
108 | #define SOCK_RDM 4 /* reliably-delivered message */ |
109 | #define SOCK_SEQPACKET 5 /* sequenced packet stream */ |
110 | #define SOCK_CONN_DGRAM 6 /* connection-orientated datagram */ |
111 | #define SOCK_DCCP SOCK_CONN_DGRAM |
112 | |
113 | #define SOCK_CLOEXEC 0x10000000 /* set close on exec on socket */ |
114 | #define SOCK_NONBLOCK 0x20000000 /* set non blocking i/o socket */ |
115 | #define SOCK_NOSIGPIPE 0x40000000 /* don't send sigpipe */ |
116 | #define SOCK_FLAGS_MASK 0xf0000000 /* flags mask */ |
117 | |
118 | /* |
119 | * Option flags per-socket. |
120 | */ |
121 | #define SO_DEBUG 0x0001 /* turn on debugging info recording */ |
122 | #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ |
123 | #define SO_REUSEADDR 0x0004 /* allow local address reuse */ |
124 | #define SO_KEEPALIVE 0x0008 /* keep connections alive */ |
125 | #define SO_DONTROUTE 0x0010 /* just use interface addresses */ |
126 | #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ |
127 | #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ |
128 | #define SO_LINGER 0x0080 /* linger on close if data present */ |
129 | #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ |
130 | #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ |
131 | /* SO_OTIMESTAMP 0x0400 */ |
132 | #define SO_NOSIGPIPE 0x0800 /* no SIGPIPE from EPIPE */ |
133 | #define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */ |
134 | #define SO_TIMESTAMP 0x2000 /* timestamp received dgram traffic */ |
135 | #define SO_RERROR 0x4000 /* Keep track of receive errors */ |
136 | |
137 | /* Allowed default option flags */ |
138 | #define SO_DEFOPTS (SO_DEBUG|SO_REUSEADDR|SO_KEEPALIVE|SO_DONTROUTE| \ |
139 | SO_BROADCAST|SO_USELOOPBACK|SO_LINGER|SO_OOBINLINE|SO_REUSEPORT| \ |
140 | SO_NOSIGPIPE|SO_TIMESTAMP|SO_RERROR) |
141 | |
142 | #define __SO_OPTION_BITS \ |
143 | "\20" \ |
144 | "\1SO_DEBUG" \ |
145 | "\2SO_ACCEPTCONN" \ |
146 | "\3SO_REUSEADDR" \ |
147 | "\4SO_KEEPALIVE" \ |
148 | "\5SO_DONTROUTE" \ |
149 | "\6SO_BROADCAST" \ |
150 | "\7SO_USELOOPBACK" \ |
151 | "\10SO_LINGER" \ |
152 | "\11SO_OOBINLINE" \ |
153 | "\12SO_REUSEPORT" \ |
154 | "\13SO_OTIMESTAMP" \ |
155 | "\14SO_NOSIGPIPE" \ |
156 | "\15SO_ACCEPTFILTER" \ |
157 | "\16SO_TIMESTAMP" \ |
158 | "\17SO_RERROR" |
159 | |
160 | /* |
161 | * Additional options, not kept in so_options. |
162 | */ |
163 | #define SO_SNDBUF 0x1001 /* send buffer size */ |
164 | #define SO_RCVBUF 0x1002 /* receive buffer size */ |
165 | #define SO_SNDLOWAT 0x1003 /* send low-water mark */ |
166 | #define SO_RCVLOWAT 0x1004 /* receive low-water mark */ |
167 | /* SO_OSNDTIMEO 0x1005 */ |
168 | /* SO_ORCVTIMEO 0x1006 */ |
169 | #define SO_ERROR 0x1007 /* get error status and clear */ |
170 | #define SO_TYPE 0x1008 /* get socket type */ |
171 | #define SO_OVERFLOWED 0x1009 /* datagrams: return packets dropped */ |
172 | |
173 | #define 0x100a /* user supplies no header to kernel; |
174 | * kernel removes header and supplies |
175 | * payload |
176 | */ |
177 | #define SO_SNDTIMEO 0x100b /* send timeout */ |
178 | #define SO_RCVTIMEO 0x100c /* receive timeout */ |
179 | /* |
180 | * Structure used for manipulating linger option. |
181 | */ |
182 | struct linger { |
183 | int l_onoff; /* option on/off */ |
184 | int l_linger; /* linger time in seconds */ |
185 | }; |
186 | |
187 | struct accept_filter_arg { |
188 | char af_name[16]; |
189 | char af_arg[256-16]; |
190 | }; |
191 | |
192 | /* |
193 | * Level number for (get/set)sockopt() to apply to socket itself. |
194 | */ |
195 | #define SOL_SOCKET 0xffff /* options for socket level */ |
196 | |
197 | /* |
198 | * Address families. |
199 | */ |
200 | #define AF_UNSPEC 0 /* unspecified */ |
201 | #define AF_LOCAL 1 /* local to host */ |
202 | #define AF_UNIX AF_LOCAL /* backward compatibility */ |
203 | #define AF_INET 2 /* internetwork: UDP, TCP, etc. */ |
204 | #define AF_IMPLINK 3 /* arpanet imp addresses */ |
205 | #define AF_PUP 4 /* pup protocols: e.g. BSP */ |
206 | #define AF_CHAOS 5 /* mit CHAOS protocols */ |
207 | #define AF_NS 6 /* XEROX NS protocols */ |
208 | #define AF_ISO 7 /* ISO protocols */ |
209 | #define AF_OSI AF_ISO |
210 | #define AF_ECMA 8 /* european computer manufacturers */ |
211 | #define AF_DATAKIT 9 /* datakit protocols */ |
212 | #define AF_CCITT 10 /* CCITT protocols, X.25 etc */ |
213 | #define AF_SNA 11 /* IBM SNA */ |
214 | #define AF_DECnet 12 /* DECnet */ |
215 | #define AF_DLI 13 /* DEC Direct data link interface */ |
216 | #define AF_LAT 14 /* LAT */ |
217 | #define AF_HYLINK 15 /* NSC Hyperchannel */ |
218 | #define AF_APPLETALK 16 /* Apple Talk */ |
219 | #define AF_OROUTE 17 /* Internal Routing Protocol */ |
220 | #define AF_LINK 18 /* Link layer interface */ |
221 | #if defined(_NETBSD_SOURCE) |
222 | #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ |
223 | #endif |
224 | #define AF_COIP 20 /* connection-oriented IP, aka ST II */ |
225 | #define AF_CNT 21 /* Computer Network Technology */ |
226 | #if defined(_NETBSD_SOURCE) |
227 | #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ |
228 | #endif |
229 | #define AF_IPX 23 /* Novell Internet Protocol */ |
230 | #define AF_INET6 24 /* IP version 6 */ |
231 | #if defined(_NETBSD_SOURCE) |
232 | #define pseudo_AF_PIP 25 /* Help Identify PIP packets */ |
233 | #endif |
234 | #define AF_ISDN 26 /* Integrated Services Digital Network*/ |
235 | #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ |
236 | #define AF_NATM 27 /* native ATM access */ |
237 | #define AF_ARP 28 /* (rev.) addr. res. prot. (RFC 826) */ |
238 | #if defined(_NETBSD_SOURCE) |
239 | #define pseudo_AF_KEY 29 /* Internal key management protocol */ |
240 | #define pseudo_AF_HDRCMPLT 30 /* Used by BPF to not rewrite hdrs |
241 | in interface output routine */ |
242 | #endif |
243 | #define AF_BLUETOOTH 31 /* Bluetooth: HCI, SCO, L2CAP, RFCOMM */ |
244 | #define AF_IEEE80211 32 /* IEEE80211 */ |
245 | #define AF_MPLS 33 /* MultiProtocol Label Switching */ |
246 | #define AF_ROUTE 34 /* Internal Routing Protocol */ |
247 | #define AF_CAN 35 |
248 | #define AF_ETHER 36 |
249 | #define AF_MAX 37 |
250 | |
251 | /* |
252 | * Structure used by kernel to store most |
253 | * addresses. |
254 | */ |
255 | struct sockaddr { |
256 | __uint8_t sa_len; /* total length */ |
257 | sa_family_t sa_family; /* address family */ |
258 | char sa_data[14]; /* actually longer; address value */ |
259 | }; |
260 | |
261 | #if defined(_KERNEL) |
262 | /* |
263 | * Structure used by kernel to pass protocol |
264 | * information in raw sockets. |
265 | */ |
266 | struct sockproto { |
267 | u_short sp_family; /* address family */ |
268 | u_short sp_protocol; /* protocol */ |
269 | }; |
270 | |
271 | /* |
272 | * we make the entire struct at least UCHAR_MAX + 1 in size since existing |
273 | * use of sockaddr_un permits a path up to 253 bytes + '\0'. |
274 | * sizeof(sb_len) + sizeof(sb_family) + 253 + '\0' |
275 | */ |
276 | #define _SB_DATASIZE 254 |
277 | struct sockaddr_big { |
278 | union { |
279 | struct { |
280 | __uint8_t sb_len; |
281 | sa_family_t sb_family; |
282 | char sb_data[_SB_DATASIZE]; |
283 | }; |
284 | uint64_t dummy; /* solicit natural alignment */ |
285 | }; |
286 | }; |
287 | |
288 | #endif /* _KERNEL */ |
289 | |
290 | #if 1 |
291 | /* |
292 | * RFC 2553: protocol-independent placeholder for socket addresses |
293 | */ |
294 | #define _SS_MAXSIZE 128 |
295 | #define _SS_ALIGNSIZE (sizeof(__int64_t)) |
296 | #define _SS_PAD1SIZE (_SS_ALIGNSIZE - 2) |
297 | #define _SS_PAD2SIZE (_SS_MAXSIZE - 2 - \ |
298 | _SS_PAD1SIZE - _SS_ALIGNSIZE) |
299 | |
300 | #if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) |
301 | struct sockaddr_storage { |
302 | __uint8_t ss_len; /* address length */ |
303 | sa_family_t ss_family; /* address family */ |
304 | char __ss_pad1[_SS_PAD1SIZE]; |
305 | __int64_t __ss_align;/* force desired structure storage alignment */ |
306 | char __ss_pad2[_SS_PAD2SIZE]; |
307 | }; |
308 | #define sstosa(__ss) ((struct sockaddr *)(__ss)) |
309 | #define sstocsa(__ss) ((const struct sockaddr *)(__ss)) |
310 | #endif /* _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */ |
311 | #endif /* 1 */ |
312 | |
313 | /* |
314 | * Protocol families, same as address families for now. |
315 | */ |
316 | #define PF_UNSPEC AF_UNSPEC |
317 | #define PF_LOCAL AF_LOCAL |
318 | #define PF_UNIX PF_LOCAL /* backward compatibility */ |
319 | #define PF_INET AF_INET |
320 | #define PF_IMPLINK AF_IMPLINK |
321 | #define PF_PUP AF_PUP |
322 | #define PF_CHAOS AF_CHAOS |
323 | #define PF_NS AF_NS |
324 | #define PF_ISO AF_ISO |
325 | #define PF_OSI AF_ISO |
326 | #define PF_ECMA AF_ECMA |
327 | #define PF_DATAKIT AF_DATAKIT |
328 | #define PF_CCITT AF_CCITT |
329 | #define PF_SNA AF_SNA |
330 | #define PF_DECnet AF_DECnet |
331 | #define PF_DLI AF_DLI |
332 | #define PF_LAT AF_LAT |
333 | #define PF_HYLINK AF_HYLINK |
334 | #define PF_APPLETALK AF_APPLETALK |
335 | #define PF_OROUTE AF_OROUTE |
336 | #define PF_LINK AF_LINK |
337 | #if defined(_NETBSD_SOURCE) |
338 | #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ |
339 | #endif |
340 | #define PF_COIP AF_COIP |
341 | #define PF_CNT AF_CNT |
342 | #define PF_INET6 AF_INET6 |
343 | #define PF_IPX AF_IPX /* same format as AF_NS */ |
344 | #if defined(_NETBSD_SOURCE) |
345 | #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ |
346 | #define PF_PIP pseudo_AF_PIP |
347 | #endif |
348 | #define PF_ISDN AF_ISDN /* same as E164 */ |
349 | #define PF_E164 AF_E164 |
350 | #define PF_NATM AF_NATM |
351 | #define PF_ARP AF_ARP |
352 | #if defined(_NETBSD_SOURCE) |
353 | #define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */ |
354 | #endif |
355 | #define PF_BLUETOOTH AF_BLUETOOTH |
356 | #define PF_MPLS AF_MPLS |
357 | #define PF_ROUTE AF_ROUTE |
358 | #define PF_CAN AF_CAN |
359 | #define PF_ETHER AF_ETHER |
360 | |
361 | #define PF_MAX AF_MAX |
362 | |
363 | #if defined(_NETBSD_SOURCE) |
364 | |
365 | #ifndef pid_t |
366 | typedef __pid_t pid_t; /* process id */ |
367 | #define pid_t __pid_t |
368 | #endif |
369 | |
370 | #ifndef gid_t |
371 | typedef __gid_t gid_t; /* group id */ |
372 | #define gid_t __gid_t |
373 | #endif |
374 | |
375 | #ifndef uid_t |
376 | typedef __uid_t uid_t; /* user id */ |
377 | #define uid_t __uid_t |
378 | #endif |
379 | |
380 | /* |
381 | * Socket credentials. |
382 | */ |
383 | struct sockcred { |
384 | pid_t sc_pid; /* process id */ |
385 | uid_t sc_uid; /* real user id */ |
386 | uid_t sc_euid; /* effective user id */ |
387 | gid_t sc_gid; /* real group id */ |
388 | gid_t sc_egid; /* effective group id */ |
389 | int sc_ngroups; /* number of supplemental groups */ |
390 | gid_t sc_groups[1]; /* variable length */ |
391 | }; |
392 | |
393 | /* |
394 | * Compute size of a sockcred structure with groups. |
395 | */ |
396 | #define SOCKCREDSIZE(ngrps) \ |
397 | (/*CONSTCOND*/sizeof(struct sockcred) + (sizeof(gid_t) * \ |
398 | ((ngrps) ? ((ngrps) - 1) : 0))) |
399 | #endif /* _NETBSD_SOURCE */ |
400 | |
401 | |
402 | #if defined(_NETBSD_SOURCE) |
403 | /* Definition for CTL_NET PCB fetching sysctls */ |
404 | struct kinfo_pcb { |
405 | __uint64_t ki_pcbaddr; /* PTR: pcb addr */ |
406 | __uint64_t ki_ppcbaddr; /* PTR: ppcb addr */ |
407 | __uint64_t ki_sockaddr; /* PTR: socket addr */ |
408 | |
409 | __uint32_t ki_family; /* INT: protocol family */ |
410 | __uint32_t ki_type; /* INT: socket type */ |
411 | __uint32_t ki_protocol; /* INT: protocol */ |
412 | __uint32_t ki_pflags; /* INT: generic protocol flags */ |
413 | |
414 | __uint32_t ki_sostate; /* INT: socket state */ |
415 | __uint32_t ki_prstate; /* INT: protocol state */ |
416 | __int32_t ki_tstate; /* INT: tcp state */ |
417 | __uint32_t ki_tflags; /* INT: tcp flags */ |
418 | |
419 | __uint64_t ki_rcvq; /* U_LONG: receive queue len */ |
420 | __uint64_t ki_sndq; /* U_LONG: send queue len */ |
421 | |
422 | union { |
423 | struct sockaddr _kis_src; /* STRUCT: local address */ |
424 | char _kis_pad[256 + 8]; /* pad to max addr length */ |
425 | } ki_s; |
426 | union { |
427 | struct sockaddr _kid_dst; /* STRUCT: remote address */ |
428 | char _kid_pad[256 + 8]; /* pad to max addr length */ |
429 | } ki_d; |
430 | |
431 | __uint64_t ki_inode; /* INO_T: fake inode number */ |
432 | __uint64_t ki_vnode; /* PTR: if associated with file */ |
433 | __uint64_t ki_conn; /* PTR: control block of peer */ |
434 | __uint64_t ki_refs; /* PTR: referencing socket */ |
435 | __uint64_t ki_nextref; /* PTR: link in refs list */ |
436 | }; |
437 | |
438 | #define ki_src ki_s._kis_src |
439 | #define ki_dst ki_d._kid_dst |
440 | #define ki_spad ki_s._kis_pad |
441 | #define ki_dpad ki_d._kid_pad |
442 | |
443 | #define PCB_SLOP 20 |
444 | #define PCB_ALL 0 |
445 | |
446 | #endif /* _NETBSD_SOURCE */ |
447 | |
448 | #if defined(_NETBSD_SOURCE) |
449 | /* |
450 | * PF_ROUTE - Routing table |
451 | * |
452 | * Three additional levels are defined: |
453 | * Fourth: address family, 0 is wildcard |
454 | * Fifth: type of info, defined below |
455 | * Sixth: flag(s) to mask with for NET_RT_FLAGS |
456 | */ |
457 | #define NET_RT_DUMP 1 /* dump; may limit to a.f. */ |
458 | #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ |
459 | #define NET_RT_OOOIFLIST 3 /* old NET_RT_IFLIST (pre 1.5) */ |
460 | #define NET_RT_OOIFLIST 4 /* old NET_RT_IFLIST (pre-64bit time) */ |
461 | #define NET_RT_OIFLIST 5 /* old NET_RT_IFLIST (pre 8.0) */ |
462 | #define NET_RT_IFLIST 6 /* survey interface list */ |
463 | |
464 | #endif /* _NETBSD_SOURCE */ |
465 | |
466 | /* |
467 | * Maximum queue length specifiable by listen(2). |
468 | */ |
469 | #ifndef SOMAXCONN |
470 | #define SOMAXCONN 128 |
471 | #endif |
472 | |
473 | #include <sys/cdefs.h> |
474 | |
475 | /* |
476 | * Message header for recvmsg and sendmsg calls. |
477 | * Used value-result for recvmsg, value only for sendmsg. |
478 | */ |
479 | struct msghdr { |
480 | void *msg_name; /* optional address */ |
481 | socklen_t msg_namelen; /* size of address */ |
482 | struct iovec *msg_iov; /* scatter/gather array */ |
483 | int msg_iovlen; /* # elements in msg_iov */ |
484 | void *msg_control; /* ancillary data, see below */ |
485 | socklen_t msg_controllen; /* ancillary data buffer len */ |
486 | int msg_flags; /* flags on received message */ |
487 | }; |
488 | |
489 | #define MSG_OOB 0x0001 /* process out-of-band data */ |
490 | #define MSG_PEEK 0x0002 /* peek at incoming message */ |
491 | #define MSG_DONTROUTE 0x0004 /* send without using routing tables */ |
492 | #define MSG_EOR 0x0008 /* data completes record */ |
493 | #define MSG_TRUNC 0x0010 /* data discarded before delivery */ |
494 | #define MSG_CTRUNC 0x0020 /* control data lost before delivery */ |
495 | #define MSG_WAITALL 0x0040 /* wait for full request or error */ |
496 | #define MSG_DONTWAIT 0x0080 /* this message should be nonblocking */ |
497 | #define MSG_BCAST 0x0100 /* this message was rcvd using link-level brdcst */ |
498 | #define MSG_MCAST 0x0200 /* this message was rcvd using link-level mcast */ |
499 | #define MSG_NOSIGNAL 0x0400 /* do not generate SIGPIPE on EOF */ |
500 | #if defined(_NETBSD_SOURCE) |
501 | #define MSG_CMSG_CLOEXEC 0x0800 /* close on exec receiving fd */ |
502 | #define MSG_NBIO 0x1000 /* use non-blocking I/O */ |
503 | #define MSG_WAITFORONE 0x2000 /* recvmmsg() wait for one message */ |
504 | #define MSG_NOTIFICATION 0x4000 /* SCTP notification */ |
505 | |
506 | struct mmsghdr { |
507 | struct msghdr msg_hdr; |
508 | unsigned int msg_len; |
509 | }; |
510 | #endif |
511 | |
512 | /* Extra flags used internally only */ |
513 | #define MSG_USERFLAGS 0x0ffffff |
514 | #define MSG_NAMEMBUF 0x1000000 /* msg_name is an mbuf */ |
515 | #define MSG_CONTROLMBUF 0x2000000 /* msg_control is an mbuf */ |
516 | #define MSG_IOVUSRSPACE 0x4000000 /* msg_iov is in user space */ |
517 | #define MSG_LENUSRSPACE 0x8000000 /* address length is in user space */ |
518 | |
519 | /* |
520 | * Header for ancillary data objects in msg_control buffer. |
521 | * Used for additional information with/about a datagram |
522 | * not expressible by flags. The format is a sequence |
523 | * of message elements headed by cmsghdr structures. |
524 | */ |
525 | struct cmsghdr { |
526 | socklen_t cmsg_len; /* data byte count, including hdr */ |
527 | int cmsg_level; /* originating protocol */ |
528 | int cmsg_type; /* protocol-specific type */ |
529 | /* followed by u_char cmsg_data[]; */ |
530 | }; |
531 | |
532 | /* |
533 | * Alignment requirement for CMSG struct manipulation. |
534 | * This basically behaves the same as ALIGN() ARCH/include/param.h. |
535 | * We declare it separately for two reasons: |
536 | * (1) avoid dependency between machine/param.h, and (2) to sync with kernel's |
537 | * idea of ALIGNBYTES at runtime. |
538 | * without (2), we can't guarantee binary compatibility in case of future |
539 | * changes in ALIGNBYTES. |
540 | */ |
541 | #define __CMSG_ALIGN(n) (((n) + __ALIGNBYTES) & ~__ALIGNBYTES) |
542 | |
543 | #ifdef _KERNEL |
544 | #define CMSG_ALIGN(n) __CMSG_ALIGN(n) |
545 | #endif |
546 | |
547 | #define __CMSG_ASIZE __CMSG_ALIGN(sizeof(struct cmsghdr)) |
548 | #define __CMSG_MSGNEXT(cmsg) \ |
549 | (__CASTV(char *, cmsg) + __CMSG_ALIGN((cmsg)->cmsg_len)) |
550 | #define __CMSG_MSGEND(mhdr) \ |
551 | (__CASTV(char *, (mhdr)->msg_control) + (mhdr)->msg_controllen) |
552 | |
553 | /* given pointer to struct cmsghdr, return pointer to data */ |
554 | #define CMSG_DATA(cmsg) (__CASTV(u_char *, cmsg) + __CMSG_ASIZE) |
555 | #define CCMSG_DATA(cmsg) (__CASTCV(const u_char *, cmsg) + __CMSG_ASIZE) |
556 | |
557 | /* given pointer to struct cmsghdr, return pointer to next cmsghdr */ |
558 | #define CMSG_NXTHDR(mhdr, cmsg) \ |
559 | __CASTV(struct cmsghdr *, \ |
560 | __CMSG_MSGNEXT(cmsg) + __CMSG_ASIZE > __CMSG_MSGEND(mhdr) ? 0 : \ |
561 | __CMSG_MSGNEXT(cmsg)) |
562 | |
563 | /* |
564 | * RFC 2292 requires to check msg_controllen, in case that the kernel returns |
565 | * an empty list for some reasons. |
566 | */ |
567 | #define CMSG_FIRSTHDR(mhdr) \ |
568 | __CASTV(struct cmsghdr *, \ |
569 | (mhdr)->msg_controllen < sizeof(struct cmsghdr) ? 0 : \ |
570 | (mhdr)->msg_control) |
571 | |
572 | #define CMSG_SPACE(l) (__CMSG_ASIZE + __CMSG_ALIGN(l)) |
573 | #define CMSG_LEN(l) (__CMSG_ASIZE + (l)) |
574 | |
575 | /* "Socket"-level control message types: */ |
576 | #define SCM_RIGHTS 0x01 /* access rights (array of int) */ |
577 | #if defined(_NETBSD_SOURCE) |
578 | /* 0x02 timestamp (struct timeval50) */ |
579 | /* 0x04 credentials (struct sockcred70) */ |
580 | #define SCM_TIMESTAMP 0x08 /* timestamp (struct timeval) */ |
581 | #define SCM_CREDS 0x10 /* credentials (struct sockcred) */ |
582 | #endif |
583 | |
584 | /* |
585 | * Types of socket shutdown(2). |
586 | */ |
587 | #define SHUT_RD 0 /* Disallow further receives. */ |
588 | #define SHUT_WR 1 /* Disallow further sends. */ |
589 | #define SHUT_RDWR 2 /* Disallow further sends/receives. */ |
590 | |
591 | #ifdef _KERNEL |
592 | static __inline socklen_t |
593 | sockaddr_getlen(const struct sockaddr *sa) |
594 | { |
595 | return sa->sa_len; |
596 | } |
597 | |
598 | __BEGIN_DECLS |
599 | socklen_t sockaddr_getsize_by_family(sa_family_t); |
600 | struct sockaddr *sockaddr_copy(struct sockaddr *, socklen_t, |
601 | const struct sockaddr *); |
602 | struct sockaddr *sockaddr_externalize(struct sockaddr *, socklen_t, |
603 | const struct sockaddr *); |
604 | struct sockaddr *sockaddr_alloc(sa_family_t, socklen_t, int); |
605 | const void *sockaddr_const_addr(const struct sockaddr *, socklen_t *); |
606 | void *sockaddr_addr(struct sockaddr *, socklen_t *); |
607 | const struct sockaddr *sockaddr_any(const struct sockaddr *); |
608 | const struct sockaddr *sockaddr_any_by_family(sa_family_t); |
609 | const void *sockaddr_anyaddr(const struct sockaddr *, socklen_t *); |
610 | int sockaddr_cmp(const struct sockaddr *, const struct sockaddr *); |
611 | struct sockaddr *sockaddr_dup(const struct sockaddr *, int); |
612 | int sockaddr_format(const struct sockaddr *, char *, size_t); |
613 | void sockaddr_free(struct sockaddr *); |
614 | __END_DECLS |
615 | #endif /* _KERNEL */ |
616 | |
617 | #ifndef _KERNEL |
618 | |
619 | __BEGIN_DECLS |
620 | int accept(int, struct sockaddr * __restrict, socklen_t * __restrict); |
621 | int accept4(int, struct sockaddr * __restrict, socklen_t * __restrict, int); |
622 | int bind(int, const struct sockaddr *, socklen_t); |
623 | int connect(int, const struct sockaddr *, socklen_t); |
624 | int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict); |
625 | int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict); |
626 | int getsockopt(int, int, int, void *__restrict, socklen_t * __restrict); |
627 | int getsockopt2(int, int, int, void *__restrict, socklen_t * __restrict); |
628 | int listen(int, int); |
629 | int paccept(int, struct sockaddr * __restrict, socklen_t * __restrict, |
630 | const sigset_t * __restrict, int); |
631 | ssize_t recv(int, void *, size_t, int); |
632 | ssize_t recvfrom(int, void *__restrict, size_t, int, |
633 | struct sockaddr * __restrict, socklen_t * __restrict); |
634 | ssize_t recvmsg(int, struct msghdr *, int); |
635 | ssize_t send(int, const void *, size_t, int); |
636 | ssize_t sendto(int, const void *, |
637 | size_t, int, const struct sockaddr *, socklen_t); |
638 | ssize_t sendmsg(int, const struct msghdr *, int); |
639 | int setsockopt(int, int, int, const void *, socklen_t); |
640 | int shutdown(int, int); |
641 | int sockatmark(int); |
642 | int socket(int, int, int) |
643 | #if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE) |
644 | __RENAME(__socket30) |
645 | #endif |
646 | ; |
647 | int socketpair(int, int, int, int *); |
648 | |
649 | #if defined(_NETBSD_SOURCE) |
650 | int sendmmsg(int, struct mmsghdr *, unsigned int, unsigned int); |
651 | struct timespec; |
652 | int recvmmsg(int, struct mmsghdr *, unsigned int, unsigned int, |
653 | struct timespec *); |
654 | #endif |
655 | __END_DECLS |
656 | #endif /* !_KERNEL */ |
657 | |
658 | #endif /* !_SYS_SOCKET_H_ */ |
659 | |