1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  23  *
  24  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  25  */
  26 
  27 /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
  28 /*        All Rights Reserved   */
  29 
  30 /*
  31  * University Copyright- Copyright (c) 1982, 1986, 1988
  32  * The Regents of the University of California
  33  * All Rights Reserved
  34  *
  35  * University Acknowledgment- Portions of this document are derived from
  36  * software developed by the University of California, Berkeley, and its
  37  * contributors.
  38  */
  39 
  40 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
  41 
  42 #ifndef _SYS_SOCKET_H
  43 #define _SYS_SOCKET_H
  44 
  45 #include <sys/types.h>
  46 #include <sys/uio.h>
  47 #include <sys/feature_tests.h>
  48 #include <sys/socket_impl.h>
  49 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
  50 #ifndef _KERNEL
  51 #include <sys/netconfig.h>
  52 #endif  /* !_KERNEL */
  53 /*
  54  * Historically, netinet/in.h included sys/stream.h, which pulled in
  55  * several things.  The more troublesome namespace pollution was from
  56  * sys/stream.h so that was removed.  To avoid having to fix lots of
  57  * programs, pull in a few things that are now (for better or worse)
  58  * expected by programs that include sys/socket.h
  59  */
  60 #include <sys/param.h>
  61 #include <sys/cred.h>
  62 #include <sys/poll.h>
  63 #include <netinet/in.h>
  64 #endif  /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
  65 
  66 #ifdef  __cplusplus
  67 extern "C" {
  68 #endif
  69 
  70 #ifndef _SOCKLEN_T
  71 #define _SOCKLEN_T
  72 
  73 /*
  74  * The socklen definitions are reproduced in netinet/in.h for the inet6_
  75  * functions.  Exposing all of sys/socket.h via netinet/in.h breaks existing
  76  * applications and is not required by austin.
  77  */
  78 #if defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64)
  79 typedef size_t          socklen_t;
  80 #else
  81 typedef uint32_t        socklen_t;
  82 #endif  /* defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) */
  83 
  84 #if defined(_XPG4_2) || defined(_BOOT)
  85 typedef socklen_t       *_RESTRICT_KYWD Psocklen_t;
  86 #else
  87 typedef void            *_RESTRICT_KYWD Psocklen_t;
  88 #endif  /* defined(_XPG4_2) || defined(_BOOT) */
  89 
  90 #endif  /* _SOCKLEN_T */
  91 
  92 /*
  93  * Definitions related to sockets: types, address families, options.
  94  */
  95 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
  96 #ifndef NC_TPI_CLTS
  97 #define NC_TPI_CLTS     1               /* must agree with netconfig.h */
  98 #define NC_TPI_COTS     2               /* must agree with netconfig.h */
  99 #define NC_TPI_COTS_ORD 3               /* must agree with netconfig.h */
 100 #define NC_TPI_RAW      4               /* must agree with netconfig.h */
 101 #endif  /* !NC_TPI_CLTS */
 102 #endif  /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
 103 
 104 /*
 105  * Types
 106  */
 107 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
 108 #define SOCK_STREAM     NC_TPI_COTS     /* stream socket */
 109 #define SOCK_DGRAM      NC_TPI_CLTS     /* datagram socket */
 110 #define SOCK_RAW        NC_TPI_RAW      /* raw-protocol interface */
 111 #else
 112 #define SOCK_STREAM     2               /* stream socket */
 113 #define SOCK_DGRAM      1               /* datagram socket */
 114 #define SOCK_RAW        4               /* raw-protocol interface */
 115 #endif  /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
 116 #define SOCK_RDM        5               /* reliably-delivered message */
 117 #define SOCK_SEQPACKET  6               /* sequenced packet stream */
 118 #define SOCK_TYPE_MASK  0xffff          /* type reside in these bits only */
 119 
 120 /*
 121  * Flags for socket() and accept4()
 122  */
 123 #define SOCK_CLOEXEC    0x080000        /* like open(2) O_CLOEXEC for socket */
 124 #define SOCK_NONBLOCK   0x100000        /* like O_NONBLOCK */
 125 #define SOCK_NDELAY     0x200000        /* like O_NDELAY */
 126 
 127 /*
 128  * Option flags per-socket.
 129  */
 130 #define SO_DEBUG        0x0001          /* turn on debugging info recording */
 131 #define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
 132 #define SO_REUSEADDR    0x0004          /* allow local address reuse */
 133 #define SO_KEEPALIVE    0x0008          /* keep connections alive */
 134 #define SO_DONTROUTE    0x0010          /* just use interface addresses */
 135 #define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
 136 #define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
 137 #define SO_LINGER       0x0080          /* linger on close if data present */
 138 #define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
 139 #define SO_DGRAM_ERRIND 0x0200          /* Application wants delayed error */
 140 #define SO_RECVUCRED    0x0400          /* Application wants ucred of sender */
 141 
 142 /*
 143  * Socket options are passed using a signed integer, but it is also rare
 144  * for more than one to ever be passed at the same time with setsockopt
 145  * and only one at a time can be retrieved with getsockopt.
 146  *
 147  * Since the lower numbers cannot be renumbered for compatibility reasons,
 148  * it would seem that we need to start a new number space (0x40000000 -
 149  * 0x7fffffff) for those that don't need to be stored as a bit flag
 150  * somewhere. This limits the flag options to 30 but that seems to be
 151  * plenty, anyway. 0x40000000 is reserved for future use.
 152  */
 153 #define SO_ATTACH_FILTER        0x40000001
 154 #define SO_DETACH_FILTER        0x40000002
 155 
 156 #ifdef _KERNEL
 157 #define SO_SND_COPYAVOID 0x0800         /* Internal: use zero-copy */
 158 #define SO_SND_BUFINFO  0x1000          /* Internal: get buffer info */
 159                                         /* when doing zero-copy */
 160 
 161 struct so_snd_bufinfo {
 162         ushort_t        sbi_wroff;      /* Write offset */
 163         ssize_t         sbi_maxblk;     /* Max size of a single mblk */
 164         ssize_t         sbi_maxpsz;     /* Max total size of a mblk chain */
 165         ushort_t        sbi_tail;       /* Extra space available at the end */
 166 };
 167 #endif /* _KERNEL */
 168 
 169 /*
 170  * N.B.: The following definition is present only for compatibility
 171  * with release 3.0.  It will disappear in later releases.
 172  */
 173 #define SO_DONTLINGER   (~SO_LINGER)    /* ~SO_LINGER */
 174 
 175 /*
 176  * Additional options, not kept in so_options.
 177  */
 178 #define SO_SNDBUF       0x1001          /* send buffer size */
 179 #define SO_RCVBUF       0x1002          /* receive buffer size */
 180 #define SO_SNDLOWAT     0x1003          /* send low-water mark */
 181 #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
 182 #define SO_SNDTIMEO     0x1005          /* send timeout */
 183 #define SO_RCVTIMEO     0x1006          /* receive timeout */
 184 #define SO_ERROR        0x1007          /* get error status and clear */
 185 #define SO_TYPE         0x1008          /* get socket type */
 186 #define SO_PROTOTYPE    0x1009          /* get/set protocol type */
 187 #define SO_ANON_MLP     0x100a          /* create MLP on anonymous bind */
 188 #define SO_MAC_EXEMPT   0x100b          /* allow dominated unlabeled peers */
 189 #define SO_DOMAIN       0x100c          /* get socket domain */
 190 #define SO_RCVPSH       0x100d          /* receive interval to push data */
 191 
 192 /* "Socket"-level control message types: */
 193 #define SCM_RIGHTS      0x1010          /* access rights (array of int) */
 194 #define SO_SECATTR      0x1011          /* socket's security attributes */
 195 #define SCM_UCRED       0x1012          /* sender's ucred */
 196 #define SO_TIMESTAMP    0x1013          /* socket-level timestamp option */
 197 #define SCM_TIMESTAMP   SO_TIMESTAMP    /* socket control message timestamp */
 198 #define SO_ALLZONES     0x1014          /* bind in all zones */
 199 #define SO_EXCLBIND     0x1015          /* exclusive binding */
 200 #define SO_MAC_IMPLICIT 0x1016          /* hide mac labels on wire */
 201 #define SO_VRRP         0x1017          /* VRRP control socket */
 202 
 203 #ifdef  _KERNEL
 204 #define SO_SRCADDR      0x2001          /* Internal: AF_UNIX source address */
 205 #define SO_FILEP        0x2002          /* Internal: AF_UNIX file pointer */
 206 #define SO_UNIX_CLOSE   0x2003          /* Internal: AF_UNIX peer closed */
 207 #endif  /* _KERNEL */
 208 
 209 /*
 210  * Socket filter options
 211  */
 212 #define FIL_ATTACH      0x1             /* attach filter */
 213 #define FIL_DETACH      0x2             /* detach filter */
 214 #define FIL_LIST        0x3             /* list attached filters */
 215 
 216 #define FILNAME_MAX     32
 217 /*
 218  * Structure returned by FIL_LIST
 219  */
 220 struct fil_info {
 221         int     fi_flags;               /* see below (FILF_*) */
 222         int     fi_pos;                 /* position (0 is bottom) */
 223         char    fi_name[FILNAME_MAX];   /* filter name */
 224 };
 225 
 226 #define FILF_PROG       0x1             /* programmatic attach */
 227 #define FILF_AUTO       0x2             /* automatic attach */
 228 #define FILF_BYPASS     0x4             /* filter is not active */
 229 
 230 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
 231 /*
 232  * new socket open flags to identify socket and acceptor streams
 233  */
 234 #define SO_ACCEPTOR     0x20000         /* acceptor socket */
 235 #define SO_SOCKSTR      0x40000         /* normal socket stream */
 236 #define SO_FALLBACK     0x80000         /* fallback to TPI socket */
 237 
 238 /*
 239  * Flags for socket_create() and socket_newconn()
 240  */
 241 #define SOCKET_SLEEP    KM_SLEEP
 242 #define SOCKET_NOSLEEP  KM_NOSLEEP
 243 
 244 #endif  /* _KERNEL */
 245 
 246 /*
 247  * Structure used for manipulating linger option.
 248  */
 249 struct  linger {
 250         int     l_onoff;                /* option on/off */
 251         int     l_linger;               /* linger time */
 252 };
 253 
 254 /*
 255  * Levels for (get/set)sockopt() that don't apply to a specific protocol.
 256  */
 257 #define SOL_SOCKET      0xffff          /* options for socket level */
 258 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
 259 #define SOL_ROUTE       0xfffe          /* options for routing socket level */
 260 #endif
 261 #define SOL_PACKET      0xfffd          /* options for packet level */
 262 #define SOL_FILTER      0xfffc          /* options for socket filter level */
 263 
 264 /*
 265  * Address families.
 266  *
 267  * Some of these constant names are copied for the DTrace IP provider in
 268  * usr/src/lib/libdtrace/common/{ip.d.in, ip.sed.in}, which should be kept
 269  * in sync.
 270  */
 271 #define AF_UNSPEC       0               /* unspecified */
 272 #define AF_UNIX         1               /* local to host (pipes, portals) */
 273 #define AF_LOCAL        AF_UNIX         /* Synonym for AF_UNIX */
 274 #define AF_FILE         AF_UNIX         /* Synonym for AF_UNIX */
 275 #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
 276 #define AF_IMPLINK      3               /* arpanet imp addresses */
 277 #define AF_PUP          4               /* pup protocols: e.g. BSP */
 278 #define AF_CHAOS        5               /* mit CHAOS protocols */
 279 #define AF_NS           6               /* XEROX NS protocols */
 280 #define AF_NBS          7               /* nbs protocols */
 281 #define AF_ECMA         8               /* european computer manufacturers */
 282 #define AF_DATAKIT      9               /* datakit protocols */
 283 #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
 284 #define AF_SNA          11              /* IBM SNA */
 285 #define AF_DECnet       12              /* DECnet */
 286 #define AF_DLI          13              /* Direct data link interface */
 287 #define AF_LAT          14              /* LAT */
 288 #define AF_HYLINK       15              /* NSC Hyperchannel */
 289 #define AF_APPLETALK    16              /* Apple Talk */
 290 #define AF_NIT          17              /* Network Interface Tap */
 291 #define AF_802          18              /* IEEE 802.2, also ISO 8802 */
 292 #define AF_OSI          19              /* umbrella for all families used */
 293 #define AF_X25          20              /* CCITT X.25 in particular */
 294 #define AF_OSINET       21              /* AFI = 47, IDI = 4 */
 295 #define AF_GOSIP        22              /* U.S. Government OSI */
 296 #define AF_IPX          23              /* Novell Internet Protocol */
 297 #define AF_ROUTE        24              /* Internal Routing Protocol */
 298 #define AF_LINK         25              /* Link-layer interface */
 299 #define AF_INET6        26              /* Internet Protocol, Version 6 */
 300 #define AF_KEY          27              /* Security Association DB socket */
 301 #define AF_NCA          28              /* NCA socket */
 302 #define AF_POLICY       29              /* Security Policy DB socket */
 303 #define AF_INET_OFFLOAD 30              /* Sun private; do not use */
 304 #define AF_TRILL        31              /* TRILL interface */
 305 #define AF_PACKET       32              /* PF_PACKET Linux socket interface */
 306 
 307 #define AF_MAX          32
 308 
 309 /*
 310  * Protocol families, same as address families for now.
 311  */
 312 #define PF_UNSPEC       AF_UNSPEC
 313 #define PF_UNIX         AF_UNIX
 314 #define PF_LOCAL        PF_UNIX
 315 #define PF_FILE         PF_UNIX
 316 #define PF_INET         AF_INET
 317 #define PF_IMPLINK      AF_IMPLINK
 318 #define PF_PUP          AF_PUP
 319 #define PF_CHAOS        AF_CHAOS
 320 #define PF_NS           AF_NS
 321 #define PF_NBS          AF_NBS
 322 #define PF_ECMA         AF_ECMA
 323 #define PF_DATAKIT      AF_DATAKIT
 324 #define PF_CCITT        AF_CCITT
 325 #define PF_SNA          AF_SNA
 326 #define PF_DECnet       AF_DECnet
 327 #define PF_DLI          AF_DLI
 328 #define PF_LAT          AF_LAT
 329 #define PF_HYLINK       AF_HYLINK
 330 #define PF_APPLETALK    AF_APPLETALK
 331 #define PF_NIT          AF_NIT
 332 #define PF_802          AF_802
 333 #define PF_OSI          AF_OSI
 334 #define PF_X25          AF_X25
 335 #define PF_OSINET       AF_OSINET
 336 #define PF_GOSIP        AF_GOSIP
 337 #define PF_IPX          AF_IPX
 338 #define PF_ROUTE        AF_ROUTE
 339 #define PF_LINK         AF_LINK
 340 #define PF_INET6        AF_INET6
 341 #define PF_KEY          AF_KEY
 342 #define PF_NCA          AF_NCA
 343 #define PF_POLICY       AF_POLICY
 344 #define PF_INET_OFFLOAD AF_INET_OFFLOAD /* Sun private; do not use */
 345 #define PF_TRILL        AF_TRILL
 346 #define PF_PACKET       AF_PACKET
 347 
 348 #define PF_MAX          AF_MAX
 349 
 350 /*
 351  * Maximum queue length specifiable by listen.
 352  */
 353 #define SOMAXCONN       128
 354 
 355 /*
 356  * Message header for recvmsg and sendmsg calls.
 357  */
 358 struct msghdr {
 359         void            *msg_name;              /* optional address */
 360         socklen_t       msg_namelen;            /* size of address */
 361         struct iovec    *msg_iov;               /* scatter/gather array */
 362         int             msg_iovlen;             /* # elements in msg_iov */
 363 
 364 #if defined(_XPG4_2) || defined(_KERNEL)
 365         void            *msg_control;           /* ancillary data */
 366         socklen_t       msg_controllen;         /* ancillary data buffer len */
 367         int             msg_flags;              /* flags on received message */
 368 #else
 369         caddr_t         msg_accrights;  /* access rights sent/received */
 370         int             msg_accrightslen;
 371 #endif  /* defined(_XPG4_2) || defined(_KERNEL) */
 372 };
 373 
 374 #if     defined(_KERNEL) || defined(_FAKE_KERNEL)
 375 
 376 /*
 377  *      N.B.:  we assume that omsghdr and nmsghdr are isomorphic, with
 378  *      the sole exception that nmsghdr has the additional msg_flags
 379  *      field at the end.
 380  */
 381 struct omsghdr {
 382         void            *msg_name;      /* optional address */
 383         socklen_t       msg_namelen;    /* size of address */
 384         struct  iovec   *msg_iov;       /* scatter/gather array */
 385         int             msg_iovlen;     /* # elements in msg_iov */
 386         caddr_t         msg_accrights;  /* access rights sent/received */
 387         int             msg_accrightslen;
 388 };
 389 
 390 #define nmsghdr         msghdr
 391 
 392 #if defined(_SYSCALL32)
 393 
 394 struct omsghdr32 {
 395         caddr32_t       msg_name;       /* optional address */
 396         uint32_t        msg_namelen;    /* size of address */
 397         caddr32_t       msg_iov;        /* scatter/gather array */
 398         int32_t         msg_iovlen;     /* # elements in msg_iov */
 399         caddr32_t       msg_accrights;  /* access rights sent/received */
 400         uint32_t        msg_accrightslen;
 401 };
 402 
 403 struct msghdr32 {
 404         caddr32_t       msg_name;       /* optional address */
 405         uint32_t        msg_namelen;    /* size of address */
 406         caddr32_t       msg_iov;        /* scatter/gather array */
 407         int32_t         msg_iovlen;     /* # elements in msg_iov */
 408         caddr32_t       msg_control;    /* ancillary data */
 409         uint32_t        msg_controllen; /* ancillary data buffer len */
 410         int32_t         msg_flags;      /* flags on received message */
 411 };
 412 
 413 #define nmsghdr32       msghdr32
 414 
 415 #endif  /* _SYSCALL32 */
 416 #endif  /* _KERNEL */
 417 
 418 #define MSG_OOB         0x1             /* process out-of-band data */
 419 #define MSG_PEEK        0x2             /* peek at incoming message */
 420 #define MSG_DONTROUTE   0x4             /* send without using routing tables */
 421 #define MSG_EOR         0x8             /* Terminates a record */
 422 #define MSG_CTRUNC      0x10            /* Control data truncated */
 423 #define MSG_TRUNC       0x20            /* Normal data truncated */
 424 #define MSG_WAITALL     0x40            /* Wait for complete recv or error */
 425 #define MSG_DONTWAIT    0x80            /* Don't block for this recv */
 426 #define MSG_NOTIFICATION 0x100          /* Notification, not data */
 427 #define MSG_NOSIGNAL    0x200           /* Don't generate SIGPIPE */
 428 #define MSG_DUPCTRL     0x800           /* Save control message for use with */
 429                                         /* with left over data */
 430 #define MSG_XPG4_2      0x8000          /* Private: XPG4.2 flag */
 431 
 432 #define MSG_MAXIOVLEN   16
 433 
 434 #ifdef _KERNEL
 435 
 436 /*
 437  * Internal-only MSG_... flags
 438  */
 439 
 440 #define MSG_SENDTO_NOXLATE      0x08000000      /* Skip so_ux_addr_xlate */
 441 
 442 #define MSG_MBLK_QUICKRELE      0x10000000      /* free mblk chain */
 443                                                 /* in timely manner */
 444 #define MSG_USERSPACE           0x20000000      /* buffer from user space */
 445 
 446 #endif /* _KERNEL */
 447 
 448 
 449 /* Added for XPGv2 compliance */
 450 #define SHUT_RD         0
 451 #define SHUT_WR         1
 452 #define SHUT_RDWR       2
 453 
 454 struct cmsghdr {
 455         socklen_t       cmsg_len;       /* data byte count, including hdr */
 456         int             cmsg_level;     /* originating protocol */
 457         int             cmsg_type;      /* protocol-specific type */
 458 };
 459 
 460 #if defined(_XPG4_2) || defined(_KERNEL)
 461 #if defined(__sparc)
 462 /* To maintain backward compatibility, alignment needs to be 8 on sparc. */
 463 #define _CMSG_HDR_ALIGNMENT     8
 464 #else
 465 /* for __i386 (and other future architectures) */
 466 #define _CMSG_HDR_ALIGNMENT     4
 467 #endif  /* defined(__sparc) */
 468 #endif  /* defined(_XPG4_2) || defined(_KERNEL) */
 469 
 470 #if defined(_XPG4_2)
 471 /*
 472  * The cmsg headers (and macros dealing with them) were made available as
 473  * part of UNIX95 and hence need to be protected with a _XPG4_2 define.
 474  */
 475 #define _CMSG_DATA_ALIGNMENT    (sizeof (int))
 476 #define _CMSG_HDR_ALIGN(x)      (((uintptr_t)(x) + _CMSG_HDR_ALIGNMENT - 1) & \
 477                                     ~(_CMSG_HDR_ALIGNMENT - 1))
 478 #define _CMSG_DATA_ALIGN(x)     (((uintptr_t)(x) + _CMSG_DATA_ALIGNMENT - 1) & \
 479                                     ~(_CMSG_DATA_ALIGNMENT - 1))
 480 #define CMSG_DATA(c)                                                    \
 481         ((unsigned char *)_CMSG_DATA_ALIGN((struct cmsghdr *)(c) + 1))
 482 
 483 #define CMSG_FIRSTHDR(m)                                                \
 484         (((m)->msg_controllen < sizeof (struct cmsghdr)) ?                \
 485             (struct cmsghdr *)0 : (struct cmsghdr *)((m)->msg_control))
 486 
 487 #define CMSG_NXTHDR(m, c)                                               \
 488         (((c) == 0) ? CMSG_FIRSTHDR(m) :                        \
 489         ((((uintptr_t)_CMSG_HDR_ALIGN((char *)(c) +                     \
 490         ((struct cmsghdr *)(c))->cmsg_len) + sizeof (struct cmsghdr)) >   \
 491         (((uintptr_t)((struct msghdr *)(m))->msg_control) +          \
 492         ((uintptr_t)((struct msghdr *)(m))->msg_controllen))) ?              \
 493         ((struct cmsghdr *)0) :                                         \
 494         ((struct cmsghdr *)_CMSG_HDR_ALIGN((char *)(c) +                \
 495             ((struct cmsghdr *)(c))->cmsg_len))))
 496 
 497 /* Amount of space + padding needed for a message of length l */
 498 #define CMSG_SPACE(l)                                                   \
 499         ((unsigned int)_CMSG_HDR_ALIGN(sizeof (struct cmsghdr) + (l)))
 500 
 501 /* Value to be used in cmsg_len, does not include trailing padding */
 502 #define CMSG_LEN(l)                                                     \
 503         ((unsigned int)_CMSG_DATA_ALIGN(sizeof (struct cmsghdr)) + (l))
 504 
 505 #endif  /* _XPG4_2 */
 506 
 507 #ifdef  _XPG4_2
 508 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 509 #pragma redefine_extname bind __xnet_bind
 510 #pragma redefine_extname connect __xnet_connect
 511 #pragma redefine_extname recvmsg __xnet_recvmsg
 512 #pragma redefine_extname sendmsg __xnet_sendmsg
 513 #pragma redefine_extname sendto __xnet_sendto
 514 #pragma redefine_extname socket __xnet_socket
 515 #pragma redefine_extname socketpair __xnet_socketpair
 516 #pragma redefine_extname getsockopt __xnet_getsockopt
 517 #else   /* __PRAGMA_REDEFINE_EXTNAME */
 518 #define bind    __xnet_bind
 519 #define connect __xnet_connect
 520 #define recvmsg __xnet_recvmsg
 521 #define sendmsg __xnet_sendmsg
 522 #define sendto  __xnet_sendto
 523 #define socket  __xnet_socket
 524 #define socketpair      __xnet_socketpair
 525 #define getsockopt      __xnet_getsockopt
 526 #endif  /* __PRAGMA_REDEFINE_EXTNAME */
 527 
 528 #endif  /* _XPG4_2 */
 529 
 530 #if defined(_XPG4_2) && !defined(_XPG5)
 531 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 532 #pragma redefine_extname listen __xnet_listen
 533 #else   /* __PRAGMA_REDEFINE_EXTNAME */
 534 #define listen  __xnet_listen
 535 #endif  /* __PRAGMA_REDEFINE_EXTNAME */
 536 #endif /* (_XPG4_2) && !defined(_XPG5) */
 537 
 538 #if !defined(_KERNEL) || defined(_BOOT)
 539 extern int accept(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
 540 extern int accept4(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t, int);
 541 extern int bind(int, const struct sockaddr *, socklen_t);
 542 extern int connect(int, const struct sockaddr *, socklen_t);
 543 extern int getpeername(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
 544 extern int getsockname(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
 545 extern int getsockopt(int, int, int, void *_RESTRICT_KYWD, Psocklen_t);
 546 extern int listen(int, int);    /* XXX - fixme???  where do I go */
 547 extern int socketpair(int, int, int, int *);
 548 extern ssize_t recv(int, void *, size_t, int);
 549 extern ssize_t recvfrom(int, void *_RESTRICT_KYWD, size_t, int,
 550         struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
 551 extern ssize_t recvmsg(int, struct msghdr *, int);
 552 extern ssize_t send(int, const void *, size_t, int);
 553 extern ssize_t sendmsg(int, const struct msghdr *, int);
 554 extern ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
 555         socklen_t);
 556 extern int setsockopt(int, int, int, const void *, socklen_t);
 557 extern int shutdown(int, int);
 558 extern int socket(int, int, int);
 559 
 560 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
 561 extern int sockatmark(int);
 562 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
 563 #endif  /* !defined(_KERNEL) || defined(_BOOT) */
 564 
 565 #ifdef  __cplusplus
 566 }
 567 #endif
 568 
 569 #endif  /* _SYS_SOCKET_H */