Back to index

lightning-sunbird  0.9+nobinonly
socket.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
00003  *     The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * [3 Deleted as of 22Jul99, see
00014  *     ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
00015  *        for details]
00016  * 4. Neither the name of the University nor the names of its contributors
00017  *    may be used to endorse or promote products derived from this software
00018  *    without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00021  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00024  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00025  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00026  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00027  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00028  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00029  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00030  * SUCH DAMAGE.
00031  *
00032  *     @(#)socket.h  8.4 (Berkeley) 2/21/94
00033  */
00034 
00035 /* Adapted for GUSI by Matthias Neeracher <neeri@iis.ee.ethz.ch> */
00036 
00037 #ifndef _SYS_SOCKET_H_
00038 #define       _SYS_SOCKET_H_
00039 
00040 /*
00041  * Definitions related to sockets: types, address families, options.
00042  */
00043 
00044 /*
00045  * Types
00046  */
00047 #define       SOCK_STREAM   1             /* stream socket */
00048 #define       SOCK_DGRAM    2             /* datagram socket */
00049 #define       SOCK_RAW      3             /* raw-protocol interface */
00050 #define       SOCK_RDM      4             /* reliably-delivered message */
00051 #define       SOCK_SEQPACKET       5             /* sequenced packet stream */
00052 
00053 /*
00054  * Option flags per-socket.
00055  */
00056 #define       SO_DEBUG      0x0001        /* turn on debugging info recording */
00057 #define       SO_ACCEPTCONN 0x0002        /* socket has had listen() */
00058 #define       SO_REUSEADDR  0x0004        /* allow local address reuse */
00059 #define       SO_KEEPALIVE  0x0008        /* keep connections alive */
00060 #define       SO_DONTROUTE  0x0010        /* just use interface addresses */
00061 #define       SO_BROADCAST  0x0020        /* permit sending of broadcast msgs */
00062 #define       SO_USELOOPBACK       0x0040        /* bypass hardware when possible */
00063 #define       SO_LINGER     0x0080        /* linger on close if data present */
00064 #define       SO_OOBINLINE  0x0100        /* leave received OOB data in line */
00065 #define       SO_REUSEPORT  0x0200        /* allow local address & port reuse */
00066 
00067 /*
00068  * Additional options, not kept in so_options.
00069  */
00070 #define SO_SNDBUF    0x1001        /* send buffer size */
00071 #define SO_RCVBUF    0x1002        /* receive buffer size */
00072 #define SO_SNDLOWAT  0x1003        /* send low-water mark */
00073 #define SO_RCVLOWAT  0x1004        /* receive low-water mark */
00074 #define SO_SNDTIMEO  0x1005        /* send timeout */
00075 #define SO_RCVTIMEO  0x1006        /* receive timeout */
00076 #define       SO_ERROR      0x1007        /* get error status and clear */
00077 #define       SO_TYPE              0x1008        /* get socket type */
00078 
00079 /* Mandated by XNS -- neeri */
00080 typedef unsigned     socklen_t;
00081 
00082 /*
00083  * Structure used for manipulating linger option.
00084  */
00085 struct linger {
00086        int    l_onoff;             /* option on/off */
00087        int    l_linger;            /* linger time */
00088 };
00089 
00090 /*
00091  * Level number for (get/set)sockopt() to apply to socket itself.
00092  */
00093 #define       SOL_SOCKET    0xffff        /* options for socket level */
00094 
00095 /*
00096  * Address families.
00097  */
00098 #define       AF_UNSPEC     0                    /* unspecified */
00099 #define       AF_LOCAL             1                    /* local to host (pipes, portals) */
00100 #define       AF_UNIX              AF_LOCAL      /* backward compatibility */
00101 #define       AF_INET              2                    /* internetwork: UDP, TCP, etc. */
00102 #define       AF_PPC        3                    /* PPC Toolbox                                                                      */
00103 #define       AF_PAP        4                    /* Printer Access Protocol  */
00104 #define       AF_APPLETALK  16            /* Apple Talk */
00105 
00106 #define       ATALK_SYMADDR        272           /* Symbolic Address for AppleTalk                */
00107 
00108 #define       AF_MAX        20
00109 
00110 #define       PF_UNSPEC     0                    /* unspecified */
00111 #define       PF_LOCAL             1                    /* local to host (pipes, portals) */
00112 #define       PF_UNIX              AF_LOCAL      /* backward compatibility */
00113 #define       PF_INET              2                    /* internetwork: UDP, TCP, etc. */
00114 #define       PF_PPC        3                    /* PPC Toolbox                                                                      */
00115 #define       PF_PAP        4                    /* Printer Access Protocol  */
00116 #define       PF_APPLETALK  16            /* Apple Talk */
00117 
00118 /* Mandated by XNS -- neeri */
00119 #define SHUT_RD      0
00120 #define SHUT_WR      1
00121 #define SHUT_RDWR    2
00122 
00123 #ifndef _SA_FAMILY_T_DEFINED
00124 #define _SA_FAMILY_T_DEFINED
00125 typedef unsigned short sa_family_t;
00126 #endif
00127 
00128 /*
00129  * Structure used by kernel to store most
00130  * addresses.
00131  */
00132 struct sockaddr {
00133        sa_family_t   sa_family;           /* address family */
00134        char                 sa_data[14];  /* actually longer; address value */
00135 };
00136 
00137 /*
00138  * Definitions for network related sysctl, CTL_NET.
00139  *
00140  * Second level is protocol family.
00141  * Third level is protocol number.
00142  *
00143  * Further levels are defined by the individual families below.
00144  */
00145 #define NET_MAXID    AF_MAX
00146 
00147 #define CTL_NET_NAMES { \
00148        { 0, 0 }, \
00149        { "unix", CTLTYPE_NODE }, \
00150        { "inet", CTLTYPE_NODE }, \
00151        { "ppc", CTLTYPE_NODE }, \
00152        { "pap", CTLTYPE_NODE }, \
00153        { "", CTLTYPE_NODE }, \
00154        { "", CTLTYPE_NODE }, \
00155        { "", CTLTYPE_NODE }, \
00156        { "", CTLTYPE_NODE }, \
00157        { "", CTLTYPE_NODE }, \
00158        { "", CTLTYPE_NODE }, \
00159        { "", CTLTYPE_NODE }, \
00160        { "", CTLTYPE_NODE }, \
00161        { "", CTLTYPE_NODE }, \
00162        { "", CTLTYPE_NODE }, \
00163        { "", CTLTYPE_NODE }, \
00164        { "appletalk", CTLTYPE_NODE }, \
00165 }
00166 
00167 /*
00168  * PF_ROUTE - Routing table
00169  *
00170  * Three additional levels are defined:
00171  *     Fourth: address family, 0 is wildcard
00172  *     Fifth: type of info, defined below
00173  *     Sixth: flag(s) to mask with for NET_RT_FLAGS
00174  */
00175 #define NET_RT_DUMP  1             /* dump; may limit to a.f. */
00176 #define NET_RT_FLAGS 2             /* by flags, e.g. RESOLVING */
00177 #define NET_RT_IFLIST       3             /* survey interface list */
00178 #define       NET_RT_MAXID  4
00179 
00180 #define CTL_NET_RT_NAMES { \
00181        { 0, 0 }, \
00182        { "dump", CTLTYPE_STRUCT }, \
00183        { "flags", CTLTYPE_STRUCT }, \
00184        { "iflist", CTLTYPE_STRUCT }, \
00185 }
00186 
00187 /*
00188  * Maximum queue length specifiable by listen.
00189  */
00190 #define       SOMAXCONN     5
00191 
00192 /*
00193  * Message header for recvmsg and sendmsg calls.
00194  * Used value-result for recvmsg, value only for sendmsg.
00195  */
00196 struct msghdr {
00197        void *        msg_name;                   /* optional address */
00198        socklen_t     msg_namelen;         /* size of address */
00199        struct iovec *msg_iov;                    /* scatter/gather array */
00200        int                  msg_iovlen;                 /* # elements in msg_iov */
00201        void *        msg_control;         /* ancillary data, see below */
00202        socklen_t     msg_controllen;      /* ancillary data buffer len */
00203        int                  msg_flags;                  /* flags on received message */
00204 };
00205 
00206 #define       MSG_OOB                     0x1           /* process out-of-band data */
00207 #define       MSG_PEEK                    0x2                  /* peek at incoming message */
00208 #define       MSG_DONTROUTE 0x4           /* send without using routing tables */
00209 #define       MSG_EOR                     0x8           /* data completes record */
00210 #define       MSG_TRUNC            0x10          /* data discarded before delivery */
00211 #define       MSG_CTRUNC           0x20          /* control data lost before delivery */
00212 #define       MSG_WAITALL          0x40          /* wait for full request or error */
00213 #define       MSG_DONTWAIT  0x80          /* this message should be nonblocking */
00214 
00215 /*
00216  * Header for ancillary data objects in msg_control buffer.
00217  * Used for additional information with/about a datagram
00218  * not expressible by flags.  The format is a sequence
00219  * of message elements headed by cmsghdr structures.
00220  */
00221 struct cmsghdr {
00222        socklen_t     cmsg_len;            /* data byte count, including hdr */
00223        int                  cmsg_level;          /* originating protocol */
00224        int                  cmsg_type;           /* protocol-specific type */
00225 /* followed by       u_char  cmsg_data[]; */
00226 };
00227 
00228 /* given pointer to struct cmsghdr, return pointer to data */
00229 #define       CMSG_DATA(cmsg)             ((u_char *)((cmsg) + 1))
00230 
00231 /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
00232 #define       CMSG_NXTHDR(mhdr, cmsg)     \
00233        (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
00234            (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
00235            (struct cmsghdr *)NULL : \
00236            (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
00237 
00238 #define       CMSG_FIRSTHDR(mhdr)  ((struct cmsghdr *)(mhdr)->msg_control)
00239 
00240 /* "Socket"-level control message types: */
00241 #define       SCM_RIGHTS    0x01          /* access rights (array of int) */
00242 
00243 #include <sys/cdefs.h>
00244 
00245 __BEGIN_DECLS
00246 int    accept __P((int, struct sockaddr *, socklen_t *));
00247 int    bind __P((int, const struct sockaddr *, socklen_t));
00248 int    connect __P((int, const struct sockaddr *, socklen_t));
00249 int    getpeername __P((int, struct sockaddr *, socklen_t *));
00250 int    getsockname __P((int, struct sockaddr *, socklen_t *));
00251 int    getsockopt __P((int, int, int, void *, socklen_t *));
00252 int    listen __P((int, int));
00253 ssize_t       recv __P((int, void *, size_t, int));
00254 ssize_t       recvfrom __P((int, void *, size_t, int, struct sockaddr *, socklen_t *));
00255 ssize_t       recvmsg __P((int, struct msghdr *, int));
00256 ssize_t       send __P((int, const void *, size_t, int));
00257 ssize_t       sendto __P((int, const void *,
00258            size_t, int, const struct sockaddr *, socklen_t));
00259 ssize_t       sendmsg __P((int, const struct msghdr *, int));
00260 int    setsockopt __P((int, int, int, const void *, socklen_t));
00261 int    shutdown __P((int, int));
00262 int    socket __P((int, int, int));
00263 int    socketpair __P((int, int, int, int *));
00264 __END_DECLS
00265 
00266 #endif /* !_SYS_SOCKET_H_ */