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

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

CVSweb <webmaster@jp.NetBSD.org>