1 /* 2 * Copyright (c) 1993, 1982198519861988 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)socket.h 8.1 (Berkeley) 06/02/93 8 */ 9 10 #ifndef _SOCKET_H_ 11 #define _SOCKET_H_ 12 13 /* 14 * Definitions related to sockets: types, address families, options. 15 */ 16 17 /* 18 * Types 19 */ 20 #define SOCK_STREAM 1 /* stream socket */ 21 #define SOCK_DGRAM 2 /* datagram socket */ 22 #define SOCK_RAW 3 /* raw-protocol interface */ 23 #define SOCK_RDM 4 /* reliably-delivered message */ 24 #define SOCK_SEQPACKET 5 /* sequenced packet stream */ 25 26 /* 27 * Option flags per-socket. 28 */ 29 #define SO_DEBUG 0x0001 /* turn on debugging info recording */ 30 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 31 #define SO_REUSEADDR 0x0004 /* allow local address reuse */ 32 #define SO_KEEPALIVE 0x0008 /* keep connections alive */ 33 #define SO_DONTROUTE 0x0010 /* just use interface addresses */ 34 #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ 35 #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ 36 #define SO_LINGER 0x0080 /* linger on close if data present */ 37 #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ 38 #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ 39 40 /* 41 * Additional options, not kept in so_options. 42 */ 43 #define SO_SNDBUF 0x1001 /* send buffer size */ 44 #define SO_RCVBUF 0x1002 /* receive buffer size */ 45 #define SO_SNDLOWAT 0x1003 /* send low-water mark */ 46 #define SO_RCVLOWAT 0x1004 /* receive low-water mark */ 47 #define SO_SNDTIMEO 0x1005 /* send timeout */ 48 #define SO_RCVTIMEO 0x1006 /* receive timeout */ 49 #define SO_ERROR 0x1007 /* get error status and clear */ 50 #define SO_TYPE 0x1008 /* get socket type */ 51 52 /* 53 * Structure used for manipulating linger option. 54 */ 55 struct linger { 56 int l_onoff; /* option on/off */ 57 int l_linger; /* linger time */ 58 }; 59 60 /* 61 * Level number for (get/set)sockopt() to apply to socket itself. 62 */ 63 #define SOL_SOCKET 0xffff /* options for socket level */ 64 65 /* 66 * Address families. 67 */ 68 #define AF_UNSPEC 0 /* unspecified */ 69 #define AF_UNIX 1 /* local to host (pipes, portals) */ 70 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 71 #define AF_IMPLINK 3 /* arpanet imp addresses */ 72 #define AF_PUP 4 /* pup protocols: e.g. BSP */ 73 #define AF_CHAOS 5 /* mit CHAOS protocols */ 74 #define AF_NS 6 /* XEROX NS protocols */ 75 #define AF_ISO 7 /* ISO protocols */ 76 #define AF_OSI AF_ISO 77 #define AF_ECMA 8 /* european computer manufacturers */ 78 #define AF_DATAKIT 9 /* datakit protocols */ 79 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 80 #define AF_SNA 11 /* IBM SNA */ 81 #define AF_DECnet 12 /* DECnet */ 82 #define AF_DLI 13 /* DEC Direct data link interface */ 83 #define AF_LAT 14 /* LAT */ 84 #define AF_HYLINK 15 /* NSC Hyperchannel */ 85 #define AF_APPLETALK 16 /* Apple Talk */ 86 #define AF_ROUTE 17 /* Internal Routing Protocol */ 87 #define AF_LINK 18 /* Link layer interface */ 88 #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ 89 #define AF_COIP 20 /* connection-oriented IP, aka ST II */ 90 #define AF_CNT 21 /* Computer Network Technology */ 91 #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ 92 #define AF_IPX 23 /* Novell Internet Protocol */ 93 #define AF_SIP 24 /* Simple Internet Protocol */ 94 #define pseudo_AF_PIP 25 /* Help Identify PIP packets */ 95 96 #define AF_MAX 26 97 98 /* 99 * Structure used by kernel to store most 100 * addresses. 101 */ 102 struct sockaddr { 103 u_char sa_len; /* total length */ 104 u_char sa_family; /* address family */ 105 char sa_data[14]; /* actually longer; address value */ 106 }; 107 108 /* 109 * Structure used by kernel to pass protocol 110 * information in raw sockets. 111 */ 112 struct sockproto { 113 u_short sp_family; /* address family */ 114 u_short sp_protocol; /* protocol */ 115 }; 116 117 /* 118 * Protocol families, same as address families for now. 119 */ 120 #define PF_UNSPEC AF_UNSPEC 121 #define PF_UNIX AF_UNIX 122 #define PF_INET AF_INET 123 #define PF_IMPLINK AF_IMPLINK 124 #define PF_PUP AF_PUP 125 #define PF_CHAOS AF_CHAOS 126 #define PF_NS AF_NS 127 #define PF_ISO AF_ISO 128 #define PF_OSI AF_ISO 129 #define PF_ECMA AF_ECMA 130 #define PF_DATAKIT AF_DATAKIT 131 #define PF_CCITT AF_CCITT 132 #define PF_SNA AF_SNA 133 #define PF_DECnet AF_DECnet 134 #define PF_DLI AF_DLI 135 #define PF_LAT AF_LAT 136 #define PF_HYLINK AF_HYLINK 137 #define PF_APPLETALK AF_APPLETALK 138 #define PF_ROUTE AF_ROUTE 139 #define PF_LINK AF_LINK 140 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ 141 #define PF_COIP AF_COIP 142 #define PF_CNT AF_CNT 143 #define PF_SIP AF_SIP 144 #define PF_IPX AF_IPX /* same format as AF_NS */ 145 #define PF_RTIP pseudo_AF_FTIP /* same format as AF_INET */ 146 #define PF_PIP pseudo_AF_PIP 147 148 #define PF_MAX AF_MAX 149 150 /* 151 * Definitions for network related sysctl, CTL_NET. 152 * 153 * Second level is protocol family. 154 * Third level is protocol number. 155 * 156 * Further levels are defined by the individual families below. 157 */ 158 #define NET_MAXID AF_MAX 159 160 #define CTL_NET_NAMES { \ 161 { 0, 0 }, \ 162 { "unix", CTLTYPE_NODE }, \ 163 { "inet", CTLTYPE_NODE }, \ 164 { "implink", CTLTYPE_NODE }, \ 165 { "pup", CTLTYPE_NODE }, \ 166 { "chaos", CTLTYPE_NODE }, \ 167 { "xerox_ns", CTLTYPE_NODE }, \ 168 { "iso", CTLTYPE_NODE }, \ 169 { "emca", CTLTYPE_NODE }, \ 170 { "datakit", CTLTYPE_NODE }, \ 171 { "ccitt", CTLTYPE_NODE }, \ 172 { "ibm_sna", CTLTYPE_NODE }, \ 173 { "decnet", CTLTYPE_NODE }, \ 174 { "dec_dli", CTLTYPE_NODE }, \ 175 { "lat", CTLTYPE_NODE }, \ 176 { "hylink", CTLTYPE_NODE }, \ 177 { "appletalk", CTLTYPE_NODE }, \ 178 { "route", CTLTYPE_NODE }, \ 179 { "link_layer", CTLTYPE_NODE }, \ 180 { "xtp", CTLTYPE_NODE }, \ 181 { "coip", CTLTYPE_NODE }, \ 182 { "cnt", CTLTYPE_NODE }, \ 183 { "rtip", CTLTYPE_NODE }, \ 184 { "ipx", CTLTYPE_NODE }, \ 185 { "sip", CTLTYPE_NODE }, \ 186 { "pip", CTLTYPE_NODE }, \ 187 } 188 189 /* 190 * PF_ROUTE - Routing table 191 * 192 * Three additional levels are defined: 193 * Fourth: address family, 0 is wildcard 194 * Fifth: type of info, defined below 195 * Sixth: flag(s) to mask with for NET_RT_FLAGS 196 */ 197 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */ 198 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ 199 #define NET_RT_IFLIST 3 /* survey interface list */ 200 #define NET_RT_MAXID 4 201 202 #define CTL_NET_RT_NAMES { \ 203 { 0, 0 }, \ 204 { "dump", CTLTYPE_STRUCT }, \ 205 { "flags", CTLTYPE_STRUCT }, \ 206 { "iflist", CTLTYPE_STRUCT }, \ 207 } 208 209 /* 210 * Maximum queue length specifiable by listen. 211 */ 212 #define SOMAXCONN 5 213 214 /* 215 * Message header for recvmsg and sendmsg calls. 216 * Used value-result for recvmsg, value only for sendmsg. 217 */ 218 struct msghdr { 219 caddr_t msg_name; /* optional address */ 220 u_int msg_namelen; /* size of address */ 221 struct iovec *msg_iov; /* scatter/gather array */ 222 u_int msg_iovlen; /* # elements in msg_iov */ 223 caddr_t msg_control; /* ancillary data, see below */ 224 u_int msg_controllen; /* ancillary data buffer len */ 225 int msg_flags; /* flags on received message */ 226 }; 227 228 #define MSG_OOB 0x1 /* process out-of-band data */ 229 #define MSG_PEEK 0x2 /* peek at incoming message */ 230 #define MSG_DONTROUTE 0x4 /* send without using routing tables */ 231 #define MSG_EOR 0x8 /* data completes record */ 232 #define MSG_TRUNC 0x10 /* data discarded before delivery */ 233 #define MSG_CTRUNC 0x20 /* control data lost before delivery */ 234 #define MSG_WAITALL 0x40 /* wait for full request or error */ 235 #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ 236 237 /* 238 * Header for ancillary data objects in msg_control buffer. 239 * Used for additional information with/about a datagram 240 * not expressible by flags. The format is a sequence 241 * of message elements headed by cmsghdr structures. 242 */ 243 struct cmsghdr { 244 u_int cmsg_len; /* data byte count, including hdr */ 245 int cmsg_level; /* originating protocol */ 246 int cmsg_type; /* protocol-specific type */ 247 /* followed by u_char cmsg_data[]; */ 248 }; 249 250 /* given pointer to struct cmsghdr, return pointer to data */ 251 #define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1)) 252 253 /* given pointer to struct cmsghdr, return pointer to next cmsghdr */ 254 #define CMSG_NXTHDR(mhdr, cmsg) \ 255 (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \ 256 (mhdr)->msg_control + (mhdr)->msg_controllen) ? \ 257 (struct cmsghdr *)NULL : \ 258 (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len))) 259 260 #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control) 261 262 /* "Socket"-level control message types: */ 263 #define SCM_RIGHTS 0x01 /* access rights (array of int) */ 264 265 /* 266 * 4.3 compat sockaddr, move to compat file later 267 */ 268 struct osockaddr { 269 u_short sa_family; /* address family */ 270 char sa_data[14]; /* up to 14 bytes of direct address */ 271 }; 272 273 /* 274 * 4.3-compat message header (move to compat file later). 275 */ 276 struct omsghdr { 277 caddr_t msg_name; /* optional address */ 278 int msg_namelen; /* size of address */ 279 struct iovec *msg_iov; /* scatter/gather array */ 280 int msg_iovlen; /* # elements in msg_iov */ 281 caddr_t msg_accrights; /* access rights sent/received */ 282 int msg_accrightslen; 283 }; 284 285 #ifndef KERNEL 286 287 #include <sys/cdefs.h> 288 289 __BEGIN_DECLS 290 int accept __P((int, struct sockaddr *, int *)); 291 int bind __P((int, const struct sockaddr *, int)); 292 int connect __P((int, const struct sockaddr *, int)); 293 int getpeername __P((int, struct sockaddr *, int *)); 294 int getsockname __P((int, struct sockaddr *, int *)); 295 int getsockopt __P((int, int, int, void *, int *)); 296 int listen __P((int, int)); 297 int recv __P((int, void *, int, int)); 298 int recvfrom __P((int, void *, int, int, 299 struct sockaddr *, int *)); 300 int recvmsg __P((int, struct msghdr *, int)); 301 int send __P((int, const void *, int, int)); 302 int sendto __P((int, const void *, int, int, const struct sockaddr *, int)); 303 int sendmsg __P((int, const struct msghdr *, int)); 304 int setsockopt __P((int, int, int, const void *, int)); 305 int shutdown __P((int, int)); 306 int socket __P((int, int, int)); 307 int socketpair __P((int, int, int, int *)); 308 __END_DECLS 309 310 #endif /* !KERNEL */ 311 #endif /* !_SOCKET_H_ */ 312