1 /* $OpenBSD: socket.h,v 1.106 2024/12/15 11:00:05 dlg Exp $ */ 2 /* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */ 3 4 /* 5 * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 6 * The Regents of the University of California. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)socket.h 8.4 (Berkeley) 2/21/94 33 */ 34 35 #ifndef _SYS_SOCKET_H_ 36 #define _SYS_SOCKET_H_ 37 38 /* get the definitions for struct iovec, size_t, ssize_t, and <sys/cdefs.h> */ 39 #include <sys/uio.h> 40 41 #if __BSD_VISIBLE 42 #include <sys/types.h> /* for off_t, uid_t, and gid_t */ 43 #endif 44 45 #ifndef _SOCKLEN_T_DEFINED_ 46 #define _SOCKLEN_T_DEFINED_ 47 typedef __socklen_t socklen_t; /* length type for network syscalls */ 48 #endif 49 50 #ifndef _SA_FAMILY_T_DEFINED_ 51 #define _SA_FAMILY_T_DEFINED_ 52 typedef __sa_family_t sa_family_t; /* sockaddr address family type */ 53 #endif 54 55 56 /* 57 * Definitions related to sockets: types, address families, options. 58 */ 59 60 /* 61 * Types 62 */ 63 #define SOCK_STREAM 1 /* stream socket */ 64 #define SOCK_DGRAM 2 /* datagram socket */ 65 #define SOCK_RAW 3 /* raw-protocol interface */ 66 #define SOCK_RDM 4 /* reliably-delivered message */ 67 #define SOCK_SEQPACKET 5 /* sequenced packet stream */ 68 #ifdef _KERNEL 69 #define SOCK_TYPE_MASK 0x000F /* mask that covers the above */ 70 #endif 71 72 /* 73 * Socket creation flags 74 */ 75 #if __BSD_VISIBLE 76 #define SOCK_CLOEXEC 0x8000 /* set FD_CLOEXEC */ 77 #define SOCK_NONBLOCK 0x4000 /* set O_NONBLOCK */ 78 #ifdef _KERNEL 79 #define SOCK_NONBLOCK_INHERIT 0x2000 /* inherit O_NONBLOCK from listener */ 80 #endif 81 #define SOCK_DNS 0x1000 /* set SS_DNS */ 82 #endif /* __BSD_VISIBLE */ 83 84 /* 85 * Option flags per-socket. 86 */ 87 #define SO_DEBUG 0x0001 /* turn on debugging info recording */ 88 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 89 #define SO_REUSEADDR 0x0004 /* allow local address reuse */ 90 #define SO_KEEPALIVE 0x0008 /* keep connections alive */ 91 #define SO_DONTROUTE 0x0010 /* just use interface addresses */ 92 #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ 93 #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ 94 #define SO_LINGER 0x0080 /* linger on close if data present */ 95 #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ 96 #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ 97 #define SO_TIMESTAMP 0x0800 /* timestamp received dgram traffic */ 98 #define SO_BINDANY 0x1000 /* allow bind to any address */ 99 #define SO_ZEROIZE 0x2000 /* zero out all mbufs sent over socket */ 100 101 /* 102 * Additional options, not kept in so_options. 103 */ 104 #define SO_SNDBUF 0x1001 /* send buffer size */ 105 #define SO_RCVBUF 0x1002 /* receive buffer size */ 106 #define SO_SNDLOWAT 0x1003 /* send low-water mark */ 107 #define SO_RCVLOWAT 0x1004 /* receive low-water mark */ 108 #define SO_SNDTIMEO 0x1005 /* send timeout */ 109 #define SO_RCVTIMEO 0x1006 /* receive timeout */ 110 #define SO_ERROR 0x1007 /* get error status and clear */ 111 #define SO_TYPE 0x1008 /* get socket type */ 112 #define SO_NETPROC 0x1020 /* multiplex; network processing */ 113 #define SO_RTABLE 0x1021 /* routing table to be used */ 114 #define SO_PEERCRED 0x1022 /* get connect-time credentials */ 115 #define SO_SPLICE 0x1023 /* splice data to other socket */ 116 #define SO_DOMAIN 0x1024 /* get socket domain */ 117 #define SO_PROTOCOL 0x1025 /* get socket protocol */ 118 119 /* 120 * Structure used for manipulating linger option. 121 */ 122 struct linger { 123 int l_onoff; /* option on/off */ 124 int l_linger; /* linger time */ 125 }; 126 127 #if __BSD_VISIBLE 128 129 #ifndef _TIMEVAL_DECLARED 130 #define _TIMEVAL_DECLARED 131 struct timeval { 132 time_t tv_sec; /* seconds */ 133 suseconds_t tv_usec; /* and microseconds */ 134 }; 135 #endif 136 137 /* 138 * Structure used for manipulating splice option. 139 */ 140 struct splice { 141 int sp_fd; /* drain socket file descriptor */ 142 off_t sp_max; /* if set, maximum bytes to splice */ 143 struct timeval sp_idle; /* idle timeout */ 144 }; 145 146 /* 147 * Maximum number of alternate routing tables 148 */ 149 #define RT_TABLEID_MAX 255 150 #define RT_TABLEID_BITS 8 151 #define RT_TABLEID_MASK 0xff 152 153 #endif /* __BSD_VISIBLE */ 154 155 /* 156 * Level number for (get/set)sockopt() to apply to socket itself. 157 */ 158 #define SOL_SOCKET 0xffff /* options for socket level */ 159 160 /* 161 * Address families. 162 */ 163 #define AF_UNSPEC 0 /* unspecified */ 164 #define AF_UNIX 1 /* local to host */ 165 #define AF_LOCAL AF_UNIX /* draft POSIX compatibility */ 166 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 167 #define AF_IMPLINK 3 /* arpanet imp addresses */ 168 #define AF_PUP 4 /* pup protocols: e.g. BSP */ 169 #define AF_CHAOS 5 /* mit CHAOS protocols */ 170 #define AF_NS 6 /* XEROX NS protocols */ 171 #define AF_ISO 7 /* ISO protocols */ 172 #define AF_OSI AF_ISO 173 #define AF_ECMA 8 /* european computer manufacturers */ 174 #define AF_DATAKIT 9 /* datakit protocols */ 175 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 176 #define AF_SNA 11 /* IBM SNA */ 177 #define AF_DECnet 12 /* DECnet */ 178 #define AF_DLI 13 /* DEC Direct data link interface */ 179 #define AF_LAT 14 /* LAT */ 180 #define AF_HYLINK 15 /* NSC Hyperchannel */ 181 #define AF_APPLETALK 16 /* Apple Talk */ 182 #define AF_ROUTE 17 /* Internal Routing Protocol */ 183 #define AF_LINK 18 /* Link layer interface */ 184 #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ 185 #define AF_COIP 20 /* connection-oriented IP, aka ST II */ 186 #define AF_CNT 21 /* Computer Network Technology */ 187 #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ 188 #define AF_IPX 23 /* Novell Internet Protocol */ 189 #define AF_INET6 24 /* IPv6 */ 190 #define pseudo_AF_PIP 25 /* Help Identify PIP packets */ 191 #define AF_ISDN 26 /* Integrated Services Digital Network*/ 192 #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ 193 #define AF_NATM 27 /* native ATM access */ 194 #define AF_ENCAP 28 195 #define AF_SIP 29 /* Simple Internet Protocol */ 196 #define AF_KEY 30 197 #define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers 198 in interface output routine */ 199 #define AF_BLUETOOTH 32 /* Bluetooth */ 200 #define AF_MPLS 33 /* MPLS */ 201 #define pseudo_AF_PFLOW 34 /* pflow */ 202 #define pseudo_AF_PIPEX 35 /* PIPEX */ 203 #define AF_FRAME 36 /* frame (Ethernet) sockets */ 204 #define AF_MAX 37 205 206 /* 207 * Structure used by kernel to store most 208 * addresses. 209 */ 210 struct sockaddr { 211 __uint8_t sa_len; /* total length */ 212 sa_family_t sa_family; /* address family */ 213 char sa_data[14]; /* actually longer; address value */ 214 }; 215 216 /* 217 * Sockaddr type which can hold any sockaddr type available 218 * in the system. 219 * 220 * Note: __ss_{len,family} is defined in RFC2553. During RFC2553 discussion 221 * the field name went back and forth between ss_len and __ss_len, 222 * and RFC2553 specifies it to be __ss_len. openbsd picked ss_len. 223 * For maximum portability, userland programmer would need to 224 * (1) make the code never touch ss_len portion (cast it into sockaddr and 225 * touch sa_len), or (2) add "-Dss_len=__ss_len" into CFLAGS to unify all 226 * occurrences (including header file) to __ss_len. 227 */ 228 struct sockaddr_storage { 229 __uint8_t ss_len; /* total length */ 230 sa_family_t ss_family; /* address family */ 231 unsigned char __ss_pad1[6]; /* align to quad */ 232 __uint64_t __ss_pad2; /* force alignment for stupid compilers */ 233 unsigned char __ss_pad3[240]; /* pad to a total of 256 bytes */ 234 }; 235 236 #ifdef _KERNEL 237 /* 238 * Structure used by kernel to pass protocol 239 * information in raw sockets. 240 */ 241 struct sockproto { 242 unsigned short sp_family; /* address family */ 243 unsigned short sp_protocol; /* protocol */ 244 }; 245 #endif /* _KERNEL */ 246 247 /* 248 * Protocol families, same as address families for now. 249 */ 250 #define PF_UNSPEC AF_UNSPEC 251 #define PF_LOCAL AF_LOCAL 252 #define PF_UNIX AF_UNIX 253 #define PF_INET AF_INET 254 #define PF_IMPLINK AF_IMPLINK 255 #define PF_PUP AF_PUP 256 #define PF_CHAOS AF_CHAOS 257 #define PF_NS AF_NS 258 #define PF_ISO AF_ISO 259 #define PF_OSI AF_ISO 260 #define PF_ECMA AF_ECMA 261 #define PF_DATAKIT AF_DATAKIT 262 #define PF_CCITT AF_CCITT 263 #define PF_SNA AF_SNA 264 #define PF_DECnet AF_DECnet 265 #define PF_DLI AF_DLI 266 #define PF_LAT AF_LAT 267 #define PF_HYLINK AF_HYLINK 268 #define PF_APPLETALK AF_APPLETALK 269 #define PF_ROUTE AF_ROUTE 270 #define PF_LINK AF_LINK 271 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ 272 #define PF_COIP AF_COIP 273 #define PF_CNT AF_CNT 274 #define PF_IPX AF_IPX /* same format as AF_NS */ 275 #define PF_INET6 AF_INET6 276 #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ 277 #define PF_PIP pseudo_AF_PIP 278 #define PF_ISDN AF_ISDN 279 #define PF_NATM AF_NATM 280 #define PF_ENCAP AF_ENCAP 281 #define PF_SIP AF_SIP 282 #define PF_KEY AF_KEY 283 #define PF_BPF pseudo_AF_HDRCMPLT 284 #define PF_BLUETOOTH AF_BLUETOOTH 285 #define PF_MPLS AF_MPLS 286 #define PF_PFLOW pseudo_AF_PFLOW 287 #define PF_PIPEX pseudo_AF_PIPEX 288 #define PF_FRAME AF_FRAME 289 #define PF_MAX AF_MAX 290 291 /* 292 * These are the valid values for the "how" field used by shutdown(2). 293 */ 294 #define SHUT_RD 0 295 #define SHUT_WR 1 296 #define SHUT_RDWR 2 297 298 #if __BSD_VISIBLE 299 #define SA_LEN(x) ((x)->sa_len) 300 301 /* Read using getsockopt() with SOL_SOCKET, SO_PEERCRED */ 302 struct sockpeercred { 303 uid_t uid; /* effective user id */ 304 gid_t gid; /* effective group id */ 305 pid_t pid; 306 }; 307 308 /* 309 * Definitions for network related sysctl, CTL_NET. 310 * 311 * Second level is protocol family. 312 * Third level is protocol number. 313 * 314 * Further levels are defined by the individual families below. 315 */ 316 #define NET_MAXID AF_MAX 317 318 #define CTL_NET_NAMES { \ 319 { 0, 0 }, \ 320 { "unix", CTLTYPE_NODE }, \ 321 { "inet", CTLTYPE_NODE }, \ 322 { "implink", CTLTYPE_NODE }, \ 323 { "pup", CTLTYPE_NODE }, \ 324 { "chaos", CTLTYPE_NODE }, \ 325 { "xerox_ns", CTLTYPE_NODE }, \ 326 { "iso", CTLTYPE_NODE }, \ 327 { "ecma", CTLTYPE_NODE }, \ 328 { "datakit", CTLTYPE_NODE }, \ 329 { "ccitt", CTLTYPE_NODE }, \ 330 { "ibm_sna", CTLTYPE_NODE }, \ 331 { "decnet", CTLTYPE_NODE }, \ 332 { "dec_dli", CTLTYPE_NODE }, \ 333 { "lat", CTLTYPE_NODE }, \ 334 { "hylink", CTLTYPE_NODE }, \ 335 { "appletalk", CTLTYPE_NODE }, \ 336 { "route", CTLTYPE_NODE }, \ 337 { "link", CTLTYPE_NODE }, \ 338 { "xtp", CTLTYPE_NODE }, \ 339 { "coip", CTLTYPE_NODE }, \ 340 { "cnt", CTLTYPE_NODE }, \ 341 { "rtip", CTLTYPE_NODE }, \ 342 { "ipx", CTLTYPE_NODE }, \ 343 { "inet6", CTLTYPE_NODE }, \ 344 { "pip", CTLTYPE_NODE }, \ 345 { "isdn", CTLTYPE_NODE }, \ 346 { "natm", CTLTYPE_NODE }, \ 347 { "encap", CTLTYPE_NODE }, \ 348 { "sip", CTLTYPE_NODE }, \ 349 { "key", CTLTYPE_NODE }, \ 350 { "bpf", CTLTYPE_NODE }, \ 351 { "bluetooth", CTLTYPE_NODE }, \ 352 { "mpls", CTLTYPE_NODE }, \ 353 { "pflow", CTLTYPE_NODE }, \ 354 { "pipex", CTLTYPE_NODE }, \ 355 } 356 357 /* 358 * PF_ROUTE - Routing table 359 * 360 * Four additional levels are defined: 361 * Fourth: address family, 0 is wildcard 362 * Fifth: type of info, defined below 363 * Sixth: flag(s) to mask with for NET_RT_FLAGS 364 * Seventh: routing table to use (facultative, defaults to 0) 365 * NET_RT_TABLE has the table id as sixth element. 366 */ 367 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */ 368 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ 369 #define NET_RT_IFLIST 3 /* survey interface list */ 370 #define NET_RT_STATS 4 /* routing table statistics */ 371 #define NET_RT_TABLE 5 372 #define NET_RT_IFNAMES 6 373 #define NET_RT_SOURCE 7 374 #define NET_RT_MAXID 8 375 376 #define CTL_NET_RT_NAMES { \ 377 { 0, 0 }, \ 378 { "dump", CTLTYPE_STRUCT }, \ 379 { "flags", CTLTYPE_STRUCT }, \ 380 { "iflist", CTLTYPE_STRUCT }, \ 381 { "stats", CTLTYPE_STRUCT }, \ 382 { "table", CTLTYPE_STRUCT }, \ 383 { "ifnames", CTLTYPE_STRUCT }, \ 384 { "source", CTLTYPE_STRUCT }, \ 385 } 386 387 /* 388 * PF_UNIX - unix socket tunables 389 */ 390 #define NET_UNIX_INFLIGHT 6 391 #define NET_UNIX_DEFERRED 7 392 #define NET_UNIX_MAXID 8 393 394 #define CTL_NET_UNIX_NAMES { \ 395 { 0, 0 }, \ 396 { "stream", CTLTYPE_NODE }, \ 397 { "dgram", CTLTYPE_NODE }, \ 398 { 0, 0 }, \ 399 { 0, 0 }, \ 400 { "seqpacket", CTLTYPE_NODE }, \ 401 { "inflight", CTLTYPE_INT }, \ 402 { "deferred", CTLTYPE_INT }, \ 403 } 404 405 #define UNPCTL_RECVSPACE 1 406 #define UNPCTL_SENDSPACE 2 407 #define NET_UNIX_PROTO_MAXID 3 408 409 #define CTL_NET_UNIX_PROTO_NAMES { \ 410 { 0, 0 }, \ 411 { "recvspace", CTLTYPE_INT }, \ 412 { "sendspace", CTLTYPE_INT }, \ 413 } 414 415 /* 416 * PF_LINK - link layer or device tunables 417 */ 418 #define NET_LINK_IFRXQ 1 /* net.link.ifrxq */ 419 #define NET_LINK_MAXID 2 420 421 #define CTL_NET_LINK_NAMES { \ 422 { 0, 0 }, \ 423 { "ifrxq", CTLTYPE_NODE }, \ 424 } 425 426 #define NET_LINK_IFRXQ_PRESSURE_RETURN \ 427 1 /* net.link.ifrxq.pressure_return */ 428 #define NET_LINK_IFRXQ_PRESSURE_DROP \ 429 2 /* net.link.ifrxq.pressure_drop */ 430 #define NET_LINK_IFRXQ_MAXID 3 431 432 #define CTL_NET_LINK_IFRXQ_NAMES { \ 433 { 0, 0 }, \ 434 { "pressure_return", CTLTYPE_INT }, \ 435 { "pressure_drop", CTLTYPE_INT }, \ 436 } 437 438 /* 439 * PF_KEY - Key Management 440 */ 441 #define NET_KEY_SADB_DUMP 1 /* return SADB */ 442 #define NET_KEY_SPD_DUMP 2 /* return SPD */ 443 #define NET_KEY_MAXID 3 444 445 #define CTL_NET_KEY_NAMES { \ 446 { 0, 0 }, \ 447 { "sadb_dump", CTLTYPE_STRUCT }, \ 448 { "spd_dump", CTLTYPE_STRUCT }, \ 449 } 450 451 /* 452 * PF_BPF not really a family, but connected under CTL_NET 453 */ 454 #define NET_BPF_BUFSIZE 1 /* default buffer size */ 455 #define NET_BPF_MAXBUFSIZE 2 /* maximum buffer size */ 456 #define NET_BPF_MAXID 3 457 458 #define CTL_NET_BPF_NAMES { \ 459 { 0, 0 }, \ 460 { "bufsize", CTLTYPE_INT }, \ 461 { "maxbufsize", CTLTYPE_INT }, \ 462 } 463 464 /* 465 * PF_PFLOW not really a family, but connected under CTL_NET 466 */ 467 #define NET_PFLOW_STATS 1 /* statistics */ 468 #define NET_PFLOW_MAXID 2 469 470 #define CTL_NET_PFLOW_NAMES { \ 471 { 0, 0 }, \ 472 { "stats", CTLTYPE_STRUCT }, \ 473 } 474 #endif /* __BSD_VISIBLE */ 475 476 /* 477 * Maximum queue length specifiable by listen(2). 478 */ 479 #define SOMAXCONN 128 480 481 /* 482 * Message header for recvmsg and sendmsg calls. 483 * Used value-result for recvmsg, value only for sendmsg. 484 */ 485 struct msghdr { 486 void *msg_name; /* optional address */ 487 socklen_t msg_namelen; /* size of address */ 488 struct iovec *msg_iov; /* scatter/gather array */ 489 unsigned int msg_iovlen; /* # elements in msg_iov */ 490 void *msg_control; /* ancillary data, see below */ 491 socklen_t msg_controllen; /* ancillary data buffer len */ 492 int msg_flags; /* flags on received message */ 493 }; 494 495 struct mmsghdr { 496 struct msghdr msg_hdr; 497 unsigned int msg_len; 498 }; 499 500 struct timespec; 501 502 #define MSG_OOB 0x1 /* process out-of-band data */ 503 #define MSG_PEEK 0x2 /* peek at incoming message */ 504 #define MSG_DONTROUTE 0x4 /* send without using routing tables */ 505 #define MSG_EOR 0x8 /* data completes record */ 506 #define MSG_TRUNC 0x10 /* data discarded before delivery */ 507 #define MSG_CTRUNC 0x20 /* control data lost before delivery */ 508 #define MSG_WAITALL 0x40 /* wait for full request or error */ 509 #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ 510 #define MSG_BCAST 0x100 /* this message rec'd as broadcast */ 511 #define MSG_MCAST 0x200 /* this message rec'd as multicast */ 512 #define MSG_NOSIGNAL 0x400 /* do not send SIGPIPE */ 513 #define MSG_CMSG_CLOEXEC 0x800 /* set FD_CLOEXEC on received fds */ 514 #define MSG_WAITFORONE 0x1000 /* nonblocking but wait for one msg */ 515 516 /* 517 * Header for ancillary data objects in msg_control buffer. 518 * Used for additional information with/about a datagram 519 * not expressible by flags. The format is a sequence 520 * of message elements headed by cmsghdr structures. 521 */ 522 struct cmsghdr { 523 socklen_t cmsg_len; /* data byte count, including hdr */ 524 int cmsg_level; /* originating protocol */ 525 int cmsg_type; /* protocol-specific type */ 526 /* followed by u_char cmsg_data[]; */ 527 }; 528 529 /* given pointer to struct cmsghdr, return pointer to data */ 530 #define CMSG_DATA(cmsg) \ 531 ((unsigned char *)(cmsg) + _ALIGN(sizeof(struct cmsghdr))) 532 533 /* given pointer to struct cmsghdr, return pointer to next cmsghdr */ 534 #define CMSG_NXTHDR(mhdr, cmsg) \ 535 (((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \ 536 _ALIGN(sizeof(struct cmsghdr)) > \ 537 ((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen) ? \ 538 (struct cmsghdr *)NULL : \ 539 (struct cmsghdr *)((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len))) 540 541 /* 542 * RFC 2292 requires to check msg_controllen, in case that the kernel returns 543 * an empty list for some reasons. 544 */ 545 #define CMSG_FIRSTHDR(mhdr) \ 546 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ 547 (struct cmsghdr *)(mhdr)->msg_control : \ 548 (struct cmsghdr *)NULL) 549 550 /* Round len up to next alignment boundary */ 551 #ifdef _KERNEL 552 #define CMSG_ALIGN(n) _ALIGN(n) 553 #endif 554 555 /* Length of the contents of a control message of length len */ 556 #define CMSG_LEN(len) (_ALIGN(sizeof(struct cmsghdr)) + (len)) 557 558 /* Length of the space taken up by a padded control message of length len */ 559 #define CMSG_SPACE(len) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(len)) 560 561 /* "Socket"-level control message types: */ 562 #define SCM_RIGHTS 0x01 /* access rights (array of int) */ 563 #define SCM_TIMESTAMP 0x04 /* timestamp (struct timeval) */ 564 565 #ifndef _KERNEL 566 567 __BEGIN_DECLS 568 int accept(int, struct sockaddr *, socklen_t *); 569 int bind(int, const struct sockaddr *, socklen_t); 570 int connect(int, const struct sockaddr *, socklen_t); 571 int getpeername(int, struct sockaddr *, socklen_t *); 572 int getsockname(int, struct sockaddr *, socklen_t *); 573 int getsockopt(int, int, int, void *, socklen_t *); 574 int listen(int, int); 575 ssize_t recv(int, void *, size_t, int); 576 ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *); 577 ssize_t recvmsg(int, struct msghdr *, int); 578 int recvmmsg(int, struct mmsghdr *, unsigned int, int, struct timespec *); 579 ssize_t send(int, const void *, size_t, int); 580 ssize_t sendto(int, const void *, 581 size_t, int, const struct sockaddr *, socklen_t); 582 ssize_t sendmsg(int, const struct msghdr *, int); 583 int sendmmsg(int, struct mmsghdr *, unsigned int, int); 584 int setsockopt(int, int, int, const void *, socklen_t); 585 int shutdown(int, int); 586 int sockatmark(int); 587 int socket(int, int, int); 588 int socketpair(int, int, int, int *); 589 590 #if __BSD_VISIBLE 591 int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); 592 #endif 593 594 #if __BSD_VISIBLE 595 int getpeereid(int, uid_t *, gid_t *); 596 int getrtable(void); 597 int setrtable(int); 598 #endif /* __BSD_VISIBLE */ 599 600 __END_DECLS 601 602 #else 603 604 static inline struct sockaddr * 605 sstosa(struct sockaddr_storage *ss) 606 { 607 return ((struct sockaddr *)(ss)); 608 } 609 610 #endif /* !_KERNEL */ 611 612 #endif /* !_SYS_SOCKET_H_ */ 613