[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.108

1.108   ! joerg       1: /*     $NetBSD: socket.h,v 1.107 2012/06/22 18:26:35 christos Exp $    */
1.44      itojun      2:
                      3: /*
                      4:  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
                      5:  * All rights reserved.
1.71      perry       6:  *
1.44      itojun      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.
1.71      perry      18:  *
1.44      itojun     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.
1.68      agc        44:  * 3. Neither the name of the University nor the names of its contributors
1.1       cgd        45:  *    may be used to endorse or promote products derived from this software
                     46:  *    without specific prior written permission.
                     47:  *
                     48:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     49:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     50:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     51:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     52:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     53:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     54:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     55:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     56:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     57:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     58:  * SUCH DAMAGE.
                     59:  *
1.28      fvdl       60:  *     @(#)socket.h    8.6 (Berkeley) 5/3/95
1.1       cgd        61:  */
                     62:
1.2       mycroft    63: #ifndef _SYS_SOCKET_H_
1.8       mycroft    64: #define        _SYS_SOCKET_H_
1.2       mycroft    65:
1.67      bjh21      66: #include <sys/featuretest.h>
                     67:
1.1       cgd        68: /*
                     69:  * Definitions related to sockets: types, address families, options.
                     70:  */
                     71:
                     72: /*
1.42      kleink     73:  * Data types.
                     74:  */
1.55      itojun     75: #include <sys/ansi.h>
1.56      kleink     76:
                     77: #ifndef sa_family_t
                     78: typedef __sa_family_t  sa_family_t;
1.58      kleink     79: #define sa_family_t    __sa_family_t
1.56      kleink     80: #endif
                     81:
1.55      itojun     82: #ifndef socklen_t
                     83: typedef __socklen_t    socklen_t;
1.58      kleink     84: #define socklen_t      __socklen_t
1.55      itojun     85: #endif
1.42      kleink     86:
1.63      kleink     87: #include <machine/ansi.h>
                     88:
                     89: #ifdef _BSD_SIZE_T_
                     90: typedef        _BSD_SIZE_T_    size_t;
                     91: #undef _BSD_SIZE_T_
                     92: #endif
                     93:
                     94: #ifdef _BSD_SSIZE_T_
                     95: typedef        _BSD_SSIZE_T_   ssize_t;
                     96: #undef _BSD_SSIZE_T_
                     97: #endif
                     98:
                     99: #include <sys/uio.h>
1.100     christos  100: #include <sys/sigtypes.h>
1.63      kleink    101:
1.42      kleink    102: /*
                    103:  * Socket types.
1.1       cgd       104:  */
                    105: #define        SOCK_STREAM     1               /* stream socket */
                    106: #define        SOCK_DGRAM      2               /* datagram socket */
                    107: #define        SOCK_RAW        3               /* raw-protocol interface */
                    108: #define        SOCK_RDM        4               /* reliably-delivered message */
                    109: #define        SOCK_SEQPACKET  5               /* sequenced packet stream */
                    110:
1.100     christos  111: #define        SOCK_CLOEXEC    0x10000000      /* set close on exec on socket */
                    112: #define        SOCK_NONBLOCK   0x20000000      /* set non blocking i/o socket */
1.105     christos  113: #define        SOCK_NOSIGPIPE  0x40000000      /* don't send sigpipe */
1.100     christos  114: #define        SOCK_FLAGS_MASK 0xf0000000      /* flags mask */
                    115:
1.1       cgd       116: /*
                    117:  * Option flags per-socket.
                    118:  */
                    119: #define        SO_DEBUG        0x0001          /* turn on debugging info recording */
                    120: #define        SO_ACCEPTCONN   0x0002          /* socket has had listen() */
                    121: #define        SO_REUSEADDR    0x0004          /* allow local address reuse */
                    122: #define        SO_KEEPALIVE    0x0008          /* keep connections alive */
                    123: #define        SO_DONTROUTE    0x0010          /* just use interface addresses */
                    124: #define        SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
                    125: #define        SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
                    126: #define        SO_LINGER       0x0080          /* linger on close if data present */
                    127: #define        SO_OOBINLINE    0x0100          /* leave received OOB data in line */
1.8       mycroft   128: #define        SO_REUSEPORT    0x0200          /* allow local address & port reuse */
1.94      christos  129: /*     SO_OTIMESTAMP   0x0400          */
1.105     christos  130: #define        SO_NOSIGPIPE    0x0800          /* no SIGPIPE from EPIPE */
1.91      tls       131: #define        SO_ACCEPTFILTER 0x1000          /* there is an accept filter */
1.94      christos  132: #define        SO_TIMESTAMP    0x2000          /* timestamp received dgram traffic */
1.1       cgd       133:
1.79      christos  134:
1.1       cgd       135: /*
                    136:  * Additional options, not kept in so_options.
                    137:  */
                    138: #define SO_SNDBUF      0x1001          /* send buffer size */
                    139: #define SO_RCVBUF      0x1002          /* receive buffer size */
                    140: #define SO_SNDLOWAT    0x1003          /* send low-water mark */
                    141: #define SO_RCVLOWAT    0x1004          /* receive low-water mark */
1.93      christos  142: /* SO_OSNDTIMEO                0x1005 */
                    143: /* SO_ORCVTIMEO                0x1006 */
1.1       cgd       144: #define        SO_ERROR        0x1007          /* get error status and clear */
                    145: #define        SO_TYPE         0x1008          /* get socket type */
1.69      darrenr   146: #define        SO_OVERFLOWED   0x1009          /* datagrams: return packets dropped */
1.1       cgd       147:
1.89      dyoung    148: #define        SO_NOHEADER     0x100a          /* user supplies no header to kernel;
                    149:                                         * kernel removes header and supplies
                    150:                                         * payload
                    151:                                         */
1.93      christos  152: #define SO_SNDTIMEO    0x100b          /* send timeout */
                    153: #define SO_RCVTIMEO    0x100c          /* receive timeout */
1.1       cgd       154: /*
                    155:  * Structure used for manipulating linger option.
                    156:  */
                    157: struct linger {
                    158:        int     l_onoff;                /* option on/off */
1.28      fvdl      159:        int     l_linger;               /* linger time in seconds */
1.1       cgd       160: };
                    161:
1.91      tls       162: struct accept_filter_arg {
                    163:        char    af_name[16];
                    164:        char    af_arg[256-16];
                    165: };
                    166:
1.1       cgd       167: /*
                    168:  * Level number for (get/set)sockopt() to apply to socket itself.
                    169:  */
                    170: #define        SOL_SOCKET      0xffff          /* options for socket level */
                    171:
                    172: /*
                    173:  * Address families.
                    174:  */
                    175: #define        AF_UNSPEC       0               /* unspecified */
1.97      pooka     176: #define        AF_LOCAL        1               /* local to host */
1.8       mycroft   177: #define        AF_UNIX         AF_LOCAL        /* backward compatibility */
1.1       cgd       178: #define        AF_INET         2               /* internetwork: UDP, TCP, etc. */
                    179: #define        AF_IMPLINK      3               /* arpanet imp addresses */
                    180: #define        AF_PUP          4               /* pup protocols: e.g. BSP */
                    181: #define        AF_CHAOS        5               /* mit CHAOS protocols */
                    182: #define        AF_NS           6               /* XEROX NS protocols */
                    183: #define        AF_ISO          7               /* ISO protocols */
                    184: #define        AF_OSI          AF_ISO
                    185: #define        AF_ECMA         8               /* european computer manufacturers */
                    186: #define        AF_DATAKIT      9               /* datakit protocols */
                    187: #define        AF_CCITT        10              /* CCITT protocols, X.25 etc */
                    188: #define        AF_SNA          11              /* IBM SNA */
                    189: #define AF_DECnet      12              /* DECnet */
                    190: #define AF_DLI         13              /* DEC Direct data link interface */
                    191: #define AF_LAT         14              /* LAT */
                    192: #define        AF_HYLINK       15              /* NSC Hyperchannel */
                    193: #define        AF_APPLETALK    16              /* Apple Talk */
1.99      matt      194: #define        AF_OROUTE       17              /* Internal Routing Protocol */
1.1       cgd       195: #define        AF_LINK         18              /* Link layer interface */
1.67      bjh21     196: #if defined(_NETBSD_SOURCE)
1.1       cgd       197: #define        pseudo_AF_XTP   19              /* eXpress Transfer Protocol (no AF) */
1.42      kleink    198: #endif
1.8       mycroft   199: #define        AF_COIP         20              /* connection-oriented IP, aka ST II */
                    200: #define        AF_CNT          21              /* Computer Network Technology */
1.67      bjh21     201: #if defined(_NETBSD_SOURCE)
1.8       mycroft   202: #define pseudo_AF_RTIP 22              /* Help Identify RTIP packets */
1.42      kleink    203: #endif
1.8       mycroft   204: #define        AF_IPX          23              /* Novell Internet Protocol */
1.21      sommerfe  205: #define        AF_INET6        24              /* IP version 6 */
1.67      bjh21     206: #if defined(_NETBSD_SOURCE)
1.8       mycroft   207: #define pseudo_AF_PIP  25              /* Help Identify PIP packets */
1.42      kleink    208: #endif
1.17      chuck     209: #define AF_ISDN                26              /* Integrated Services Digital Network*/
                    210: #define AF_E164                AF_ISDN         /* CCITT E.164 recommendation */
                    211: #define AF_NATM                27              /* native ATM access */
1.19      is        212: #define AF_ARP         28              /* (rev.) addr. res. prot. (RFC 826) */
1.67      bjh21     213: #if defined(_NETBSD_SOURCE)
1.21      sommerfe  214: #define pseudo_AF_KEY  29              /* Internal key management protocol  */
1.31      thorpej   215: #define        pseudo_AF_HDRCMPLT 30           /* Used by BPF to not rewrite hdrs
                    216:                                           in interface output routine */
1.42      kleink    217: #endif
1.83      plunky    218: #define AF_BLUETOOTH   31              /* Bluetooth: HCI, SCO, L2CAP, RFCOMM */
1.90      christos  219: #define        AF_IEEE80211    32              /* IEEE80211 */
1.98      kefren    220: #define        AF_MPLS         33              /* MultiProtocol Label Switching */
1.99      matt      221: #define        AF_ROUTE        34              /* Internal Routing Protocol */
                    222: #define        AF_MAX          35
1.1       cgd       223:
                    224: /*
1.26      thorpej   225:  * Structure used by kernel to store most
                    226:  * addresses.
1.1       cgd       227:  */
                    228: struct sockaddr {
1.63      kleink    229:        __uint8_t       sa_len;         /* total length */
1.56      kleink    230:        sa_family_t     sa_family;      /* address family */
                    231:        char            sa_data[14];    /* actually longer; address value */
1.26      thorpej   232: };
1.1       cgd       233:
1.42      kleink    234: #if defined(_KERNEL)
1.1       cgd       235: /*
                    236:  * Structure used by kernel to pass protocol
                    237:  * information in raw sockets.
                    238:  */
                    239: struct sockproto {
                    240:        u_short sp_family;              /* address family */
                    241:        u_short sp_protocol;            /* protocol */
                    242: };
1.42      kleink    243: #endif /* _KERNEL */
1.1       cgd       244:
1.44      itojun    245: #if 1
                    246: /*
                    247:  * RFC 2553: protocol-independent placeholder for socket addresses
                    248:  */
                    249: #define _SS_MAXSIZE    128
1.63      kleink    250: #define _SS_ALIGNSIZE  (sizeof(__int64_t))
1.60      kleink    251: #define _SS_PAD1SIZE   (_SS_ALIGNSIZE - 2)
                    252: #define _SS_PAD2SIZE   (_SS_MAXSIZE - 2 - \
1.44      itojun    253:                                _SS_PAD1SIZE - _SS_ALIGNSIZE)
                    254:
1.67      bjh21     255: #if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
1.44      itojun    256: struct sockaddr_storage {
1.63      kleink    257:        __uint8_t       ss_len;         /* address length */
1.56      kleink    258:        sa_family_t     ss_family;      /* address family */
                    259:        char            __ss_pad1[_SS_PAD1SIZE];
1.63      kleink    260:        __int64_t     __ss_align;/* force desired structure storage alignment */
1.56      kleink    261:        char            __ss_pad2[_SS_PAD2SIZE];
1.44      itojun    262: };
1.89      dyoung    263: #define        sstosa(__ss)    ((struct sockaddr *)(__ss))
                    264: #define        sstocsa(__ss)   ((const struct sockaddr *)(__ss))
1.67      bjh21     265: #endif /* _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */
1.46      kleink    266: #endif /* 1 */
1.44      itojun    267:
1.1       cgd       268: /*
                    269:  * Protocol families, same as address families for now.
                    270:  */
                    271: #define        PF_UNSPEC       AF_UNSPEC
1.8       mycroft   272: #define        PF_LOCAL        AF_LOCAL
                    273: #define        PF_UNIX         PF_LOCAL        /* backward compatibility */
1.1       cgd       274: #define        PF_INET         AF_INET
                    275: #define        PF_IMPLINK      AF_IMPLINK
                    276: #define        PF_PUP          AF_PUP
                    277: #define        PF_CHAOS        AF_CHAOS
                    278: #define        PF_NS           AF_NS
                    279: #define        PF_ISO          AF_ISO
                    280: #define        PF_OSI          AF_ISO
                    281: #define        PF_ECMA         AF_ECMA
                    282: #define        PF_DATAKIT      AF_DATAKIT
                    283: #define        PF_CCITT        AF_CCITT
                    284: #define        PF_SNA          AF_SNA
                    285: #define PF_DECnet      AF_DECnet
                    286: #define PF_DLI         AF_DLI
                    287: #define PF_LAT         AF_LAT
                    288: #define        PF_HYLINK       AF_HYLINK
                    289: #define        PF_APPLETALK    AF_APPLETALK
1.99      matt      290: #define        PF_OROUTE       AF_OROUTE
1.1       cgd       291: #define        PF_LINK         AF_LINK
1.67      bjh21     292: #if defined(_NETBSD_SOURCE)
1.1       cgd       293: #define        PF_XTP          pseudo_AF_XTP   /* really just proto family, no AF */
1.42      kleink    294: #endif
1.8       mycroft   295: #define        PF_COIP         AF_COIP
                    296: #define        PF_CNT          AF_CNT
1.21      sommerfe  297: #define        PF_INET6        AF_INET6
1.8       mycroft   298: #define        PF_IPX          AF_IPX          /* same format as AF_NS */
1.67      bjh21     299: #if defined(_NETBSD_SOURCE)
1.72      kleink    300: #define PF_RTIP                pseudo_AF_RTIP  /* same format as AF_INET */
1.8       mycroft   301: #define PF_PIP         pseudo_AF_PIP
1.42      kleink    302: #endif
1.20      is        303: #define PF_ISDN                AF_ISDN         /* same as E164 */
                    304: #define PF_E164                AF_E164
1.17      chuck     305: #define PF_NATM                AF_NATM
1.19      is        306: #define PF_ARP         AF_ARP
1.67      bjh21     307: #if defined(_NETBSD_SOURCE)
1.21      sommerfe  308: #define PF_KEY                 pseudo_AF_KEY   /* like PF_ROUTE, only for key mgmt */
1.42      kleink    309: #endif
1.80      gdamore   310: #define PF_BLUETOOTH   AF_BLUETOOTH
1.98      kefren    311: #define        PF_MPLS         AF_MPLS
1.99      matt      312: #define        PF_ROUTE        AF_ROUTE
1.1       cgd       313:
                    314: #define        PF_MAX          AF_MAX
                    315:
1.67      bjh21     316: #if defined(_NETBSD_SOURCE)
1.63      kleink    317:
                    318: #ifndef        gid_t
                    319: typedef        __gid_t         gid_t;          /* group id */
                    320: #define        gid_t           __gid_t
                    321: #endif
                    322:
                    323: #ifndef        uid_t
                    324: typedef        __uid_t         uid_t;          /* user id */
                    325: #define        uid_t           __uid_t
                    326: #endif
                    327:
1.1       cgd       328: /*
1.27      thorpej   329:  * Socket credentials.
                    330:  */
                    331: struct sockcred {
                    332:        uid_t   sc_uid;                 /* real user id */
                    333:        uid_t   sc_euid;                /* effective user id */
                    334:        gid_t   sc_gid;                 /* real group id */
                    335:        gid_t   sc_egid;                /* effective group id */
                    336:        int     sc_ngroups;             /* number of supplemental groups */
                    337:        gid_t   sc_groups[1];           /* variable length */
                    338: };
                    339:
                    340: /*
                    341:  * Compute size of a sockcred structure with groups.
                    342:  */
                    343: #define        SOCKCREDSIZE(ngrps) \
                    344:        (sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
1.67      bjh21     345: #endif /* _NETBSD_SOURCE */
1.27      thorpej   346:
1.38      kleink    347:
1.67      bjh21     348: #if defined(_NETBSD_SOURCE)
1.27      thorpej   349: /*
1.8       mycroft   350:  * Definitions for network related sysctl, CTL_NET.
                    351:  *
                    352:  * Second level is protocol family.
                    353:  * Third level is protocol number.
                    354:  *
                    355:  * Further levels are defined by the individual families below.
                    356:  */
                    357: #define NET_MAXID      AF_MAX
                    358:
                    359: #define CTL_NET_NAMES { \
                    360:        { 0, 0 }, \
1.28      fvdl      361:        { "local", CTLTYPE_NODE }, \
1.8       mycroft   362:        { "inet", CTLTYPE_NODE }, \
                    363:        { "implink", CTLTYPE_NODE }, \
                    364:        { "pup", CTLTYPE_NODE }, \
                    365:        { "chaos", CTLTYPE_NODE }, \
                    366:        { "xerox_ns", CTLTYPE_NODE }, \
                    367:        { "iso", CTLTYPE_NODE }, \
                    368:        { "emca", CTLTYPE_NODE }, \
                    369:        { "datakit", CTLTYPE_NODE }, \
                    370:        { "ccitt", CTLTYPE_NODE }, \
                    371:        { "ibm_sna", CTLTYPE_NODE }, \
                    372:        { "decnet", CTLTYPE_NODE }, \
                    373:        { "dec_dli", CTLTYPE_NODE }, \
                    374:        { "lat", CTLTYPE_NODE }, \
                    375:        { "hylink", CTLTYPE_NODE }, \
                    376:        { "appletalk", CTLTYPE_NODE }, \
1.99      matt      377:        { "oroute", CTLTYPE_NODE }, \
1.8       mycroft   378:        { "link_layer", CTLTYPE_NODE }, \
                    379:        { "xtp", CTLTYPE_NODE }, \
                    380:        { "coip", CTLTYPE_NODE }, \
                    381:        { "cnt", CTLTYPE_NODE }, \
                    382:        { "rtip", CTLTYPE_NODE }, \
                    383:        { "ipx", CTLTYPE_NODE }, \
1.21      sommerfe  384:        { "inet6", CTLTYPE_NODE }, \
1.8       mycroft   385:        { "pip", CTLTYPE_NODE }, \
1.20      is        386:        { "isdn", CTLTYPE_NODE }, \
1.17      chuck     387:        { "natm", CTLTYPE_NODE }, \
1.20      is        388:        { "arp", CTLTYPE_NODE }, \
1.21      sommerfe  389:        { "key", CTLTYPE_NODE }, \
1.99      matt      390:        { "ieee80211", CTLTYPE_NODE }, \
                    391:        { "mlps", CTLTYPE_NODE }, \
                    392:        { "route", CTLTYPE_NODE }, \
1.8       mycroft   393: }
1.73      atatat    394:
                    395: struct kinfo_pcb {
1.75      tron      396:        __uint64_t      ki_pcbaddr;     /* PTR: pcb addr */
                    397:        __uint64_t      ki_ppcbaddr;    /* PTR: ppcb addr */
                    398:        __uint64_t      ki_sockaddr;    /* PTR: socket addr */
                    399:
                    400:        __uint32_t      ki_family;      /* INT: protocol family */
                    401:        __uint32_t      ki_type;        /* INT: socket type */
                    402:        __uint32_t      ki_protocol;    /* INT: protocol */
                    403:        __uint32_t      ki_pflags;      /* INT: generic protocol flags */
                    404:
                    405:        __uint32_t      ki_sostate;     /* INT: socket state */
                    406:        __uint32_t      ki_prstate;     /* INT: protocol state */
                    407:        __int32_t       ki_tstate;      /* INT: tcp state */
                    408:        __uint32_t      ki_tflags;      /* INT: tcp flags */
1.73      atatat    409:
1.75      tron      410:        __uint64_t      ki_rcvq;        /* U_LONG: receive queue len */
                    411:        __uint64_t      ki_sndq;        /* U_LONG: send queue len */
1.73      atatat    412:
                    413:        union {
                    414:                struct sockaddr _kis_src; /* STRUCT: local address */
                    415:                char _kis_pad[256 + 8];         /* pad to max addr length */
                    416:        } ki_s;
                    417:        union {
                    418:                struct sockaddr _kid_dst; /* STRUCT: remote address */
                    419:                char _kid_pad[256 + 8];         /* pad to max addr length */
                    420:        } ki_d;
                    421:
1.75      tron      422:        __uint64_t      ki_inode;       /* INO_T: fake inode number */
                    423:        __uint64_t      ki_vnode;       /* PTR: if associated with file */
                    424:        __uint64_t      ki_conn;        /* PTR: control block of peer */
                    425:        __uint64_t      ki_refs;        /* PTR: referencing socket */
                    426:        __uint64_t      ki_nextref;     /* PTR: link in refs list */
1.73      atatat    427: };
                    428:
                    429: #define ki_src ki_s._kis_src
                    430: #define ki_dst ki_d._kid_dst
                    431:
                    432: #define PCB_SLOP               20
                    433: #define PCB_ALL                        0
                    434:
1.67      bjh21     435: #endif /* _NETBSD_SOURCE */
1.8       mycroft   436:
1.67      bjh21     437: #if defined(_NETBSD_SOURCE)
1.8       mycroft   438: /*
                    439:  * PF_ROUTE - Routing table
                    440:  *
                    441:  * Three additional levels are defined:
                    442:  *     Fourth: address family, 0 is wildcard
                    443:  *     Fifth: type of info, defined below
                    444:  *     Sixth: flag(s) to mask with for NET_RT_FLAGS
                    445:  */
                    446: #define NET_RT_DUMP    1               /* dump; may limit to a.f. */
                    447: #define NET_RT_FLAGS   2               /* by flags, e.g. RESOLVING */
1.92      christos  448: #define NET_RT_OOIFLIST        3               /* old NET_RT_IFLIST (pre 1.5) */
                    449: #define NET_RT_OIFLIST 4               /* survey interface list */
                    450: #define        NET_RT_IFLIST   5
                    451: #define        NET_RT_MAXID    6
1.8       mycroft   452:
                    453: #define CTL_NET_RT_NAMES { \
                    454:        { 0, 0 }, \
                    455:        { "dump", CTLTYPE_STRUCT }, \
                    456:        { "flags", CTLTYPE_STRUCT }, \
1.47      bouyer    457:        { 0, 0 }, \
1.92      christos  458:        { 0, 0 }, \
1.8       mycroft   459:        { "iflist", CTLTYPE_STRUCT }, \
                    460: }
1.67      bjh21     461: #endif /* _NETBSD_SOURCE */
1.8       mycroft   462:
                    463: /*
1.13      mycroft   464:  * Maximum queue length specifiable by listen(2).
1.1       cgd       465:  */
1.66      christos  466: #ifndef SOMAXCONN
1.13      mycroft   467: #define        SOMAXCONN       128
1.66      christos  468: #endif
1.16      neil      469:
1.1       cgd       470: /*
                    471:  * Message header for recvmsg and sendmsg calls.
                    472:  * Used value-result for recvmsg, value only for sendmsg.
                    473:  */
                    474: struct msghdr {
1.42      kleink    475:        void            *msg_name;      /* optional address */
                    476:        socklen_t       msg_namelen;    /* size of address */
                    477:        struct iovec    *msg_iov;       /* scatter/gather array */
                    478:        int             msg_iovlen;     /* # elements in msg_iov */
                    479:        void            *msg_control;   /* ancillary data, see below */
                    480:        socklen_t       msg_controllen; /* ancillary data buffer len */
                    481:        int             msg_flags;      /* flags on received message */
1.1       cgd       482: };
                    483:
1.79      christos  484: #define        MSG_OOB         0x0001          /* process out-of-band data */
                    485: #define        MSG_PEEK        0x0002          /* peek at incoming message */
                    486: #define        MSG_DONTROUTE   0x0004          /* send without using routing tables */
                    487: #define        MSG_EOR         0x0008          /* data completes record */
                    488: #define        MSG_TRUNC       0x0010          /* data discarded before delivery */
                    489: #define        MSG_CTRUNC      0x0020          /* control data lost before delivery */
                    490: #define        MSG_WAITALL     0x0040          /* wait for full request or error */
                    491: #define        MSG_DONTWAIT    0x0080          /* this message should be nonblocking */
                    492: #define        MSG_BCAST       0x0100          /* this message was rcvd using link-level brdcst */
                    493: #define        MSG_MCAST       0x0200          /* this message was rcvd using link-level mcast */
                    494: #define        MSG_NOSIGNAL    0x0400          /* do not generate SIGPIPE on EOF */
1.100     christos  495: #if defined(_NETBSD_SOURCE)
                    496: #define        MSG_CMSG_CLOEXEC 0x0800         /* close on exec receiving fd */
1.101     christos  497: #define        MSG_NBIO        0x1000          /* use non-blocking I/O */
1.107     christos  498: #define        MSG_WAITFORONE  0x2000          /* recvmmsg() wait for one message */
                    499:
                    500: struct mmsghdr {
                    501:        struct msghdr msg_hdr;
                    502:        unsigned int msg_len;
                    503: };
1.100     christos  504: #endif
1.1       cgd       505:
1.86      dsl       506: /* Extra flags used internally only */
                    507: #define        MSG_USERFLAGS   0x0ffffff
                    508: #define MSG_NAMEMBUF   0x1000000       /* msg_name is an mbuf */
                    509: #define MSG_CONTROLMBUF        0x2000000       /* msg_control is an mbuf */
                    510: #define MSG_IOVUSRSPACE        0x4000000       /* msg_iov is in user space */
1.87      dsl       511: #define MSG_LENUSRSPACE        0x8000000       /* address length is in user space */
1.86      dsl       512:
1.1       cgd       513: /*
                    514:  * Header for ancillary data objects in msg_control buffer.
                    515:  * Used for additional information with/about a datagram
                    516:  * not expressible by flags.  The format is a sequence
                    517:  * of message elements headed by cmsghdr structures.
                    518:  */
                    519: struct cmsghdr {
1.42      kleink    520:        socklen_t       cmsg_len;       /* data byte count, including hdr */
                    521:        int             cmsg_level;     /* originating protocol */
                    522:        int             cmsg_type;      /* protocol-specific type */
1.1       cgd       523: /* followed by u_char  cmsg_data[]; */
                    524: };
                    525:
1.8       mycroft   526: /* given pointer to struct cmsghdr, return pointer to data */
1.50      itojun    527: #define        CMSG_DATA(cmsg) \
1.57      christos  528:        ((u_char *)(void *)(cmsg) + __CMSG_ALIGN(sizeof(struct cmsghdr)))
1.77      christos  529: #define        CCMSG_DATA(cmsg) \
                    530:        ((const u_char *)(const void *)(cmsg) + \
                    531:        __CMSG_ALIGN(sizeof(struct cmsghdr)))
1.1       cgd       532:
1.44      itojun    533: /*
                    534:  * Alignment requirement for CMSG struct manipulation.
1.51      itojun    535:  * This basically behaves the same as ALIGN() ARCH/include/param.h.
                    536:  * We declare it separately for two reasons:
                    537:  * (1) avoid dependency between machine/param.h, and (2) to sync with kernel's
                    538:  * idea of ALIGNBYTES at runtime.
                    539:  * without (2), we can't guarantee binary compatibility in case of future
                    540:  * changes in ALIGNBYTES.
1.44      itojun    541:  */
1.104     joerg     542: #define __CMSG_ALIGN(n)        (((n) + __ALIGNBYTES) & ~__ALIGNBYTES)
1.102     joerg     543: #ifdef _KERNEL
                    544: #define CMSG_ALIGN(n)  __CMSG_ALIGN(n)
1.53      itojun    545: #endif
1.44      itojun    546:
1.8       mycroft   547: /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
1.1       cgd       548: #define        CMSG_NXTHDR(mhdr, cmsg) \
1.84      christos  549:        (((char *)(cmsg) + __CMSG_ALIGN((cmsg)->cmsg_len) + \
1.53      itojun    550:                            __CMSG_ALIGN(sizeof(struct cmsghdr)) > \
1.84      christos  551:            (((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \
1.78      kleink    552:            (struct cmsghdr *)0 : \
1.106     roy       553:            (struct cmsghdr *)(void *)((char *)(cmsg) + \
1.63      kleink    554:                __CMSG_ALIGN((cmsg)->cmsg_len)))
1.1       cgd       555:
1.62      itojun    556: /*
                    557:  * RFC 2292 requires to check msg_controllen, in case that the kernel returns
                    558:  * an empty list for some reasons.
                    559:  */
                    560: #define        CMSG_FIRSTHDR(mhdr) \
                    561:        ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
                    562:         (struct cmsghdr *)(mhdr)->msg_control : \
1.78      kleink    563:         (struct cmsghdr *)0)
1.1       cgd       564:
1.53      itojun    565: #define CMSG_SPACE(l)  (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(l))
                    566: #define CMSG_LEN(l)    (__CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
1.44      itojun    567:
1.1       cgd       568: /* "Socket"-level control message types: */
                    569: #define        SCM_RIGHTS      0x01            /* access rights (array of int) */
1.67      bjh21     570: #if defined(_NETBSD_SOURCE)
1.94      christos  571: /*                     0x02               timestamp (struct timeval50) */
1.42      kleink    572: #define        SCM_CREDS       0x04            /* credentials (struct sockcred) */
1.94      christos  573: #define        SCM_TIMESTAMP   0x08            /* timestamp (struct timeval) */
1.42      kleink    574: #endif
1.29      kleink    575:
                    576: /*
                    577:  * Types of socket shutdown(2).
                    578:  */
                    579: #define        SHUT_RD         0               /* Disallow further receives. */
                    580: #define        SHUT_WR         1               /* Disallow further sends. */
                    581: #define        SHUT_RDWR       2               /* Disallow further sends/receives. */
1.1       cgd       582:
1.59      toshii    583: #include <sys/cdefs.h>
                    584:
1.85      dyoung    585: #ifdef _KERNEL
1.89      dyoung    586: static inline socklen_t
                    587: sockaddr_getlen(const struct sockaddr *sa)
                    588: {
                    589:        return sa->sa_len;
                    590: }
                    591:
1.85      dyoung    592: __BEGIN_DECLS
1.88      dyoung    593: struct sockaddr *sockaddr_copy(struct sockaddr *, socklen_t,
                    594:     const struct sockaddr *);
1.96      dyoung    595: struct sockaddr *sockaddr_externalize(struct sockaddr *, socklen_t,
                    596:     const struct sockaddr *);
1.88      dyoung    597: struct sockaddr *sockaddr_alloc(sa_family_t, socklen_t, int);
1.89      dyoung    598: const void *sockaddr_const_addr(const struct sockaddr *, socklen_t *);
                    599: void *sockaddr_addr(struct sockaddr *, socklen_t *);
                    600: const struct sockaddr *sockaddr_any(const struct sockaddr *);
1.95      dyoung    601: const struct sockaddr *sockaddr_any_by_family(int);
1.89      dyoung    602: const void *sockaddr_anyaddr(const struct sockaddr *, socklen_t *);
1.85      dyoung    603: int sockaddr_cmp(const struct sockaddr *, const struct sockaddr *);
                    604: struct sockaddr *sockaddr_dup(const struct sockaddr *, int);
1.108   ! joerg     605: void sockaddr_format(const struct sockaddr *, char *, size_t);
1.85      dyoung    606: void sockaddr_free(struct sockaddr *);
                    607: __END_DECLS
                    608: #endif /* _KERNEL */
                    609:
1.12      briggs    610: #ifndef        _KERNEL
1.1       cgd       611:
                    612: __BEGIN_DECLS
1.70      perry     613: int    accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
                    614: int    bind(int, const struct sockaddr *, socklen_t);
                    615: int    connect(int, const struct sockaddr *, socklen_t);
                    616: int    getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
                    617: int    getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
1.84      christos  618: int    getsockopt(int, int, int, void *__restrict, socklen_t * __restrict);
1.70      perry     619: int    listen(int, int);
1.100     christos  620: int    paccept(int, struct sockaddr * __restrict, socklen_t * __restrict,
                    621:        const sigset_t * __restrict, int);
1.70      perry     622: ssize_t        recv(int, void *, size_t, int);
1.84      christos  623: ssize_t        recvfrom(int, void *__restrict, size_t, int,
1.70      perry     624:            struct sockaddr * __restrict, socklen_t * __restrict);
                    625: ssize_t        recvmsg(int, struct msghdr *, int);
                    626: ssize_t        send(int, const void *, size_t, int);
                    627: ssize_t        sendto(int, const void *,
                    628:            size_t, int, const struct sockaddr *, socklen_t);
                    629: ssize_t        sendmsg(int, const struct msghdr *, int);
                    630: int    setsockopt(int, int, int, const void *, socklen_t);
                    631: int    shutdown(int, int);
                    632: int    sockatmark(int);
1.81      mrg       633: int    socket(int, int, int)
1.82      mrg       634: #if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE)
1.81      mrg       635: __RENAME(__socket30)
                    636: #endif
                    637:                             ;
1.70      perry     638: int    socketpair(int, int, int, int *);
1.107     christos  639:
                    640: #if defined(_NETBSD_SOURCE)
                    641: int    sendmmsg(int, struct mmsghdr *, unsigned int, unsigned int);
                    642: struct timespec;
                    643: int    recvmmsg(int, struct mmsghdr *, unsigned int, unsigned int,
                    644:     struct timespec *);
                    645: #endif
1.1       cgd       646: __END_DECLS
1.14      christos  647: #endif /* !_KERNEL */
1.1       cgd       648:
1.2       mycroft   649: #endif /* !_SYS_SOCKET_H_ */

CVSweb <webmaster@jp.NetBSD.org>