socket.h revision 16480
185909Simp/* 285909Simp * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 3122116Sbde * The Regents of the University of California. All rights reserved. 4122116Sbde * 5122116Sbde * Redistribution and use in source and binary forms, with or without 6180012Sru * modification, are permitted provided that the following conditions 7240468Sbrooks * are met: 8160440Sobrien * 1. Redistributions of source code must retain the above copyright 9210151Simp * notice, this list of conditions and the following disclaimer. 10239272Sgonzo * 2. Redistributions in binary form must reproduce the above copyright 11210151Simp * notice, this list of conditions and the following disclaimer in the 1285909Simp * documentation and/or other materials provided with the distribution. 1385909Simp * 3. All advertising materials mentioning features or use of this software 1485909Simp * must display the following acknowledgement: 1585909Simp * This product includes software developed by the University of 16175888Simp * California, Berkeley and its contributors. 17175888Simp * 4. Neither the name of the University nor the names of its contributors 1885909Simp * may be used to endorse or promote products derived from this software 19218538Simp * without specific prior written permission. 2085909Simp * 2191512Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22240451Snp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23116341Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2485909Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2585909Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2685909Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2785909Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28220863Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29140606Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30187103Sgnn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31220863Sdim * SUCH DAMAGE. 32224882Snwhitehorn * 33224882Snwhitehorn * @(#)socket.h 8.4 (Berkeley) 2/21/94 34224882Snwhitehorn * $Id: socket.h,v 1.12 1996/06/14 17:22:18 wollman Exp $ 35140606Sobrien */ 36220863Sdim 37224882Snwhitehorn#ifndef _SYS_SOCKET_H_ 38220863Sdim#define _SYS_SOCKET_H_ 39240468Sbrooks 40127204Sobrien/* 41220863Sdim * Definitions related to sockets: types, address families, options. 42228868Sdim */ 43228868Sdim 44228868Sdim/* 45140606Sobrien * Types 46220863Sdim */ 47220863Sdim#define SOCK_STREAM 1 /* stream socket */ 48124834Sru#define SOCK_DGRAM 2 /* datagram socket */ 49124834Sru#define SOCK_RAW 3 /* raw-protocol interface */ 5085909Simp#define SOCK_RDM 4 /* reliably-delivered message */ 5185909Simp#define SOCK_SEQPACKET 5 /* sequenced packet stream */ 5285909Simp 53160043Sobrien/* 54126890Strhodes * Option flags per-socket. 5585909Simp */ 56192901Sthompsa#define SO_DEBUG 0x0001 /* turn on debugging info recording */ 57126890Strhodes#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 58151605Sobrien#define SO_REUSEADDR 0x0004 /* allow local address reuse */ 59151605Sobrien#define SO_KEEPALIVE 0x0008 /* keep connections alive */ 60130416Smlaier#define SO_DONTROUTE 0x0010 /* just use interface addresses */ 61130416Smlaier#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ 62149978Sobrien#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ 63149978Sobrien#define SO_LINGER 0x0080 /* linger on close if data present */ 64149978Sobrien#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ 65149978Sobrien#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ 66149978Sobrien#define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */ 67185522Ssam 68250173Sadrian/* 69149978Sobrien * Additional options, not kept in so_options. 70149978Sobrien */ 71149978Sobrien#define SO_SNDBUF 0x1001 /* send buffer size */ 72149978Sobrien#define SO_RCVBUF 0x1002 /* receive buffer size */ 73229353Sgjb#define SO_SNDLOWAT 0x1003 /* send low-water mark */ 74149978Sobrien#define SO_RCVLOWAT 0x1004 /* receive low-water mark */ 75149978Sobrien#define SO_SNDTIMEO 0x1005 /* send timeout */ 76218792Snp#define SO_RCVTIMEO 0x1006 /* receive timeout */ 77218792Snp#define SO_ERROR 0x1007 /* get error status and clear */ 78183292Skmacy#define SO_TYPE 0x1008 /* get socket type */ 79149978Sobrien#define SO_PRIVSTATE 0x1009 /* get/deny privileged state */ 80149978Sobrien 81160043Sobrien/* 82150966Sglebius * Structure used for manipulating linger option. 83240468Sbrooks */ 84124834Srustruct linger { 85210311Sjmallett int l_onoff; /* option on/off */ 86132766Skan int l_linger; /* linger time */ 87132766Skan}; 88210311Sjmallett 89210311Sjmallett/* 90215988Sjmallett * Level number for (get/set)sockopt() to apply to socket itself. 91210311Sjmallett */ 92215988Sjmallett#define SOL_SOCKET 0xffff /* options for socket level */ 93210311Sjmallett 94210394Srpaulo/* 95171239Speter * Address families. 9685909Simp */ 9785909Simp#define AF_UNSPEC 0 /* unspecified */ 9885909Simp#define AF_LOCAL 1 /* local to host (pipes, portals) */ 9985909Simp#define AF_UNIX AF_LOCAL /* backward compatibility */ 100240468Sbrooks#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 101232263Sdim#define AF_IMPLINK 3 /* arpanet imp addresses */ 102260495Sdim#define AF_PUP 4 /* pup protocols: e.g. BSP */ 103260495Sdim#define AF_CHAOS 5 /* mit CHAOS protocols */ 104232263Sdim#define AF_NS 6 /* XEROX NS protocols */ 105232263Sdim#define AF_ISO 7 /* ISO protocols */ 10699923Sbde#define AF_OSI AF_ISO 107242715Sdim#define AF_ECMA 8 /* European computer manufacturers */ 108242715Sdim#define AF_DATAKIT 9 /* datakit protocols */ 109242715Sdim#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 110242715Sdim#define AF_SNA 11 /* IBM SNA */ 11199932Sbde#define AF_DECnet 12 /* DECnet */ 11299932Sbde#define AF_DLI 13 /* DEC Direct data link interface */ 113242717Sdim#define AF_LAT 14 /* LAT */ 114242717Sdim#define AF_HYLINK 15 /* NSC Hyperchannel */ 115242717Sdim#define AF_APPLETALK 16 /* Apple Talk */ 116242717Sdim#define AF_ROUTE 17 /* Internal Routing Protocol */ 11799932Sbde#define AF_LINK 18 /* Link layer interface */ 118242717Sdim#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ 11999923Sbde#define AF_COIP 20 /* connection-oriented IP, aka ST II */ 12099932Sbde#define AF_CNT 21 /* Computer Network Technology */ 12185909Simp#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ 12291002Speter#define AF_IPX 23 /* Novell Internet Protocol */ 12385909Simp#define AF_SIP 24 /* Simple Internet Protocol */ 12485909Simp#define pseudo_AF_PIP 25 /* Help Identify PIP packets */ 12585909Simp#define AF_ISDN 26 /* Integrated Services Digital Network*/ 12685909Simp#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ 127116341Smarkm#define pseudo_AF_KEY 27 /* Internal key-management function */ 128116341Smarkm 129116341Smarkm#define AF_MAX 28 13091002Speter 13191002Speter/* 13291002Speter * Structure used by kernel to store most 133105489Smux * addresses. 13485909Simp */ 135105462Smuxstruct sockaddr { 136105462Smux u_char sa_len; /* total length */ 13785909Simp u_char sa_family; /* address family */ 138239956Sjhb char sa_data[14]; /* actually longer; address value */ 139239957Sjhb}; 140239957Sjhb 141239955Sjhb/* 142233578Speter * Structure used by kernel to pass protocol 143233578Speter * information in raw sockets. 144253996Savg */ 145233578Speterstruct sockproto { 146233578Speter u_short sp_family; /* address family */ 147233578Speter u_short sp_protocol; /* protocol */ 148233578Speter}; 149228158Sfjoe 150228140Sfjoe/* 151228158Sfjoe * Protocol families, same as address families for now. 152228158Sfjoe */ 153228124Sfjoe#define PF_UNSPEC AF_UNSPEC 154228158Sfjoe#define PF_LOCAL AF_LOCAL 155228124Sfjoe#define PF_UNIX PF_LOCAL /* backward compatibility */ 156179226Sjb#define PF_INET AF_INET 157116341Smarkm#define PF_IMPLINK AF_IMPLINK 158116341Smarkm#define PF_PUP AF_PUP 159219819Sjeff#define PF_CHAOS AF_CHAOS 160219819Sjeff#define PF_NS AF_NS 161219819Sjeff#define PF_ISO AF_ISO 162260495Sdim#define PF_OSI AF_ISO 163219819Sjeff#define PF_ECMA AF_ECMA 164219819Sjeff#define PF_DATAKIT AF_DATAKIT 165219819Sjeff#define PF_CCITT AF_CCITT 166219819Sjeff#define PF_SNA AF_SNA 167131210Simp#define PF_DECnet AF_DECnet 168144293Sphk#define PF_DLI AF_DLI 16985909Simp#define PF_LAT AF_LAT 170111684Sru#define PF_HYLINK AF_HYLINK 171111684Sru#define PF_APPLETALK AF_APPLETALK 172111684Sru#define PF_ROUTE AF_ROUTE 173243664Smarcel#define PF_LINK AF_LINK 17489180Smsmith#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ 17585909Simp#define PF_COIP AF_COIP 17685909Simp#define PF_CNT AF_CNT 177123966Sbde#define PF_SIP AF_SIP 178175888Simp#define PF_IPX AF_IPX /* same format as AF_NS */ 17985909Simp#define PF_RTIP pseudo_AF_FTIP /* same format as AF_INET */ 18088893Simp#define PF_PIP pseudo_AF_PIP 18188893Simp#define PF_ISDN AF_ISDN 18288893Simp#define PF_KEY pseudo_AF_KEY 183221265Sbz 184210151Simp#define PF_MAX AF_MAX 18590789Sphk 18690789Sphk/* 18790789Sphk * Definitions for network related sysctl, CTL_NET. 18888893Simp * 18988893Simp * Second level is protocol family. 19088893Simp * Third level is protocol number. 191216746Scperciva * 192216746Scperciva * Further levels are defined by the individual families below. 193216746Scperciva */ 19488893Simp#define NET_MAXID AF_MAX 195125772Sru 19688893Simp#define CTL_NET_NAMES { \ 197240402Sobrien { 0, 0 }, \ 198240402Sobrien { "unix", CTLTYPE_NODE }, \ 199240402Sobrien { "inet", CTLTYPE_NODE }, \ 200240402Sobrien { "implink", CTLTYPE_NODE }, \ 201240402Sobrien { "pup", CTLTYPE_NODE }, \ 202 { "chaos", CTLTYPE_NODE }, \ 203 { "xerox_ns", CTLTYPE_NODE }, \ 204 { "iso", CTLTYPE_NODE }, \ 205 { "emca", CTLTYPE_NODE }, \ 206 { "datakit", CTLTYPE_NODE }, \ 207 { "ccitt", CTLTYPE_NODE }, \ 208 { "ibm_sna", CTLTYPE_NODE }, \ 209 { "decnet", CTLTYPE_NODE }, \ 210 { "dec_dli", CTLTYPE_NODE }, \ 211 { "lat", CTLTYPE_NODE }, \ 212 { "hylink", CTLTYPE_NODE }, \ 213 { "appletalk", CTLTYPE_NODE }, \ 214 { "route", CTLTYPE_NODE }, \ 215 { "link_layer", CTLTYPE_NODE }, \ 216 { "xtp", CTLTYPE_NODE }, \ 217 { "coip", CTLTYPE_NODE }, \ 218 { "cnt", CTLTYPE_NODE }, \ 219 { "rtip", CTLTYPE_NODE }, \ 220 { "ipx", CTLTYPE_NODE }, \ 221 { "sip", CTLTYPE_NODE }, \ 222 { "pip", CTLTYPE_NODE }, \ 223 { "isdn", CTLTYPE_NODE }, \ 224 { "key", CTLTYPE_NODE }, \ 225} 226 227/* 228 * PF_ROUTE - Routing table 229 * 230 * Three additional levels are defined: 231 * Fourth: address family, 0 is wildcard 232 * Fifth: type of info, defined below 233 * Sixth: flag(s) to mask with for NET_RT_FLAGS 234 */ 235#define NET_RT_DUMP 1 /* dump; may limit to a.f. */ 236#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ 237#define NET_RT_IFLIST 3 /* survey interface list */ 238#define NET_RT_MAXID 4 239 240#define CTL_NET_RT_NAMES { \ 241 { 0, 0 }, \ 242 { "dump", CTLTYPE_STRUCT }, \ 243 { "flags", CTLTYPE_STRUCT }, \ 244 { "iflist", CTLTYPE_STRUCT }, \ 245} 246 247/* 248 * Maximum queue length specifiable by listen. 249 */ 250#define SOMAXCONN 128 251 252/* 253 * Message header for recvmsg and sendmsg calls. 254 * Used value-result for recvmsg, value only for sendmsg. 255 */ 256struct msghdr { 257 caddr_t msg_name; /* optional address */ 258 u_int msg_namelen; /* size of address */ 259 struct iovec *msg_iov; /* scatter/gather array */ 260 u_int msg_iovlen; /* # elements in msg_iov */ 261 caddr_t msg_control; /* ancillary data, see below */ 262 u_int msg_controllen; /* ancillary data buffer len */ 263 int msg_flags; /* flags on received message */ 264}; 265 266#define MSG_OOB 0x1 /* process out-of-band data */ 267#define MSG_PEEK 0x2 /* peek at incoming message */ 268#define MSG_DONTROUTE 0x4 /* send without using routing tables */ 269#define MSG_EOR 0x8 /* data completes record */ 270#define MSG_TRUNC 0x10 /* data discarded before delivery */ 271#define MSG_CTRUNC 0x20 /* control data lost before delivery */ 272#define MSG_WAITALL 0x40 /* wait for full request or error */ 273#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ 274#define MSG_EOF 0x100 /* data completes connection */ 275#define MSG_COMPAT 0x8000 /* used in sendit() */ 276 277/* 278 * Header for ancillary data objects in msg_control buffer. 279 * Used for additional information with/about a datagram 280 * not expressible by flags. The format is a sequence 281 * of message elements headed by cmsghdr structures. 282 */ 283struct cmsghdr { 284 u_int cmsg_len; /* data byte count, including hdr */ 285 int cmsg_level; /* originating protocol */ 286 int cmsg_type; /* protocol-specific type */ 287/* followed by u_char cmsg_data[]; */ 288}; 289 290/* given pointer to struct cmsghdr, return pointer to data */ 291#define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1)) 292 293/* given pointer to struct cmsghdr, return pointer to next cmsghdr */ 294#define CMSG_NXTHDR(mhdr, cmsg) \ 295 (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \ 296 (mhdr)->msg_control + (mhdr)->msg_controllen) ? \ 297 (struct cmsghdr *)NULL : \ 298 (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len))) 299 300#define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control) 301 302/* "Socket"-level control message types: */ 303#define SCM_RIGHTS 0x01 /* access rights (array of int) */ 304#define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */ 305 306/* 307 * 4.3 compat sockaddr, move to compat file later 308 */ 309struct osockaddr { 310 u_short sa_family; /* address family */ 311 char sa_data[14]; /* up to 14 bytes of direct address */ 312}; 313 314/* 315 * 4.3-compat message header (move to compat file later). 316 */ 317struct omsghdr { 318 caddr_t msg_name; /* optional address */ 319 int msg_namelen; /* size of address */ 320 struct iovec *msg_iov; /* scatter/gather array */ 321 int msg_iovlen; /* # elements in msg_iov */ 322 caddr_t msg_accrights; /* access rights sent/received */ 323 int msg_accrightslen; 324}; 325 326#ifndef KERNEL 327 328#include <sys/cdefs.h> 329 330__BEGIN_DECLS 331int accept __P((int, struct sockaddr *, int *)); 332int bind __P((int, const struct sockaddr *, int)); 333int connect __P((int, const struct sockaddr *, int)); 334int getpeername __P((int, struct sockaddr *, int *)); 335int getsockname __P((int, struct sockaddr *, int *)); 336int getsockopt __P((int, int, int, void *, int *)); 337int listen __P((int, int)); 338ssize_t recv __P((int, void *, size_t, int)); 339ssize_t recvfrom __P((int, void *, size_t, int, struct sockaddr *, int *)); 340ssize_t recvmsg __P((int, struct msghdr *, int)); 341ssize_t send __P((int, const void *, size_t, int)); 342ssize_t sendto __P((int, const void *, 343 size_t, int, const struct sockaddr *, int)); 344ssize_t sendmsg __P((int, const struct msghdr *, int)); 345int setsockopt __P((int, int, int, const void *, int)); 346int shutdown __P((int, int)); 347int socket __P((int, int, int)); 348int socketpair __P((int, int, int, int *)); 349__END_DECLS 350 351#else /* KERNEL */ 352void pfctlinput __P((int, struct sockaddr *)); 353#endif /* !KERNEL */ 354#endif /* !_SYS_SOCKET_H_ */ 355