FreeBSD/Linux Kernel Cross Reference
sys/sys/socket.h
1 /* $NetBSD: socket.h,v 1.91 2008/08/04 03:55:47 tls 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
101 /*
102 * Socket types.
103 */
104 #define SOCK_STREAM 1 /* stream socket */
105 #define SOCK_DGRAM 2 /* datagram socket */
106 #define SOCK_RAW 3 /* raw-protocol interface */
107 #define SOCK_RDM 4 /* reliably-delivered message */
108 #define SOCK_SEQPACKET 5 /* sequenced packet stream */
109
110 /*
111 * Option flags per-socket.
112 */
113 #define SO_DEBUG 0x0001 /* turn on debugging info recording */
114 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
115 #define SO_REUSEADDR 0x0004 /* allow local address reuse */
116 #define SO_KEEPALIVE 0x0008 /* keep connections alive */
117 #define SO_DONTROUTE 0x0010 /* just use interface addresses */
118 #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
119 #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
120 #define SO_LINGER 0x0080 /* linger on close if data present */
121 #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
122 #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
123 #define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */
124 #define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
125
126
127 /*
128 * Additional options, not kept in so_options.
129 */
130 #define SO_SNDBUF 0x1001 /* send buffer size */
131 #define SO_RCVBUF 0x1002 /* receive buffer size */
132 #define SO_SNDLOWAT 0x1003 /* send low-water mark */
133 #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
134 #define SO_SNDTIMEO 0x1005 /* send timeout */
135 #define SO_RCVTIMEO 0x1006 /* receive timeout */
136 #define SO_ERROR 0x1007 /* get error status and clear */
137 #define SO_TYPE 0x1008 /* get socket type */
138 #define SO_OVERFLOWED 0x1009 /* datagrams: return packets dropped */
139
140 #define SO_NOHEADER 0x100a /* user supplies no header to kernel;
141 * kernel removes header and supplies
142 * payload
143 */
144 /*
145 * Structure used for manipulating linger option.
146 */
147 struct linger {
148 int l_onoff; /* option on/off */
149 int l_linger; /* linger time in seconds */
150 };
151
152 struct accept_filter_arg {
153 char af_name[16];
154 char af_arg[256-16];
155 };
156
157 /*
158 * Level number for (get/set)sockopt() to apply to socket itself.
159 */
160 #define SOL_SOCKET 0xffff /* options for socket level */
161
162 /*
163 * Address families.
164 */
165 #define AF_UNSPEC 0 /* unspecified */
166 #define AF_LOCAL 1 /* local to host (pipes, portals) */
167 #define AF_UNIX AF_LOCAL /* backward compatibility */
168 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
169 #define AF_IMPLINK 3 /* arpanet imp addresses */
170 #define AF_PUP 4 /* pup protocols: e.g. BSP */
171 #define AF_CHAOS 5 /* mit CHAOS protocols */
172 #define AF_NS 6 /* XEROX NS protocols */
173 #define AF_ISO 7 /* ISO protocols */
174 #define AF_OSI AF_ISO
175 #define AF_ECMA 8 /* european computer manufacturers */
176 #define AF_DATAKIT 9 /* datakit protocols */
177 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
178 #define AF_SNA 11 /* IBM SNA */
179 #define AF_DECnet 12 /* DECnet */
180 #define AF_DLI 13 /* DEC Direct data link interface */
181 #define AF_LAT 14 /* LAT */
182 #define AF_HYLINK 15 /* NSC Hyperchannel */
183 #define AF_APPLETALK 16 /* Apple Talk */
184 #define AF_ROUTE 17 /* Internal Routing Protocol */
185 #define AF_LINK 18 /* Link layer interface */
186 #if defined(_NETBSD_SOURCE)
187 #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
188 #endif
189 #define AF_COIP 20 /* connection-oriented IP, aka ST II */
190 #define AF_CNT 21 /* Computer Network Technology */
191 #if defined(_NETBSD_SOURCE)
192 #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
193 #endif
194 #define AF_IPX 23 /* Novell Internet Protocol */
195 #define AF_INET6 24 /* IP version 6 */
196 #if defined(_NETBSD_SOURCE)
197 #define pseudo_AF_PIP 25 /* Help Identify PIP packets */
198 #endif
199 #define AF_ISDN 26 /* Integrated Services Digital Network*/
200 #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
201 #define AF_NATM 27 /* native ATM access */
202 #define AF_ARP 28 /* (rev.) addr. res. prot. (RFC 826) */
203 #if defined(_NETBSD_SOURCE)
204 #define pseudo_AF_KEY 29 /* Internal key management protocol */
205 #define pseudo_AF_HDRCMPLT 30 /* Used by BPF to not rewrite hdrs
206 in interface output routine */
207 #endif
208 #define AF_BLUETOOTH 31 /* Bluetooth: HCI, SCO, L2CAP, RFCOMM */
209 #define AF_IEEE80211 32 /* IEEE80211 */
210
211 #define AF_MAX 33
212
213 /*
214 * Structure used by kernel to store most
215 * addresses.
216 */
217 struct sockaddr {
218 __uint8_t sa_len; /* total length */
219 sa_family_t sa_family; /* address family */
220 char sa_data[14]; /* actually longer; address value */
221 };
222
223 #if defined(_KERNEL)
224 /*
225 * Structure used by kernel to pass protocol
226 * information in raw sockets.
227 */
228 struct sockproto {
229 u_short sp_family; /* address family */
230 u_short sp_protocol; /* protocol */
231 };
232 #endif /* _KERNEL */
233
234 #if 1
235 /*
236 * RFC 2553: protocol-independent placeholder for socket addresses
237 */
238 #define _SS_MAXSIZE 128
239 #define _SS_ALIGNSIZE (sizeof(__int64_t))
240 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - 2)
241 #define _SS_PAD2SIZE (_SS_MAXSIZE - 2 - \
242 _SS_PAD1SIZE - _SS_ALIGNSIZE)
243
244 #if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
245 struct sockaddr_storage {
246 __uint8_t ss_len; /* address length */
247 sa_family_t ss_family; /* address family */
248 char __ss_pad1[_SS_PAD1SIZE];
249 __int64_t __ss_align;/* force desired structure storage alignment */
250 char __ss_pad2[_SS_PAD2SIZE];
251 };
252 #define sstosa(__ss) ((struct sockaddr *)(__ss))
253 #define sstocsa(__ss) ((const struct sockaddr *)(__ss))
254 #endif /* _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */
255 #endif /* 1 */
256
257 /*
258 * Protocol families, same as address families for now.
259 */
260 #define PF_UNSPEC AF_UNSPEC
261 #define PF_LOCAL AF_LOCAL
262 #define PF_UNIX PF_LOCAL /* backward compatibility */
263 #define PF_INET AF_INET
264 #define PF_IMPLINK AF_IMPLINK
265 #define PF_PUP AF_PUP
266 #define PF_CHAOS AF_CHAOS
267 #define PF_NS AF_NS
268 #define PF_ISO AF_ISO
269 #define PF_OSI AF_ISO
270 #define PF_ECMA AF_ECMA
271 #define PF_DATAKIT AF_DATAKIT
272 #define PF_CCITT AF_CCITT
273 #define PF_SNA AF_SNA
274 #define PF_DECnet AF_DECnet
275 #define PF_DLI AF_DLI
276 #define PF_LAT AF_LAT
277 #define PF_HYLINK AF_HYLINK
278 #define PF_APPLETALK AF_APPLETALK
279 #define PF_ROUTE AF_ROUTE
280 #define PF_LINK AF_LINK
281 #if defined(_NETBSD_SOURCE)
282 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
283 #endif
284 #define PF_COIP AF_COIP
285 #define PF_CNT AF_CNT
286 #define PF_INET6 AF_INET6
287 #define PF_IPX AF_IPX /* same format as AF_NS */
288 #if defined(_NETBSD_SOURCE)
289 #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
290 #define PF_PIP pseudo_AF_PIP
291 #endif
292 #define PF_ISDN AF_ISDN /* same as E164 */
293 #define PF_E164 AF_E164
294 #define PF_NATM AF_NATM
295 #define PF_ARP AF_ARP
296 #if defined(_NETBSD_SOURCE)
297 #define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */
298 #endif
299 #define PF_BLUETOOTH AF_BLUETOOTH
300
301 #define PF_MAX AF_MAX
302
303 #if defined(_NETBSD_SOURCE)
304
305 #ifndef gid_t
306 typedef __gid_t gid_t; /* group id */
307 #define gid_t __gid_t
308 #endif
309
310 #ifndef uid_t
311 typedef __uid_t uid_t; /* user id */
312 #define uid_t __uid_t
313 #endif
314
315 /*
316 * Socket credentials.
317 */
318 struct sockcred {
319 uid_t sc_uid; /* real user id */
320 uid_t sc_euid; /* effective user id */
321 gid_t sc_gid; /* real group id */
322 gid_t sc_egid; /* effective group id */
323 int sc_ngroups; /* number of supplemental groups */
324 gid_t sc_groups[1]; /* variable length */
325 };
326
327 /*
328 * Compute size of a sockcred structure with groups.
329 */
330 #define SOCKCREDSIZE(ngrps) \
331 (sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
332 #endif /* _NETBSD_SOURCE */
333
334
335 #if defined(_NETBSD_SOURCE)
336 /*
337 * Definitions for network related sysctl, CTL_NET.
338 *
339 * Second level is protocol family.
340 * Third level is protocol number.
341 *
342 * Further levels are defined by the individual families below.
343 */
344 #define NET_MAXID AF_MAX
345
346 #define CTL_NET_NAMES { \
347 { 0, 0 }, \
348 { "local", CTLTYPE_NODE }, \
349 { "inet", CTLTYPE_NODE }, \
350 { "implink", CTLTYPE_NODE }, \
351 { "pup", CTLTYPE_NODE }, \
352 { "chaos", CTLTYPE_NODE }, \
353 { "xerox_ns", CTLTYPE_NODE }, \
354 { "iso", CTLTYPE_NODE }, \
355 { "emca", CTLTYPE_NODE }, \
356 { "datakit", CTLTYPE_NODE }, \
357 { "ccitt", CTLTYPE_NODE }, \
358 { "ibm_sna", CTLTYPE_NODE }, \
359 { "decnet", CTLTYPE_NODE }, \
360 { "dec_dli", CTLTYPE_NODE }, \
361 { "lat", CTLTYPE_NODE }, \
362 { "hylink", CTLTYPE_NODE }, \
363 { "appletalk", CTLTYPE_NODE }, \
364 { "route", CTLTYPE_NODE }, \
365 { "link_layer", CTLTYPE_NODE }, \
366 { "xtp", CTLTYPE_NODE }, \
367 { "coip", CTLTYPE_NODE }, \
368 { "cnt", CTLTYPE_NODE }, \
369 { "rtip", CTLTYPE_NODE }, \
370 { "ipx", CTLTYPE_NODE }, \
371 { "inet6", CTLTYPE_NODE }, \
372 { "pip", CTLTYPE_NODE }, \
373 { "isdn", CTLTYPE_NODE }, \
374 { "natm", CTLTYPE_NODE }, \
375 { "arp", CTLTYPE_NODE }, \
376 { "key", CTLTYPE_NODE }, \
377 }
378
379 struct kinfo_pcb {
380 __uint64_t ki_pcbaddr; /* PTR: pcb addr */
381 __uint64_t ki_ppcbaddr; /* PTR: ppcb addr */
382 __uint64_t ki_sockaddr; /* PTR: socket addr */
383
384 __uint32_t ki_family; /* INT: protocol family */
385 __uint32_t ki_type; /* INT: socket type */
386 __uint32_t ki_protocol; /* INT: protocol */
387 __uint32_t ki_pflags; /* INT: generic protocol flags */
388
389 __uint32_t ki_sostate; /* INT: socket state */
390 __uint32_t ki_prstate; /* INT: protocol state */
391 __int32_t ki_tstate; /* INT: tcp state */
392 __uint32_t ki_tflags; /* INT: tcp flags */
393
394 __uint64_t ki_rcvq; /* U_LONG: receive queue len */
395 __uint64_t ki_sndq; /* U_LONG: send queue len */
396
397 union {
398 struct sockaddr _kis_src; /* STRUCT: local address */
399 char _kis_pad[256 + 8]; /* pad to max addr length */
400 } ki_s;
401 union {
402 struct sockaddr _kid_dst; /* STRUCT: remote address */
403 char _kid_pad[256 + 8]; /* pad to max addr length */
404 } ki_d;
405
406 __uint64_t ki_inode; /* INO_T: fake inode number */
407 __uint64_t ki_vnode; /* PTR: if associated with file */
408 __uint64_t ki_conn; /* PTR: control block of peer */
409 __uint64_t ki_refs; /* PTR: referencing socket */
410 __uint64_t ki_nextref; /* PTR: link in refs list */
411 };
412
413 #define ki_src ki_s._kis_src
414 #define ki_dst ki_d._kid_dst
415
416 #define PCB_SLOP 20
417 #define PCB_ALL 0
418
419 #endif /* _NETBSD_SOURCE */
420
421 #if defined(_NETBSD_SOURCE)
422 /*
423 * PF_ROUTE - Routing table
424 *
425 * Three additional levels are defined:
426 * Fourth: address family, 0 is wildcard
427 * Fifth: type of info, defined below
428 * Sixth: flag(s) to mask with for NET_RT_FLAGS
429 */
430 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */
431 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
432 #define NET_RT_OIFLIST 3 /* old NET_RT_IFLIST (pre 1.5) */
433 #define NET_RT_IFLIST 4 /* survey interface list */
434 #define NET_RT_MAXID 5
435
436 #define CTL_NET_RT_NAMES { \
437 { 0, 0 }, \
438 { "dump", CTLTYPE_STRUCT }, \
439 { "flags", CTLTYPE_STRUCT }, \
440 { 0, 0 }, \
441 { "iflist", CTLTYPE_STRUCT }, \
442 }
443 #endif /* _NETBSD_SOURCE */
444
445 /*
446 * Maximum queue length specifiable by listen(2).
447 */
448 #ifndef SOMAXCONN
449 #define SOMAXCONN 128
450 #endif
451
452 /*
453 * Message header for recvmsg and sendmsg calls.
454 * Used value-result for recvmsg, value only for sendmsg.
455 */
456 struct msghdr {
457 void *msg_name; /* optional address */
458 socklen_t msg_namelen; /* size of address */
459 struct iovec *msg_iov; /* scatter/gather array */
460 int msg_iovlen; /* # elements in msg_iov */
461 void *msg_control; /* ancillary data, see below */
462 socklen_t msg_controllen; /* ancillary data buffer len */
463 int msg_flags; /* flags on received message */
464 };
465
466 #define MSG_OOB 0x0001 /* process out-of-band data */
467 #define MSG_PEEK 0x0002 /* peek at incoming message */
468 #define MSG_DONTROUTE 0x0004 /* send without using routing tables */
469 #define MSG_EOR 0x0008 /* data completes record */
470 #define MSG_TRUNC 0x0010 /* data discarded before delivery */
471 #define MSG_CTRUNC 0x0020 /* control data lost before delivery */
472 #define MSG_WAITALL 0x0040 /* wait for full request or error */
473 #define MSG_DONTWAIT 0x0080 /* this message should be nonblocking */
474 #define MSG_BCAST 0x0100 /* this message was rcvd using link-level brdcst */
475 #define MSG_MCAST 0x0200 /* this message was rcvd using link-level mcast */
476 #define MSG_NOSIGNAL 0x0400 /* do not generate SIGPIPE on EOF */
477
478 /* Extra flags used internally only */
479 #define MSG_USERFLAGS 0x0ffffff
480 #define MSG_NAMEMBUF 0x1000000 /* msg_name is an mbuf */
481 #define MSG_CONTROLMBUF 0x2000000 /* msg_control is an mbuf */
482 #define MSG_IOVUSRSPACE 0x4000000 /* msg_iov is in user space */
483 #define MSG_LENUSRSPACE 0x8000000 /* address length is in user space */
484
485 /*
486 * Header for ancillary data objects in msg_control buffer.
487 * Used for additional information with/about a datagram
488 * not expressible by flags. The format is a sequence
489 * of message elements headed by cmsghdr structures.
490 */
491 struct cmsghdr {
492 socklen_t cmsg_len; /* data byte count, including hdr */
493 int cmsg_level; /* originating protocol */
494 int cmsg_type; /* protocol-specific type */
495 /* followed by u_char cmsg_data[]; */
496 };
497
498 /* given pointer to struct cmsghdr, return pointer to data */
499 #define CMSG_DATA(cmsg) \
500 ((u_char *)(void *)(cmsg) + __CMSG_ALIGN(sizeof(struct cmsghdr)))
501 #define CCMSG_DATA(cmsg) \
502 ((const u_char *)(const void *)(cmsg) + \
503 __CMSG_ALIGN(sizeof(struct cmsghdr)))
504
505 /*
506 * Alignment requirement for CMSG struct manipulation.
507 * This basically behaves the same as ALIGN() ARCH/include/param.h.
508 * We declare it separately for two reasons:
509 * (1) avoid dependency between machine/param.h, and (2) to sync with kernel's
510 * idea of ALIGNBYTES at runtime.
511 * without (2), we can't guarantee binary compatibility in case of future
512 * changes in ALIGNBYTES.
513 */
514 #define __CMSG_ALIGN(n) (((n) + __cmsg_alignbytes()) & ~__cmsg_alignbytes())
515 #ifdef _KERNEL
516 #define CMSG_ALIGN(n) __CMSG_ALIGN(n)
517 #endif
518
519 /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
520 #define CMSG_NXTHDR(mhdr, cmsg) \
521 (((char *)(cmsg) + __CMSG_ALIGN((cmsg)->cmsg_len) + \
522 __CMSG_ALIGN(sizeof(struct cmsghdr)) > \
523 (((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \
524 (struct cmsghdr *)0 : \
525 (struct cmsghdr *)((char *)(cmsg) + \
526 __CMSG_ALIGN((cmsg)->cmsg_len)))
527
528 /*
529 * RFC 2292 requires to check msg_controllen, in case that the kernel returns
530 * an empty list for some reasons.
531 */
532 #define CMSG_FIRSTHDR(mhdr) \
533 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
534 (struct cmsghdr *)(mhdr)->msg_control : \
535 (struct cmsghdr *)0)
536
537 #define CMSG_SPACE(l) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(l))
538 #define CMSG_LEN(l) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
539
540 /* "Socket"-level control message types: */
541 #define SCM_RIGHTS 0x01 /* access rights (array of int) */
542 #if defined(_NETBSD_SOURCE)
543 #define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */
544 #define SCM_CREDS 0x04 /* credentials (struct sockcred) */
545 #endif
546
547 /*
548 * Types of socket shutdown(2).
549 */
550 #define SHUT_RD 0 /* Disallow further receives. */
551 #define SHUT_WR 1 /* Disallow further sends. */
552 #define SHUT_RDWR 2 /* Disallow further sends/receives. */
553
554 #include <sys/cdefs.h>
555
556 __BEGIN_DECLS
557 int __cmsg_alignbytes(void);
558 __END_DECLS
559
560 #ifdef _KERNEL
561 static inline socklen_t
562 sockaddr_getlen(const struct sockaddr *sa)
563 {
564 return sa->sa_len;
565 }
566
567 __BEGIN_DECLS
568 struct sockaddr *sockaddr_copy(struct sockaddr *, socklen_t,
569 const struct sockaddr *);
570 struct sockaddr *sockaddr_alloc(sa_family_t, socklen_t, int);
571 const void *sockaddr_const_addr(const struct sockaddr *, socklen_t *);
572 void *sockaddr_addr(struct sockaddr *, socklen_t *);
573 const struct sockaddr *sockaddr_any(const struct sockaddr *);
574 const void *sockaddr_anyaddr(const struct sockaddr *, socklen_t *);
575 int sockaddr_cmp(const struct sockaddr *, const struct sockaddr *);
576 struct sockaddr *sockaddr_dup(const struct sockaddr *, int);
577 void sockaddr_free(struct sockaddr *);
578 __END_DECLS
579 #endif /* _KERNEL */
580
581 #ifndef _KERNEL
582
583 __BEGIN_DECLS
584 int accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
585 int bind(int, const struct sockaddr *, socklen_t);
586 int connect(int, const struct sockaddr *, socklen_t);
587 int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
588 int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
589 int getsockopt(int, int, int, void *__restrict, socklen_t * __restrict);
590 int listen(int, int);
591 ssize_t recv(int, void *, size_t, int);
592 ssize_t recvfrom(int, void *__restrict, size_t, int,
593 struct sockaddr * __restrict, socklen_t * __restrict);
594 ssize_t recvmsg(int, struct msghdr *, int);
595 ssize_t send(int, const void *, size_t, int);
596 ssize_t sendto(int, const void *,
597 size_t, int, const struct sockaddr *, socklen_t);
598 ssize_t sendmsg(int, const struct msghdr *, int);
599 int setsockopt(int, int, int, const void *, socklen_t);
600 int shutdown(int, int);
601 int sockatmark(int);
602 int socket(int, int, int)
603 #if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE)
604 __RENAME(__socket30)
605 #endif
606 ;
607 int socketpair(int, int, int, int *);
608 __END_DECLS
609 #endif /* !_KERNEL */
610
611 #endif /* !_SYS_SOCKET_H_ */
Cache object: fba399df9e56a533e1b0aa664e32a277
|