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