The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/socket.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *      This product includes software developed by the University of
   16  *      California, Berkeley and its contributors.
   17  * 4. Neither the name of the University nor the names of its contributors
   18  *    may be used to endorse or promote products derived from this software
   19  *    without specific prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   31  * SUCH DAMAGE.
   32  *
   33  *      @(#)socket.h    8.4 (Berkeley) 2/21/94
   34  * $FreeBSD$
   35  */
   36 
   37 #ifndef _SYS_SOCKET_H_
   38 #define _SYS_SOCKET_H_
   39 
   40 /*
   41  * Definitions related to sockets: types, address families, options.
   42  */
   43 
   44 /*
   45  * Data types.
   46  */
   47 typedef u_char          sa_family_t;
   48 typedef int             socklen_t;
   49 
   50 /*
   51  * Types
   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 */
   71 #define SO_REUSEPORT    0x0200          /* allow local address & port reuse */
   72 #define SO_TIMESTAMP    0x0400          /* timestamp received dgram traffic */
   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 /*efine SO_PRIVSTATE    0x1009             get/deny privileged state */
   86 
   87 /*
   88  * Structure used for manipulating linger option.
   89  */
   90 struct  linger {
   91         int     l_onoff;                /* option on/off */
   92         int     l_linger;               /* linger time */
   93 };
   94 
   95 /*
   96  * Level number for (get/set)sockopt() to apply to socket itself.
   97  */
   98 #define SOL_SOCKET      0xffff          /* options for socket level */
   99 
  100 /*
  101  * Address families.
  102  */
  103 #define AF_UNSPEC       0               /* unspecified */
  104 #define AF_LOCAL        1               /* local to host (pipes, portals) */
  105 #define AF_UNIX         AF_LOCAL        /* backward compatibility */
  106 #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
  107 #define AF_IMPLINK      3               /* arpanet imp addresses */
  108 #define AF_PUP          4               /* pup protocols: e.g. BSP */
  109 #define AF_CHAOS        5               /* mit CHAOS protocols */
  110 #define AF_NS           6               /* XEROX NS protocols */
  111 #define AF_ISO          7               /* ISO protocols */
  112 #define AF_OSI          AF_ISO
  113 #define AF_ECMA         8               /* European computer manufacturers */
  114 #define AF_DATAKIT      9               /* datakit protocols */
  115 #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
  116 #define AF_SNA          11              /* IBM SNA */
  117 #define AF_DECnet       12              /* DECnet */
  118 #define AF_DLI          13              /* DEC Direct data link interface */
  119 #define AF_LAT          14              /* LAT */
  120 #define AF_HYLINK       15              /* NSC Hyperchannel */
  121 #define AF_APPLETALK    16              /* Apple Talk */
  122 #define AF_ROUTE        17              /* Internal Routing Protocol */
  123 #define AF_LINK         18              /* Link layer interface */
  124 #define pseudo_AF_XTP   19              /* eXpress Transfer Protocol (no AF) */
  125 #define AF_COIP         20              /* connection-oriented IP, aka ST II */
  126 #define AF_CNT          21              /* Computer Network Technology */
  127 #define pseudo_AF_RTIP  22              /* Help Identify RTIP packets */
  128 #define AF_IPX          23              /* Novell Internet Protocol */
  129 #define AF_SIP          24              /* Simple Internet Protocol */
  130 #define pseudo_AF_PIP   25              /* Help Identify PIP packets */
  131 #define AF_ISDN         26              /* Integrated Services Digital Network*/
  132 #define AF_E164         AF_ISDN         /* CCITT E.164 recommendation */
  133 #define pseudo_AF_KEY   27              /* Internal key-management function */
  134 #define AF_INET6        28              /* IPv6 */
  135 #define AF_NATM         29              /* native ATM access */
  136 #define AF_ATM          30              /* ATM */
  137 #define pseudo_AF_HDRCMPLT 31           /* Used by BPF in 4.x to not rewrite
  138                                          * headers in interface output routine
  139                                          */
  140 #define AF_NETGRAPH     32              /* Netgraph sockets */
  141 
  142 #define AF_MAX          33
  143 
  144 /*
  145  * Structure used by kernel to store most
  146  * addresses.
  147  */
  148 struct sockaddr {
  149         u_char  sa_len;                 /* total length */
  150         u_char  sa_family;              /* address family */
  151         char    sa_data[14];            /* actually longer; address value */
  152 };
  153 #define SOCK_MAXADDRLEN 255             /* longest possible addresses */
  154 
  155 /*
  156  * Structure used by kernel to pass protocol
  157  * information in raw sockets.
  158  */
  159 struct sockproto {
  160         u_short sp_family;              /* address family */
  161         u_short sp_protocol;            /* protocol */
  162 };
  163 
  164 /*
  165  * Protocol families, same as address families for now.
  166  */
  167 #define PF_UNSPEC       AF_UNSPEC
  168 #define PF_LOCAL        AF_LOCAL
  169 #define PF_UNIX         PF_LOCAL        /* backward compatibility */
  170 #define PF_INET         AF_INET
  171 #define PF_IMPLINK      AF_IMPLINK
  172 #define PF_PUP          AF_PUP
  173 #define PF_CHAOS        AF_CHAOS
  174 #define PF_NS           AF_NS
  175 #define PF_ISO          AF_ISO
  176 #define PF_OSI          AF_ISO
  177 #define PF_ECMA         AF_ECMA
  178 #define PF_DATAKIT      AF_DATAKIT
  179 #define PF_CCITT        AF_CCITT
  180 #define PF_SNA          AF_SNA
  181 #define PF_DECnet       AF_DECnet
  182 #define PF_DLI          AF_DLI
  183 #define PF_LAT          AF_LAT
  184 #define PF_HYLINK       AF_HYLINK
  185 #define PF_APPLETALK    AF_APPLETALK
  186 #define PF_ROUTE        AF_ROUTE
  187 #define PF_LINK         AF_LINK
  188 #define PF_XTP          pseudo_AF_XTP   /* really just proto family, no AF */
  189 #define PF_COIP         AF_COIP
  190 #define PF_CNT          AF_CNT
  191 #define PF_SIP          AF_SIP
  192 #define PF_IPX          AF_IPX          /* same format as AF_NS */
  193 #define PF_RTIP         pseudo_AF_RTIP  /* same format as AF_INET */
  194 #define PF_PIP          pseudo_AF_PIP
  195 #define PF_ISDN         AF_ISDN
  196 #define PF_KEY          pseudo_AF_KEY
  197 #define PF_INET6        AF_INET6
  198 #define PF_NATM         AF_NATM
  199 #define PF_ATM          AF_ATM
  200 #define PF_NETGRAPH     AF_NETGRAPH
  201 
  202 #define PF_MAX          AF_MAX
  203 
  204 /*
  205  * Definitions for network related sysctl, CTL_NET.
  206  *
  207  * Second level is protocol family.
  208  * Third level is protocol number.
  209  *
  210  * Further levels are defined by the individual families below.
  211  */
  212 #define NET_MAXID       AF_MAX
  213 
  214 #define CTL_NET_NAMES { \
  215         { 0, 0 }, \
  216         { "unix", CTLTYPE_NODE }, \
  217         { "inet", CTLTYPE_NODE }, \
  218         { "implink", CTLTYPE_NODE }, \
  219         { "pup", CTLTYPE_NODE }, \
  220         { "chaos", CTLTYPE_NODE }, \
  221         { "xerox_ns", CTLTYPE_NODE }, \
  222         { "iso", CTLTYPE_NODE }, \
  223         { "emca", CTLTYPE_NODE }, \
  224         { "datakit", CTLTYPE_NODE }, \
  225         { "ccitt", CTLTYPE_NODE }, \
  226         { "ibm_sna", CTLTYPE_NODE }, \
  227         { "decnet", CTLTYPE_NODE }, \
  228         { "dec_dli", CTLTYPE_NODE }, \
  229         { "lat", CTLTYPE_NODE }, \
  230         { "hylink", CTLTYPE_NODE }, \
  231         { "appletalk", CTLTYPE_NODE }, \
  232         { "route", CTLTYPE_NODE }, \
  233         { "link_layer", CTLTYPE_NODE }, \
  234         { "xtp", CTLTYPE_NODE }, \
  235         { "coip", CTLTYPE_NODE }, \
  236         { "cnt", CTLTYPE_NODE }, \
  237         { "rtip", CTLTYPE_NODE }, \
  238         { "ipx", CTLTYPE_NODE }, \
  239         { "sip", CTLTYPE_NODE }, \
  240         { "pip", CTLTYPE_NODE }, \
  241         { "isdn", CTLTYPE_NODE }, \
  242         { "key", CTLTYPE_NODE }, \
  243         { "inet6", CTLTYPE_NODE }, \
  244         { "natm", CTLTYPE_NODE }, \
  245         { "netgraph", CTLTYPE_NODE } \
  246 }
  247 
  248 /*
  249  * PF_ROUTE - Routing table
  250  *
  251  * Three additional levels are defined:
  252  *      Fourth: address family, 0 is wildcard
  253  *      Fifth: type of info, defined below
  254  *      Sixth: flag(s) to mask with for NET_RT_FLAGS
  255  */
  256 #define NET_RT_DUMP     1               /* dump; may limit to a.f. */
  257 #define NET_RT_FLAGS    2               /* by flags, e.g. RESOLVING */
  258 #define NET_RT_IFLIST   3               /* survey interface list */
  259 #define NET_RT_MAXID    4
  260 
  261 #define CTL_NET_RT_NAMES { \
  262         { 0, 0 }, \
  263         { "dump", CTLTYPE_STRUCT }, \
  264         { "flags", CTLTYPE_STRUCT }, \
  265         { "iflist", CTLTYPE_STRUCT }, \
  266 }
  267 
  268 /*
  269  * Maximum queue length specifiable by listen.
  270  */
  271 #define SOMAXCONN       128
  272 
  273 /*
  274  * Message header for recvmsg and sendmsg calls.
  275  * Used value-result for recvmsg, value only for sendmsg.
  276  */
  277 struct msghdr {
  278         caddr_t msg_name;               /* optional address */
  279         u_int   msg_namelen;            /* size of address */
  280         struct  iovec *msg_iov;         /* scatter/gather array */
  281         u_int   msg_iovlen;             /* # elements in msg_iov */
  282         caddr_t msg_control;            /* ancillary data, see below */
  283         u_int   msg_controllen;         /* ancillary data buffer len */
  284         int     msg_flags;              /* flags on received message */
  285 };
  286 
  287 #define MSG_OOB         0x1             /* process out-of-band data */
  288 #define MSG_PEEK        0x2             /* peek at incoming message */
  289 #define MSG_DONTROUTE   0x4             /* send without using routing tables */
  290 #define MSG_EOR         0x8             /* data completes record */
  291 #define MSG_TRUNC       0x10            /* data discarded before delivery */
  292 #define MSG_CTRUNC      0x20            /* control data lost before delivery */
  293 #define MSG_WAITALL     0x40            /* wait for full request or error */
  294 #define MSG_DONTWAIT    0x80            /* this message should be nonblocking */
  295 #define MSG_EOF         0x100           /* data completes connection */
  296 #define MSG_COMPAT      0x8000          /* used in sendit() */
  297 
  298 /*
  299  * Header for ancillary data objects in msg_control buffer.
  300  * Used for additional information with/about a datagram
  301  * not expressible by flags.  The format is a sequence
  302  * of message elements headed by cmsghdr structures.
  303  */
  304 struct cmsghdr {
  305         u_int   cmsg_len;               /* data byte count, including hdr */
  306         int     cmsg_level;             /* originating protocol */
  307         int     cmsg_type;              /* protocol-specific type */
  308 /* followed by  u_char  cmsg_data[]; */
  309 };
  310 
  311 /*
  312  * While we may have more groups than this, the cmsgcred struct must
  313  * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
  314  * this.
  315 */
  316 #define CMGROUP_MAX 16
  317 
  318 /*
  319  * Credentials structure, used to verify the identity of a peer
  320  * process that has sent us a message. This is allocated by the
  321  * peer process but filled in by the kernel. This prevents the
  322  * peer from lying about its identity. (Note that cmcred_groups[0]
  323  * is the effective GID.)
  324  */
  325 struct cmsgcred {
  326         pid_t   cmcred_pid;             /* PID of sending process */
  327         uid_t   cmcred_uid;             /* real UID of sending process */
  328         uid_t   cmcred_euid;            /* effective UID of sending process */
  329         gid_t   cmcred_gid;             /* real GID of sending process */
  330         short   cmcred_ngroups;         /* number or groups */
  331         gid_t   cmcred_groups[CMGROUP_MAX];     /* groups */
  332 };
  333 
  334 /* given pointer to struct cmsghdr, return pointer to data */
  335 #define CMSG_DATA(cmsg)         ((u_char *)((cmsg) + 1))
  336 
  337 /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
  338 #define CMSG_NXTHDR(mhdr, cmsg) \
  339         (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
  340             (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
  341             (struct cmsghdr *)NULL : \
  342             (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
  343 
  344 #define CMSG_FIRSTHDR(mhdr)     ((struct cmsghdr *)(mhdr)->msg_control)
  345 
  346 /* "Socket"-level control message types: */
  347 #define SCM_RIGHTS      0x01            /* access rights (array of int) */
  348 #define SCM_TIMESTAMP   0x02            /* timestamp (struct timeval) */
  349 #define SCM_CREDS       0x03            /* process creds (struct cmsgcred) */
  350 
  351 /*
  352  * 4.3 compat sockaddr, move to compat file later
  353  */
  354 struct osockaddr {
  355         u_short sa_family;              /* address family */
  356         char    sa_data[14];            /* up to 14 bytes of direct address */
  357 };
  358 
  359 /*
  360  * 4.3-compat message header (move to compat file later).
  361  */
  362 struct omsghdr {
  363         caddr_t msg_name;               /* optional address */
  364         int     msg_namelen;            /* size of address */
  365         struct  iovec *msg_iov;         /* scatter/gather array */
  366         int     msg_iovlen;             /* # elements in msg_iov */
  367         caddr_t msg_accrights;          /* access rights sent/received */
  368         int     msg_accrightslen;
  369 };
  370 
  371 /*
  372  * howto arguments for shutdown(2), specified by Posix.1g.
  373  */
  374 #define SHUT_RD         0               /* shut down the reading side */
  375 #define SHUT_WR         1               /* shut down the writing side */
  376 #define SHUT_RDWR       2               /* shut down both sides */
  377 
  378 /*
  379  * sendfile(2) header/trailer struct
  380  */
  381 struct sf_hdtr {
  382         struct iovec *headers;  /* pointer to an array of header struct iovec's */
  383         int hdr_cnt;            /* number of header iovec's */
  384         struct iovec *trailers; /* pointer to an array of trailer struct iovec's */
  385         int trl_cnt;            /* number of trailer iovec's */
  386 };
  387 
  388 #ifndef KERNEL
  389 
  390 #include <sys/cdefs.h>
  391 
  392 __BEGIN_DECLS
  393 int     accept __P((int, struct sockaddr *, int *));
  394 int     bind __P((int, const struct sockaddr *, int));
  395 int     connect __P((int, const struct sockaddr *, int));
  396 int     getpeername __P((int, struct sockaddr *, int *));
  397 int     getsockname __P((int, struct sockaddr *, int *));
  398 int     getsockopt __P((int, int, int, void *, int *));
  399 int     listen __P((int, int));
  400 ssize_t recv __P((int, void *, size_t, int));
  401 ssize_t recvfrom __P((int, void *, size_t, int, struct sockaddr *, int *));
  402 ssize_t recvmsg __P((int, struct msghdr *, int));
  403 ssize_t send __P((int, const void *, size_t, int));
  404 ssize_t sendto __P((int, const void *,
  405             size_t, int, const struct sockaddr *, int));
  406 ssize_t sendmsg __P((int, const struct msghdr *, int));
  407 int     sendfile __P((int, int, off_t, size_t, struct sf_hdtr *, off_t *, int));
  408 int     setsockopt __P((int, int, int, const void *, int));
  409 int     shutdown __P((int, int));
  410 int     socket __P((int, int, int));
  411 int     socketpair __P((int, int, int, int *));
  412 __END_DECLS
  413 
  414 #endif /* !KERNEL */
  415 
  416 #endif /* !_SYS_SOCKET_H_ */

Cache object: 2bb8281eb568d1e7d1022563b51d2e41


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.