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