socket.h revision 16480
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 3. All advertising materials mentioning features or use of this software 141541Srgrimes * must display the following acknowledgement: 151541Srgrimes * This product includes software developed by the University of 161541Srgrimes * California, Berkeley and its contributors. 171541Srgrimes * 4. Neither the name of the University nor the names of its contributors 181541Srgrimes * may be used to endorse or promote products derived from this software 191541Srgrimes * without specific prior written permission. 201541Srgrimes * 211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311541Srgrimes * SUCH DAMAGE. 321541Srgrimes * 331541Srgrimes * @(#)socket.h 8.4 (Berkeley) 2/21/94 3416480Swollman * $Id: socket.h,v 1.12 1996/06/14 17:22:18 wollman Exp $ 351541Srgrimes */ 361541Srgrimes 371541Srgrimes#ifndef _SYS_SOCKET_H_ 381541Srgrimes#define _SYS_SOCKET_H_ 391541Srgrimes 401541Srgrimes/* 411541Srgrimes * Definitions related to sockets: types, address families, options. 421541Srgrimes */ 431541Srgrimes 441541Srgrimes/* 451541Srgrimes * Types 461541Srgrimes */ 471541Srgrimes#define SOCK_STREAM 1 /* stream socket */ 481541Srgrimes#define SOCK_DGRAM 2 /* datagram socket */ 491541Srgrimes#define SOCK_RAW 3 /* raw-protocol interface */ 501541Srgrimes#define SOCK_RDM 4 /* reliably-delivered message */ 511541Srgrimes#define SOCK_SEQPACKET 5 /* sequenced packet stream */ 521541Srgrimes 531541Srgrimes/* 541541Srgrimes * Option flags per-socket. 551541Srgrimes */ 561541Srgrimes#define SO_DEBUG 0x0001 /* turn on debugging info recording */ 571541Srgrimes#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 581541Srgrimes#define SO_REUSEADDR 0x0004 /* allow local address reuse */ 591541Srgrimes#define SO_KEEPALIVE 0x0008 /* keep connections alive */ 601541Srgrimes#define SO_DONTROUTE 0x0010 /* just use interface addresses */ 611541Srgrimes#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ 621541Srgrimes#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ 631541Srgrimes#define SO_LINGER 0x0080 /* linger on close if data present */ 641541Srgrimes#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ 651541Srgrimes#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ 6615701Swollman#define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */ 671541Srgrimes 681541Srgrimes/* 691541Srgrimes * Additional options, not kept in so_options. 701541Srgrimes */ 711541Srgrimes#define SO_SNDBUF 0x1001 /* send buffer size */ 721541Srgrimes#define SO_RCVBUF 0x1002 /* receive buffer size */ 731541Srgrimes#define SO_SNDLOWAT 0x1003 /* send low-water mark */ 741541Srgrimes#define SO_RCVLOWAT 0x1004 /* receive low-water mark */ 751541Srgrimes#define SO_SNDTIMEO 0x1005 /* send timeout */ 761541Srgrimes#define SO_RCVTIMEO 0x1006 /* receive timeout */ 771541Srgrimes#define SO_ERROR 0x1007 /* get error status and clear */ 781541Srgrimes#define SO_TYPE 0x1008 /* get socket type */ 7913955Swollman#define SO_PRIVSTATE 0x1009 /* get/deny privileged state */ 801541Srgrimes 811541Srgrimes/* 821541Srgrimes * Structure used for manipulating linger option. 831541Srgrimes */ 841541Srgrimesstruct linger { 851541Srgrimes int l_onoff; /* option on/off */ 861541Srgrimes int l_linger; /* linger time */ 871541Srgrimes}; 881541Srgrimes 891541Srgrimes/* 901541Srgrimes * Level number for (get/set)sockopt() to apply to socket itself. 911541Srgrimes */ 921541Srgrimes#define SOL_SOCKET 0xffff /* options for socket level */ 931541Srgrimes 941541Srgrimes/* 951541Srgrimes * Address families. 961541Srgrimes */ 971541Srgrimes#define AF_UNSPEC 0 /* unspecified */ 981541Srgrimes#define AF_LOCAL 1 /* local to host (pipes, portals) */ 991541Srgrimes#define AF_UNIX AF_LOCAL /* backward compatibility */ 1001541Srgrimes#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 1011541Srgrimes#define AF_IMPLINK 3 /* arpanet imp addresses */ 1021541Srgrimes#define AF_PUP 4 /* pup protocols: e.g. BSP */ 1031541Srgrimes#define AF_CHAOS 5 /* mit CHAOS protocols */ 1041541Srgrimes#define AF_NS 6 /* XEROX NS protocols */ 1051541Srgrimes#define AF_ISO 7 /* ISO protocols */ 1061541Srgrimes#define AF_OSI AF_ISO 10713765Smpp#define AF_ECMA 8 /* European computer manufacturers */ 1081541Srgrimes#define AF_DATAKIT 9 /* datakit protocols */ 1091541Srgrimes#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 1101541Srgrimes#define AF_SNA 11 /* IBM SNA */ 1111541Srgrimes#define AF_DECnet 12 /* DECnet */ 1121541Srgrimes#define AF_DLI 13 /* DEC Direct data link interface */ 1131541Srgrimes#define AF_LAT 14 /* LAT */ 1141541Srgrimes#define AF_HYLINK 15 /* NSC Hyperchannel */ 1151541Srgrimes#define AF_APPLETALK 16 /* Apple Talk */ 1161541Srgrimes#define AF_ROUTE 17 /* Internal Routing Protocol */ 1171541Srgrimes#define AF_LINK 18 /* Link layer interface */ 1181541Srgrimes#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ 1191541Srgrimes#define AF_COIP 20 /* connection-oriented IP, aka ST II */ 1201541Srgrimes#define AF_CNT 21 /* Computer Network Technology */ 1211541Srgrimes#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ 1221541Srgrimes#define AF_IPX 23 /* Novell Internet Protocol */ 1231541Srgrimes#define AF_SIP 24 /* Simple Internet Protocol */ 1245413Sse#define pseudo_AF_PIP 25 /* Help Identify PIP packets */ 1255413Sse#define AF_ISDN 26 /* Integrated Services Digital Network*/ 1265413Sse#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ 12716368Swollman#define pseudo_AF_KEY 27 /* Internal key-management function */ 1281541Srgrimes 12916368Swollman#define AF_MAX 28 1301541Srgrimes 1311541Srgrimes/* 1321541Srgrimes * Structure used by kernel to store most 1331541Srgrimes * addresses. 1341541Srgrimes */ 1351541Srgrimesstruct sockaddr { 1361541Srgrimes u_char sa_len; /* total length */ 1371541Srgrimes u_char sa_family; /* address family */ 1381541Srgrimes char sa_data[14]; /* actually longer; address value */ 1391541Srgrimes}; 1401541Srgrimes 1411541Srgrimes/* 1421541Srgrimes * Structure used by kernel to pass protocol 1431541Srgrimes * information in raw sockets. 1441541Srgrimes */ 1451541Srgrimesstruct sockproto { 1461541Srgrimes u_short sp_family; /* address family */ 1471541Srgrimes u_short sp_protocol; /* protocol */ 1481541Srgrimes}; 1491541Srgrimes 1501541Srgrimes/* 1511541Srgrimes * Protocol families, same as address families for now. 1521541Srgrimes */ 1531541Srgrimes#define PF_UNSPEC AF_UNSPEC 1541541Srgrimes#define PF_LOCAL AF_LOCAL 1551541Srgrimes#define PF_UNIX PF_LOCAL /* backward compatibility */ 1561541Srgrimes#define PF_INET AF_INET 1571541Srgrimes#define PF_IMPLINK AF_IMPLINK 1581541Srgrimes#define PF_PUP AF_PUP 1591541Srgrimes#define PF_CHAOS AF_CHAOS 1601541Srgrimes#define PF_NS AF_NS 1611541Srgrimes#define PF_ISO AF_ISO 1621541Srgrimes#define PF_OSI AF_ISO 1631541Srgrimes#define PF_ECMA AF_ECMA 1641541Srgrimes#define PF_DATAKIT AF_DATAKIT 1651541Srgrimes#define PF_CCITT AF_CCITT 1661541Srgrimes#define PF_SNA AF_SNA 1671541Srgrimes#define PF_DECnet AF_DECnet 1681541Srgrimes#define PF_DLI AF_DLI 1691541Srgrimes#define PF_LAT AF_LAT 1701541Srgrimes#define PF_HYLINK AF_HYLINK 1711541Srgrimes#define PF_APPLETALK AF_APPLETALK 1721541Srgrimes#define PF_ROUTE AF_ROUTE 1731541Srgrimes#define PF_LINK AF_LINK 1741541Srgrimes#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ 1751541Srgrimes#define PF_COIP AF_COIP 1761541Srgrimes#define PF_CNT AF_CNT 1771541Srgrimes#define PF_SIP AF_SIP 1781541Srgrimes#define PF_IPX AF_IPX /* same format as AF_NS */ 1791541Srgrimes#define PF_RTIP pseudo_AF_FTIP /* same format as AF_INET */ 1801541Srgrimes#define PF_PIP pseudo_AF_PIP 1815413Sse#define PF_ISDN AF_ISDN 18216480Swollman#define PF_KEY pseudo_AF_KEY 1831541Srgrimes 1841541Srgrimes#define PF_MAX AF_MAX 1851541Srgrimes 1861541Srgrimes/* 1871541Srgrimes * Definitions for network related sysctl, CTL_NET. 1881541Srgrimes * 1891541Srgrimes * Second level is protocol family. 1901541Srgrimes * Third level is protocol number. 1911541Srgrimes * 1921541Srgrimes * Further levels are defined by the individual families below. 1931541Srgrimes */ 1941541Srgrimes#define NET_MAXID AF_MAX 1951541Srgrimes 1961541Srgrimes#define CTL_NET_NAMES { \ 1971541Srgrimes { 0, 0 }, \ 1981541Srgrimes { "unix", CTLTYPE_NODE }, \ 1991541Srgrimes { "inet", CTLTYPE_NODE }, \ 2001541Srgrimes { "implink", CTLTYPE_NODE }, \ 2011541Srgrimes { "pup", CTLTYPE_NODE }, \ 2021541Srgrimes { "chaos", CTLTYPE_NODE }, \ 2031541Srgrimes { "xerox_ns", CTLTYPE_NODE }, \ 2041541Srgrimes { "iso", CTLTYPE_NODE }, \ 2051541Srgrimes { "emca", CTLTYPE_NODE }, \ 2061541Srgrimes { "datakit", CTLTYPE_NODE }, \ 2071541Srgrimes { "ccitt", CTLTYPE_NODE }, \ 2081541Srgrimes { "ibm_sna", CTLTYPE_NODE }, \ 2091541Srgrimes { "decnet", CTLTYPE_NODE }, \ 2101541Srgrimes { "dec_dli", CTLTYPE_NODE }, \ 2111541Srgrimes { "lat", CTLTYPE_NODE }, \ 2121541Srgrimes { "hylink", CTLTYPE_NODE }, \ 2131541Srgrimes { "appletalk", CTLTYPE_NODE }, \ 2141541Srgrimes { "route", CTLTYPE_NODE }, \ 2151541Srgrimes { "link_layer", CTLTYPE_NODE }, \ 2161541Srgrimes { "xtp", CTLTYPE_NODE }, \ 2171541Srgrimes { "coip", CTLTYPE_NODE }, \ 2181541Srgrimes { "cnt", CTLTYPE_NODE }, \ 2191541Srgrimes { "rtip", CTLTYPE_NODE }, \ 2201541Srgrimes { "ipx", CTLTYPE_NODE }, \ 2211541Srgrimes { "sip", CTLTYPE_NODE }, \ 2221541Srgrimes { "pip", CTLTYPE_NODE }, \ 22316368Swollman { "isdn", CTLTYPE_NODE }, \ 22416368Swollman { "key", CTLTYPE_NODE }, \ 2251541Srgrimes} 2261541Srgrimes 2271541Srgrimes/* 2281541Srgrimes * PF_ROUTE - Routing table 2291541Srgrimes * 2301541Srgrimes * Three additional levels are defined: 2311541Srgrimes * Fourth: address family, 0 is wildcard 2321541Srgrimes * Fifth: type of info, defined below 2331541Srgrimes * Sixth: flag(s) to mask with for NET_RT_FLAGS 2341541Srgrimes */ 2351541Srgrimes#define NET_RT_DUMP 1 /* dump; may limit to a.f. */ 2361541Srgrimes#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ 2371541Srgrimes#define NET_RT_IFLIST 3 /* survey interface list */ 2381541Srgrimes#define NET_RT_MAXID 4 2391541Srgrimes 2401541Srgrimes#define CTL_NET_RT_NAMES { \ 2411541Srgrimes { 0, 0 }, \ 2421541Srgrimes { "dump", CTLTYPE_STRUCT }, \ 2431541Srgrimes { "flags", CTLTYPE_STRUCT }, \ 2441541Srgrimes { "iflist", CTLTYPE_STRUCT }, \ 2451541Srgrimes} 2461541Srgrimes 2471541Srgrimes/* 2481541Srgrimes * Maximum queue length specifiable by listen. 2491541Srgrimes */ 25013258Sdg#define SOMAXCONN 128 2511541Srgrimes 2521541Srgrimes/* 2531541Srgrimes * Message header for recvmsg and sendmsg calls. 2541541Srgrimes * Used value-result for recvmsg, value only for sendmsg. 2551541Srgrimes */ 2561541Srgrimesstruct msghdr { 2571541Srgrimes caddr_t msg_name; /* optional address */ 2581541Srgrimes u_int msg_namelen; /* size of address */ 2591541Srgrimes struct iovec *msg_iov; /* scatter/gather array */ 2601541Srgrimes u_int msg_iovlen; /* # elements in msg_iov */ 2611541Srgrimes caddr_t msg_control; /* ancillary data, see below */ 2621541Srgrimes u_int msg_controllen; /* ancillary data buffer len */ 2631541Srgrimes int msg_flags; /* flags on received message */ 2641541Srgrimes}; 2651541Srgrimes 2661541Srgrimes#define MSG_OOB 0x1 /* process out-of-band data */ 2671541Srgrimes#define MSG_PEEK 0x2 /* peek at incoming message */ 2681541Srgrimes#define MSG_DONTROUTE 0x4 /* send without using routing tables */ 2691541Srgrimes#define MSG_EOR 0x8 /* data completes record */ 2701541Srgrimes#define MSG_TRUNC 0x10 /* data discarded before delivery */ 2711541Srgrimes#define MSG_CTRUNC 0x20 /* control data lost before delivery */ 2721541Srgrimes#define MSG_WAITALL 0x40 /* wait for full request or error */ 2731541Srgrimes#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ 2746223Swollman#define MSG_EOF 0x100 /* data completes connection */ 2753304Sphk#define MSG_COMPAT 0x8000 /* used in sendit() */ 2761541Srgrimes 2771541Srgrimes/* 2781541Srgrimes * Header for ancillary data objects in msg_control buffer. 2791541Srgrimes * Used for additional information with/about a datagram 2801541Srgrimes * not expressible by flags. The format is a sequence 2811541Srgrimes * of message elements headed by cmsghdr structures. 2821541Srgrimes */ 2831541Srgrimesstruct cmsghdr { 2841541Srgrimes u_int cmsg_len; /* data byte count, including hdr */ 2851541Srgrimes int cmsg_level; /* originating protocol */ 2861541Srgrimes int cmsg_type; /* protocol-specific type */ 2871541Srgrimes/* followed by u_char cmsg_data[]; */ 2881541Srgrimes}; 2891541Srgrimes 2901541Srgrimes/* given pointer to struct cmsghdr, return pointer to data */ 2911541Srgrimes#define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1)) 2921541Srgrimes 2931541Srgrimes/* given pointer to struct cmsghdr, return pointer to next cmsghdr */ 2941541Srgrimes#define CMSG_NXTHDR(mhdr, cmsg) \ 2951541Srgrimes (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \ 2961541Srgrimes (mhdr)->msg_control + (mhdr)->msg_controllen) ? \ 2971541Srgrimes (struct cmsghdr *)NULL : \ 2981541Srgrimes (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len))) 2991541Srgrimes 3001541Srgrimes#define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control) 3011541Srgrimes 3021541Srgrimes/* "Socket"-level control message types: */ 3031541Srgrimes#define SCM_RIGHTS 0x01 /* access rights (array of int) */ 30415701Swollman#define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */ 3051541Srgrimes 3061541Srgrimes/* 3071541Srgrimes * 4.3 compat sockaddr, move to compat file later 3081541Srgrimes */ 3091541Srgrimesstruct osockaddr { 3101541Srgrimes u_short sa_family; /* address family */ 3111541Srgrimes char sa_data[14]; /* up to 14 bytes of direct address */ 3121541Srgrimes}; 3131541Srgrimes 3141541Srgrimes/* 3151541Srgrimes * 4.3-compat message header (move to compat file later). 3161541Srgrimes */ 3171541Srgrimesstruct omsghdr { 3181541Srgrimes caddr_t msg_name; /* optional address */ 3191541Srgrimes int msg_namelen; /* size of address */ 3201541Srgrimes struct iovec *msg_iov; /* scatter/gather array */ 3211541Srgrimes int msg_iovlen; /* # elements in msg_iov */ 3221541Srgrimes caddr_t msg_accrights; /* access rights sent/received */ 3231541Srgrimes int msg_accrightslen; 3241541Srgrimes}; 3251541Srgrimes 3261541Srgrimes#ifndef KERNEL 3271541Srgrimes 3281541Srgrimes#include <sys/cdefs.h> 3291541Srgrimes 3301541Srgrimes__BEGIN_DECLS 3311541Srgrimesint accept __P((int, struct sockaddr *, int *)); 3321541Srgrimesint bind __P((int, const struct sockaddr *, int)); 3331541Srgrimesint connect __P((int, const struct sockaddr *, int)); 3341541Srgrimesint getpeername __P((int, struct sockaddr *, int *)); 3351541Srgrimesint getsockname __P((int, struct sockaddr *, int *)); 3361541Srgrimesint getsockopt __P((int, int, int, void *, int *)); 3371541Srgrimesint listen __P((int, int)); 3381541Srgrimesssize_t recv __P((int, void *, size_t, int)); 3391541Srgrimesssize_t recvfrom __P((int, void *, size_t, int, struct sockaddr *, int *)); 3401541Srgrimesssize_t recvmsg __P((int, struct msghdr *, int)); 3411541Srgrimesssize_t send __P((int, const void *, size_t, int)); 3421541Srgrimesssize_t sendto __P((int, const void *, 3431541Srgrimes size_t, int, const struct sockaddr *, int)); 3441541Srgrimesssize_t sendmsg __P((int, const struct msghdr *, int)); 3451541Srgrimesint setsockopt __P((int, int, int, const void *, int)); 3461541Srgrimesint shutdown __P((int, int)); 3471541Srgrimesint socket __P((int, int, int)); 3481541Srgrimesint socketpair __P((int, int, int, int *)); 3491541Srgrimes__END_DECLS 3501541Srgrimes 3513438Sphk#else /* KERNEL */ 3523438Sphkvoid pfctlinput __P((int, struct sockaddr *)); 3531541Srgrimes#endif /* !KERNEL */ 3541541Srgrimes#endif /* !_SYS_SOCKET_H_ */ 355