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

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

CVSweb <webmaster@jp.NetBSD.org>