[BACK]Return to socket.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / sys

Annotation of src/sys/sys/socket.h, Revision 1.67

1.67    ! bjh21       1: /*     $NetBSD: socket.h,v 1.66 2003/04/19 21:30:29 christos Exp $     */
1.44      itojun      2:
                      3: /*
                      4:  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  * 3. Neither the name of the project nor the names of its contributors
                     16:  *    may be used to endorse or promote products derived from this software
                     17:  *    without specific prior written permission.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
                     20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
                     23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     29:  * SUCH DAMAGE.
                     30:  */
1.10      cgd        31:
1.1       cgd        32: /*
1.8       mycroft    33:  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
                     34:  *     The Regents of the University of California.  All rights reserved.
1.1       cgd        35:  *
                     36:  * Redistribution and use in source and binary forms, with or without
                     37:  * modification, are permitted provided that the following conditions
                     38:  * are met:
                     39:  * 1. Redistributions of source code must retain the above copyright
                     40:  *    notice, this list of conditions and the following disclaimer.
                     41:  * 2. Redistributions in binary form must reproduce the above copyright
                     42:  *    notice, this list of conditions and the following disclaimer in the
                     43:  *    documentation and/or other materials provided with the distribution.
                     44:  * 3. All advertising materials mentioning features or use of this software
                     45:  *    must display the following acknowledgement:
                     46:  *     This product includes software developed by the University of
                     47:  *     California, Berkeley and its contributors.
                     48:  * 4. Neither the name of the University nor the names of its contributors
                     49:  *    may be used to endorse or promote products derived from this software
                     50:  *    without specific prior written permission.
                     51:  *
                     52:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     53:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     54:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     55:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     56:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     57:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     58:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     59:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     60:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     61:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     62:  * SUCH DAMAGE.
                     63:  *
1.28      fvdl       64:  *     @(#)socket.h    8.6 (Berkeley) 5/3/95
1.1       cgd        65:  */
                     66:
1.2       mycroft    67: #ifndef _SYS_SOCKET_H_
1.8       mycroft    68: #define        _SYS_SOCKET_H_
1.2       mycroft    69:
1.67    ! bjh21      70: #include <sys/featuretest.h>
        !            71:
1.1       cgd        72: /*
                     73:  * Definitions related to sockets: types, address families, options.
                     74:  */
                     75:
                     76: /*
1.42      kleink     77:  * Data types.
                     78:  */
1.55      itojun     79: #include <sys/ansi.h>
1.56      kleink     80:
                     81: #ifndef sa_family_t
                     82: typedef __sa_family_t  sa_family_t;
1.58      kleink     83: #define sa_family_t    __sa_family_t
1.56      kleink     84: #endif
                     85:
1.55      itojun     86: #ifndef socklen_t
                     87: typedef __socklen_t    socklen_t;
1.58      kleink     88: #define socklen_t      __socklen_t
1.55      itojun     89: #endif
1.42      kleink     90:
1.63      kleink     91: #include <machine/ansi.h>
                     92:
                     93: #ifdef _BSD_SIZE_T_
                     94: typedef        _BSD_SIZE_T_    size_t;
                     95: #undef _BSD_SIZE_T_
                     96: #endif
                     97:
                     98: #ifdef _BSD_SSIZE_T_
                     99: typedef        _BSD_SSIZE_T_   ssize_t;
                    100: #undef _BSD_SSIZE_T_
                    101: #endif
                    102:
                    103: #include <sys/uio.h>
                    104:
1.42      kleink    105: /*
                    106:  * Socket types.
1.1       cgd       107:  */
                    108: #define        SOCK_STREAM     1               /* stream socket */
                    109: #define        SOCK_DGRAM      2               /* datagram socket */
                    110: #define        SOCK_RAW        3               /* raw-protocol interface */
                    111: #define        SOCK_RDM        4               /* reliably-delivered message */
                    112: #define        SOCK_SEQPACKET  5               /* sequenced packet stream */
                    113:
                    114: /*
                    115:  * Option flags per-socket.
                    116:  */
                    117: #define        SO_DEBUG        0x0001          /* turn on debugging info recording */
                    118: #define        SO_ACCEPTCONN   0x0002          /* socket has had listen() */
                    119: #define        SO_REUSEADDR    0x0004          /* allow local address reuse */
                    120: #define        SO_KEEPALIVE    0x0008          /* keep connections alive */
                    121: #define        SO_DONTROUTE    0x0010          /* just use interface addresses */
                    122: #define        SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
                    123: #define        SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
                    124: #define        SO_LINGER       0x0080          /* linger on close if data present */
                    125: #define        SO_OOBINLINE    0x0100          /* leave received OOB data in line */
1.8       mycroft   126: #define        SO_REUSEPORT    0x0200          /* allow local address & port reuse */
1.18      thorpej   127: #define        SO_TIMESTAMP    0x0400          /* timestamp received dgram traffic */
1.1       cgd       128:
                    129: /*
                    130:  * Additional options, not kept in so_options.
                    131:  */
                    132: #define SO_SNDBUF      0x1001          /* send buffer size */
                    133: #define SO_RCVBUF      0x1002          /* receive buffer size */
                    134: #define SO_SNDLOWAT    0x1003          /* send low-water mark */
                    135: #define SO_RCVLOWAT    0x1004          /* receive low-water mark */
                    136: #define SO_SNDTIMEO    0x1005          /* send timeout */
                    137: #define SO_RCVTIMEO    0x1006          /* receive timeout */
                    138: #define        SO_ERROR        0x1007          /* get error status and clear */
                    139: #define        SO_TYPE         0x1008          /* get socket type */
                    140:
                    141: /*
                    142:  * Structure used for manipulating linger option.
                    143:  */
                    144: struct linger {
                    145:        int     l_onoff;                /* option on/off */
1.28      fvdl      146:        int     l_linger;               /* linger time in seconds */
1.1       cgd       147: };
                    148:
                    149: /*
                    150:  * Level number for (get/set)sockopt() to apply to socket itself.
                    151:  */
                    152: #define        SOL_SOCKET      0xffff          /* options for socket level */
                    153:
                    154: /*
                    155:  * Address families.
                    156:  */
                    157: #define        AF_UNSPEC       0               /* unspecified */
1.8       mycroft   158: #define        AF_LOCAL        1               /* local to host (pipes, portals) */
                    159: #define        AF_UNIX         AF_LOCAL        /* backward compatibility */
1.1       cgd       160: #define        AF_INET         2               /* internetwork: UDP, TCP, etc. */
                    161: #define        AF_IMPLINK      3               /* arpanet imp addresses */
                    162: #define        AF_PUP          4               /* pup protocols: e.g. BSP */
                    163: #define        AF_CHAOS        5               /* mit CHAOS protocols */
                    164: #define        AF_NS           6               /* XEROX NS protocols */
                    165: #define        AF_ISO          7               /* ISO protocols */
                    166: #define        AF_OSI          AF_ISO
                    167: #define        AF_ECMA         8               /* european computer manufacturers */
                    168: #define        AF_DATAKIT      9               /* datakit protocols */
                    169: #define        AF_CCITT        10              /* CCITT protocols, X.25 etc */
                    170: #define        AF_SNA          11              /* IBM SNA */
                    171: #define AF_DECnet      12              /* DECnet */
                    172: #define AF_DLI         13              /* DEC Direct data link interface */
                    173: #define AF_LAT         14              /* LAT */
                    174: #define        AF_HYLINK       15              /* NSC Hyperchannel */
                    175: #define        AF_APPLETALK    16              /* Apple Talk */
                    176: #define        AF_ROUTE        17              /* Internal Routing Protocol */
                    177: #define        AF_LINK         18              /* Link layer interface */
1.67    ! bjh21     178: #if defined(_NETBSD_SOURCE)
1.1       cgd       179: #define        pseudo_AF_XTP   19              /* eXpress Transfer Protocol (no AF) */
1.42      kleink    180: #endif
1.8       mycroft   181: #define        AF_COIP         20              /* connection-oriented IP, aka ST II */
                    182: #define        AF_CNT          21              /* Computer Network Technology */
1.67    ! bjh21     183: #if defined(_NETBSD_SOURCE)
1.8       mycroft   184: #define pseudo_AF_RTIP 22              /* Help Identify RTIP packets */
1.42      kleink    185: #endif
1.8       mycroft   186: #define        AF_IPX          23              /* Novell Internet Protocol */
1.21      sommerfe  187: #define        AF_INET6        24              /* IP version 6 */
1.67    ! bjh21     188: #if defined(_NETBSD_SOURCE)
1.8       mycroft   189: #define pseudo_AF_PIP  25              /* Help Identify PIP packets */
1.42      kleink    190: #endif
1.17      chuck     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 */
1.19      is        194: #define AF_ARP         28              /* (rev.) addr. res. prot. (RFC 826) */
1.67    ! bjh21     195: #if defined(_NETBSD_SOURCE)
1.21      sommerfe  196: #define pseudo_AF_KEY  29              /* Internal key management protocol  */
1.31      thorpej   197: #define        pseudo_AF_HDRCMPLT 30           /* Used by BPF to not rewrite hdrs
                    198:                                           in interface output routine */
1.42      kleink    199: #endif
1.1       cgd       200:
1.31      thorpej   201: #define        AF_MAX          31
1.1       cgd       202:
                    203: /*
1.26      thorpej   204:  * Structure used by kernel to store most
                    205:  * addresses.
1.1       cgd       206:  */
                    207: struct sockaddr {
1.63      kleink    208:        __uint8_t       sa_len;         /* total length */
1.56      kleink    209:        sa_family_t     sa_family;      /* address family */
                    210:        char            sa_data[14];    /* actually longer; address value */
1.26      thorpej   211: };
1.1       cgd       212:
1.42      kleink    213: #if defined(_KERNEL)
1.1       cgd       214: /*
                    215:  * Structure used by kernel to pass protocol
                    216:  * information in raw sockets.
                    217:  */
                    218: struct sockproto {
                    219:        u_short sp_family;              /* address family */
                    220:        u_short sp_protocol;            /* protocol */
                    221: };
1.42      kleink    222: #endif /* _KERNEL */
1.1       cgd       223:
1.44      itojun    224: #if 1
                    225: /*
                    226:  * RFC 2553: protocol-independent placeholder for socket addresses
                    227:  */
                    228: #define _SS_MAXSIZE    128
1.63      kleink    229: #define _SS_ALIGNSIZE  (sizeof(__int64_t))
1.60      kleink    230: #define _SS_PAD1SIZE   (_SS_ALIGNSIZE - 2)
                    231: #define _SS_PAD2SIZE   (_SS_MAXSIZE - 2 - \
1.44      itojun    232:                                _SS_PAD1SIZE - _SS_ALIGNSIZE)
                    233:
1.67    ! bjh21     234: #if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
1.44      itojun    235: struct sockaddr_storage {
1.63      kleink    236:        __uint8_t       ss_len;         /* address length */
1.56      kleink    237:        sa_family_t     ss_family;      /* address family */
                    238:        char            __ss_pad1[_SS_PAD1SIZE];
1.63      kleink    239:        __int64_t     __ss_align;/* force desired structure storage alignment */
1.56      kleink    240:        char            __ss_pad2[_SS_PAD2SIZE];
1.44      itojun    241: };
1.67    ! bjh21     242: #endif /* _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */
1.46      kleink    243: #endif /* 1 */
1.44      itojun    244:
1.1       cgd       245: /*
                    246:  * Protocol families, same as address families for now.
                    247:  */
                    248: #define        PF_UNSPEC       AF_UNSPEC
1.8       mycroft   249: #define        PF_LOCAL        AF_LOCAL
                    250: #define        PF_UNIX         PF_LOCAL        /* backward compatibility */
1.1       cgd       251: #define        PF_INET         AF_INET
                    252: #define        PF_IMPLINK      AF_IMPLINK
                    253: #define        PF_PUP          AF_PUP
                    254: #define        PF_CHAOS        AF_CHAOS
                    255: #define        PF_NS           AF_NS
                    256: #define        PF_ISO          AF_ISO
                    257: #define        PF_OSI          AF_ISO
                    258: #define        PF_ECMA         AF_ECMA
                    259: #define        PF_DATAKIT      AF_DATAKIT
                    260: #define        PF_CCITT        AF_CCITT
                    261: #define        PF_SNA          AF_SNA
                    262: #define PF_DECnet      AF_DECnet
                    263: #define PF_DLI         AF_DLI
                    264: #define PF_LAT         AF_LAT
                    265: #define        PF_HYLINK       AF_HYLINK
                    266: #define        PF_APPLETALK    AF_APPLETALK
                    267: #define        PF_ROUTE        AF_ROUTE
                    268: #define        PF_LINK         AF_LINK
1.67    ! bjh21     269: #if defined(_NETBSD_SOURCE)
1.1       cgd       270: #define        PF_XTP          pseudo_AF_XTP   /* really just proto family, no AF */
1.42      kleink    271: #endif
1.8       mycroft   272: #define        PF_COIP         AF_COIP
                    273: #define        PF_CNT          AF_CNT
1.21      sommerfe  274: #define        PF_INET6        AF_INET6
1.8       mycroft   275: #define        PF_IPX          AF_IPX          /* same format as AF_NS */
1.67    ! bjh21     276: #if defined(_NETBSD_SOURCE)
1.8       mycroft   277: #define PF_RTIP                pseudo_AF_FTIP  /* same format as AF_INET */
                    278: #define PF_PIP         pseudo_AF_PIP
1.42      kleink    279: #endif
1.20      is        280: #define PF_ISDN                AF_ISDN         /* same as E164 */
                    281: #define PF_E164                AF_E164
1.17      chuck     282: #define PF_NATM                AF_NATM
1.19      is        283: #define PF_ARP         AF_ARP
1.67    ! bjh21     284: #if defined(_NETBSD_SOURCE)
1.21      sommerfe  285: #define PF_KEY                 pseudo_AF_KEY   /* like PF_ROUTE, only for key mgmt */
1.42      kleink    286: #endif
1.1       cgd       287:
                    288: #define        PF_MAX          AF_MAX
                    289:
1.67    ! bjh21     290: #if defined(_NETBSD_SOURCE)
1.63      kleink    291:
                    292: #ifndef        gid_t
                    293: typedef        __gid_t         gid_t;          /* group id */
                    294: #define        gid_t           __gid_t
                    295: #endif
                    296:
                    297: #ifndef        uid_t
                    298: typedef        __uid_t         uid_t;          /* user id */
                    299: #define        uid_t           __uid_t
                    300: #endif
                    301:
1.1       cgd       302: /*
1.27      thorpej   303:  * Socket credentials.
                    304:  */
                    305: struct sockcred {
                    306:        uid_t   sc_uid;                 /* real user id */
                    307:        uid_t   sc_euid;                /* effective user id */
                    308:        gid_t   sc_gid;                 /* real group id */
                    309:        gid_t   sc_egid;                /* effective group id */
                    310:        int     sc_ngroups;             /* number of supplemental groups */
                    311:        gid_t   sc_groups[1];           /* variable length */
                    312: };
                    313:
                    314: /*
                    315:  * Compute size of a sockcred structure with groups.
                    316:  */
                    317: #define        SOCKCREDSIZE(ngrps) \
                    318:        (sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
1.67    ! bjh21     319: #endif /* _NETBSD_SOURCE */
1.27      thorpej   320:
1.38      kleink    321:
1.67    ! bjh21     322: #if defined(_NETBSD_SOURCE)
1.27      thorpej   323: /*
1.8       mycroft   324:  * Definitions for network related sysctl, CTL_NET.
                    325:  *
                    326:  * Second level is protocol family.
                    327:  * Third level is protocol number.
                    328:  *
                    329:  * Further levels are defined by the individual families below.
                    330:  */
                    331: #define NET_MAXID      AF_MAX
                    332:
                    333: #define CTL_NET_NAMES { \
                    334:        { 0, 0 }, \
1.28      fvdl      335:        { "local", CTLTYPE_NODE }, \
1.8       mycroft   336:        { "inet", CTLTYPE_NODE }, \
                    337:        { "implink", CTLTYPE_NODE }, \
                    338:        { "pup", CTLTYPE_NODE }, \
                    339:        { "chaos", CTLTYPE_NODE }, \
                    340:        { "xerox_ns", CTLTYPE_NODE }, \
                    341:        { "iso", CTLTYPE_NODE }, \
                    342:        { "emca", CTLTYPE_NODE }, \
                    343:        { "datakit", CTLTYPE_NODE }, \
                    344:        { "ccitt", CTLTYPE_NODE }, \
                    345:        { "ibm_sna", CTLTYPE_NODE }, \
                    346:        { "decnet", CTLTYPE_NODE }, \
                    347:        { "dec_dli", CTLTYPE_NODE }, \
                    348:        { "lat", CTLTYPE_NODE }, \
                    349:        { "hylink", CTLTYPE_NODE }, \
                    350:        { "appletalk", CTLTYPE_NODE }, \
                    351:        { "route", CTLTYPE_NODE }, \
                    352:        { "link_layer", CTLTYPE_NODE }, \
                    353:        { "xtp", CTLTYPE_NODE }, \
                    354:        { "coip", CTLTYPE_NODE }, \
                    355:        { "cnt", CTLTYPE_NODE }, \
                    356:        { "rtip", CTLTYPE_NODE }, \
                    357:        { "ipx", CTLTYPE_NODE }, \
1.21      sommerfe  358:        { "inet6", CTLTYPE_NODE }, \
1.8       mycroft   359:        { "pip", CTLTYPE_NODE }, \
1.20      is        360:        { "isdn", CTLTYPE_NODE }, \
1.17      chuck     361:        { "natm", CTLTYPE_NODE }, \
1.20      is        362:        { "arp", CTLTYPE_NODE }, \
1.21      sommerfe  363:        { "key", CTLTYPE_NODE }, \
1.8       mycroft   364: }
1.67    ! bjh21     365: #endif /* _NETBSD_SOURCE */
1.8       mycroft   366:
1.67    ! bjh21     367: #if defined(_NETBSD_SOURCE)
1.8       mycroft   368: /*
                    369:  * PF_ROUTE - Routing table
                    370:  *
                    371:  * Three additional levels are defined:
                    372:  *     Fourth: address family, 0 is wildcard
                    373:  *     Fifth: type of info, defined below
                    374:  *     Sixth: flag(s) to mask with for NET_RT_FLAGS
                    375:  */
                    376: #define NET_RT_DUMP    1               /* dump; may limit to a.f. */
                    377: #define NET_RT_FLAGS   2               /* by flags, e.g. RESOLVING */
1.47      bouyer    378: #define NET_RT_OIFLIST 3               /* old NET_RT_IFLIST (pre 1.5) */
                    379: #define NET_RT_IFLIST  4               /* survey interface list */
                    380: #define        NET_RT_MAXID    5
1.8       mycroft   381:
                    382: #define CTL_NET_RT_NAMES { \
                    383:        { 0, 0 }, \
                    384:        { "dump", CTLTYPE_STRUCT }, \
                    385:        { "flags", CTLTYPE_STRUCT }, \
1.47      bouyer    386:        { 0, 0 }, \
1.8       mycroft   387:        { "iflist", CTLTYPE_STRUCT }, \
                    388: }
1.67    ! bjh21     389: #endif /* _NETBSD_SOURCE */
1.8       mycroft   390:
                    391: /*
1.13      mycroft   392:  * Maximum queue length specifiable by listen(2).
1.1       cgd       393:  */
1.66      christos  394: #ifndef SOMAXCONN
1.13      mycroft   395: #define        SOMAXCONN       128
1.66      christos  396: #endif
1.16      neil      397:
1.1       cgd       398: /*
                    399:  * Message header for recvmsg and sendmsg calls.
                    400:  * Used value-result for recvmsg, value only for sendmsg.
                    401:  */
                    402: struct msghdr {
1.42      kleink    403:        void            *msg_name;      /* optional address */
                    404:        socklen_t       msg_namelen;    /* size of address */
                    405:        struct iovec    *msg_iov;       /* scatter/gather array */
                    406:        int             msg_iovlen;     /* # elements in msg_iov */
                    407:        void            *msg_control;   /* ancillary data, see below */
                    408:        socklen_t       msg_controllen; /* ancillary data buffer len */
                    409:        int             msg_flags;      /* flags on received message */
1.1       cgd       410: };
                    411:
                    412: #define        MSG_OOB         0x1             /* process out-of-band data */
                    413: #define        MSG_PEEK        0x2             /* peek at incoming message */
                    414: #define        MSG_DONTROUTE   0x4             /* send without using routing tables */
                    415: #define        MSG_EOR         0x8             /* data completes record */
                    416: #define        MSG_TRUNC       0x10            /* data discarded before delivery */
                    417: #define        MSG_CTRUNC      0x20            /* control data lost before delivery */
                    418: #define        MSG_WAITALL     0x40            /* wait for full request or error */
1.8       mycroft   419: #define        MSG_DONTWAIT    0x80            /* this message should be nonblocking */
1.30      matt      420: #define        MSG_BCAST       0x100           /* this message was rcvd using link-level brdcst */
                    421: #define        MSG_MCAST       0x200           /* this message was rcvd using link-level mcast */
1.1       cgd       422:
                    423: /*
                    424:  * Header for ancillary data objects in msg_control buffer.
                    425:  * Used for additional information with/about a datagram
                    426:  * not expressible by flags.  The format is a sequence
                    427:  * of message elements headed by cmsghdr structures.
                    428:  */
                    429: struct cmsghdr {
1.42      kleink    430:        socklen_t       cmsg_len;       /* data byte count, including hdr */
                    431:        int             cmsg_level;     /* originating protocol */
                    432:        int             cmsg_type;      /* protocol-specific type */
1.1       cgd       433: /* followed by u_char  cmsg_data[]; */
                    434: };
                    435:
1.8       mycroft   436: /* given pointer to struct cmsghdr, return pointer to data */
1.50      itojun    437: #define        CMSG_DATA(cmsg) \
1.57      christos  438:        ((u_char *)(void *)(cmsg) + __CMSG_ALIGN(sizeof(struct cmsghdr)))
1.1       cgd       439:
1.44      itojun    440: /*
                    441:  * Alignment requirement for CMSG struct manipulation.
1.51      itojun    442:  * This basically behaves the same as ALIGN() ARCH/include/param.h.
                    443:  * We declare it separately for two reasons:
                    444:  * (1) avoid dependency between machine/param.h, and (2) to sync with kernel's
                    445:  * idea of ALIGNBYTES at runtime.
                    446:  * without (2), we can't guarantee binary compatibility in case of future
                    447:  * changes in ALIGNBYTES.
1.44      itojun    448:  */
1.53      itojun    449: #define __CMSG_ALIGN(n)        (((n) + __cmsg_alignbytes()) & ~__cmsg_alignbytes())
                    450: #ifdef _KERNEL
1.54      augustss  451: #define CMSG_ALIGN(n)  __CMSG_ALIGN(n)
1.53      itojun    452: #endif
1.44      itojun    453:
1.8       mycroft   454: /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
1.1       cgd       455: #define        CMSG_NXTHDR(mhdr, cmsg) \
1.63      kleink    456:        (((__caddr_t)(cmsg) + __CMSG_ALIGN((cmsg)->cmsg_len) + \
1.53      itojun    457:                            __CMSG_ALIGN(sizeof(struct cmsghdr)) > \
1.63      kleink    458:            (((__caddr_t)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \
1.1       cgd       459:            (struct cmsghdr *)NULL : \
1.63      kleink    460:            (struct cmsghdr *)((__caddr_t)(cmsg) + \
                    461:                __CMSG_ALIGN((cmsg)->cmsg_len)))
1.1       cgd       462:
1.62      itojun    463: /*
                    464:  * RFC 2292 requires to check msg_controllen, in case that the kernel returns
                    465:  * an empty list for some reasons.
                    466:  */
                    467: #define        CMSG_FIRSTHDR(mhdr) \
                    468:        ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
                    469:         (struct cmsghdr *)(mhdr)->msg_control : \
                    470:         (struct cmsghdr *)NULL)
1.1       cgd       471:
1.53      itojun    472: #define CMSG_SPACE(l)  (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(l))
                    473: #define CMSG_LEN(l)    (__CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
1.44      itojun    474:
1.1       cgd       475: /* "Socket"-level control message types: */
                    476: #define        SCM_RIGHTS      0x01            /* access rights (array of int) */
1.67    ! bjh21     477: #if defined(_NETBSD_SOURCE)
1.18      thorpej   478: #define        SCM_TIMESTAMP   0x02            /* timestamp (struct timeval) */
1.42      kleink    479: #define        SCM_CREDS       0x04            /* credentials (struct sockcred) */
                    480: #endif
1.29      kleink    481:
                    482: /*
                    483:  * Types of socket shutdown(2).
                    484:  */
                    485: #define        SHUT_RD         0               /* Disallow further receives. */
                    486: #define        SHUT_WR         1               /* Disallow further sends. */
                    487: #define        SHUT_RDWR       2               /* Disallow further sends/receives. */
1.1       cgd       488:
1.67    ! bjh21     489: #if defined(_NETBSD_SOURCE)
1.1       cgd       490: /*
                    491:  * 4.3 compat sockaddr, move to compat file later
                    492:  */
                    493: struct osockaddr {
1.63      kleink    494:        __uint16_t      sa_family;      /* address family */
1.60      kleink    495:        char            sa_data[14];    /* up to 14 bytes of direct address */
1.1       cgd       496: };
                    497:
                    498: /*
                    499:  * 4.3-compat message header (move to compat file later).
                    500:  */
                    501: struct omsghdr {
1.63      kleink    502:        __caddr_t       msg_name;       /* optional address */
                    503:        int             msg_namelen;    /* size of address */
                    504:        struct iovec    *msg_iov;       /* scatter/gather array */
                    505:        int             msg_iovlen;     /* # elements in msg_iov */
                    506:        __caddr_t       msg_accrights;  /* access rights sent/received */
                    507:        int             msg_accrightslen;
1.1       cgd       508: };
1.42      kleink    509: #endif
1.51      itojun    510:
1.59      toshii    511: #include <sys/cdefs.h>
                    512:
                    513: __BEGIN_DECLS
1.51      itojun    514: int    __cmsg_alignbytes __P((void));
1.59      toshii    515: __END_DECLS
1.1       cgd       516:
1.12      briggs    517: #ifndef        _KERNEL
1.1       cgd       518:
                    519: __BEGIN_DECLS
1.65      kleink    520: int    accept __P((int, struct sockaddr * __restrict, socklen_t * __restrict));
1.42      kleink    521: int    bind __P((int, const struct sockaddr *, socklen_t));
                    522: int    connect __P((int, const struct sockaddr *, socklen_t));
1.65      kleink    523: int    getpeername __P((int, struct sockaddr * __restrict,
                    524:            socklen_t * __restrict));
                    525: int    getsockname __P((int, struct sockaddr * __restrict,
                    526:            socklen_t * __restrict));
                    527: int    getsockopt __P((int, int, int, void * __restrict,
                    528:            socklen_t * __restrict));
1.1       cgd       529: int    listen __P((int, int));
1.8       mycroft   530: ssize_t        recv __P((int, void *, size_t, int));
1.65      kleink    531: ssize_t        recvfrom __P((int, void * __restrict, size_t, int,
                    532:            struct sockaddr * __restrict, socklen_t * __restrict));
1.8       mycroft   533: ssize_t        recvmsg __P((int, struct msghdr *, int));
                    534: ssize_t        send __P((int, const void *, size_t, int));
                    535: ssize_t        sendto __P((int, const void *,
1.42      kleink    536:            size_t, int, const struct sockaddr *, socklen_t));
1.8       mycroft   537: ssize_t        sendmsg __P((int, const struct msghdr *, int));
1.42      kleink    538: int    setsockopt __P((int, int, int, const void *, socklen_t));
1.1       cgd       539: int    shutdown __P((int, int));
1.64      kleink    540: int    sockatmark __P((int));
1.1       cgd       541: int    socket __P((int, int, int));
                    542: int    socketpair __P((int, int, int, int *));
                    543: __END_DECLS
1.14      christos  544: #endif /* !_KERNEL */
1.1       cgd       545:
1.2       mycroft   546: #endif /* !_SYS_SOCKET_H_ */

CVSweb <webmaster@jp.NetBSD.org>