1 /* 2 * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)socket.h 8.6 (Berkeley) 05/03/95 8 */ 9 10 #ifndef _SYS_SOCKET_H_ 11 #define _SYS_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 in seconds */ 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_LOCAL 1 /* local to host (pipes, portals) */ 70 #define AF_UNIX AF_LOCAL /* backward compatibility */ 71 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 72 #define AF_IMPLINK 3 /* arpanet imp addresses */ 73 #define AF_PUP 4 /* pup protocols: e.g. BSP */ 74 #define AF_CHAOS 5 /* mit CHAOS protocols */ 75 #define AF_NS 6 /* XEROX NS protocols */ 76 #define AF_ISO 7 /* ISO protocols */ 77 #define AF_OSI AF_ISO 78 #define AF_ECMA 8 /* european computer manufacturers */ 79 #define AF_DATAKIT 9 /* datakit protocols */ 80 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 81 #define AF_SNA 11 /* IBM SNA */ 82 #define AF_DECnet 12 /* DECnet */ 83 #define AF_DLI 13 /* DEC Direct data link interface */ 84 #define AF_LAT 14 /* LAT */ 85 #define AF_HYLINK 15 /* NSC Hyperchannel */ 86 #define AF_APPLETALK 16 /* Apple Talk */ 87 #define AF_ROUTE 17 /* Internal Routing Protocol */ 88 #define AF_LINK 18 /* Link layer interface */ 89 #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ 90 #define AF_COIP 20 /* connection-oriented IP, aka ST II */ 91 #define AF_CNT 21 /* Computer Network Technology */ 92 #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ 93 #define AF_IPX 23 /* Novell Internet Protocol */ 94 #define AF_SIP 24 /* Simple Internet Protocol */ 95 #define pseudo_AF_PIP 25 /* Help Identify PIP packets */ 96 97 #define AF_MAX 26 98 99 /* 100 * Structure used by kernel to store most 101 * addresses. 102 */ 103 struct sockaddr { 104 u_char sa_len; /* total length */ 105 u_char sa_family; /* address family */ 106 char sa_data[14]; /* actually longer; address value */ 107 }; 108 109 /* 110 * Structure used by kernel to pass protocol 111 * information in raw sockets. 112 */ 113 struct sockproto { 114 u_short sp_family; /* address family */ 115 u_short sp_protocol; /* protocol */ 116 }; 117 118 /* 119 * Protocol families, same as address families for now. 120 */ 121 #define PF_UNSPEC AF_UNSPEC 122 #define PF_LOCAL AF_LOCAL 123 #define PF_UNIX PF_LOCAL /* backward compatibility */ 124 #define PF_INET AF_INET 125 #define PF_IMPLINK AF_IMPLINK 126 #define PF_PUP AF_PUP 127 #define PF_CHAOS AF_CHAOS 128 #define PF_NS AF_NS 129 #define PF_ISO AF_ISO 130 #define PF_OSI AF_ISO 131 #define PF_ECMA AF_ECMA 132 #define PF_DATAKIT AF_DATAKIT 133 #define PF_CCITT AF_CCITT 134 #define PF_SNA AF_SNA 135 #define PF_DECnet AF_DECnet 136 #define PF_DLI AF_DLI 137 #define PF_LAT AF_LAT 138 #define PF_HYLINK AF_HYLINK 139 #define PF_APPLETALK AF_APPLETALK 140 #define PF_ROUTE AF_ROUTE 141 #define PF_LINK AF_LINK 142 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ 143 #define PF_COIP AF_COIP 144 #define PF_CNT AF_CNT 145 #define PF_SIP AF_SIP 146 #define PF_IPX AF_IPX /* same format as AF_NS */ 147 #define PF_RTIP pseudo_AF_FTIP /* same format as AF_INET */ 148 #define PF_PIP pseudo_AF_PIP 149 150 #define PF_MAX AF_MAX 151 152 /* 153 * Definitions for network related sysctl, CTL_NET. 154 * 155 * Second level is protocol family. 156 * Third level is protocol number. 157 * 158 * Further levels are defined by the individual families below. 159 */ 160 #define NET_MAXID AF_MAX 161 162 #define CTL_NET_NAMES { \ 163 { 0, 0 }, \ 164 { "local", CTLTYPE_NODE }, \ 165 { "inet", CTLTYPE_NODE }, \ 166 { "implink", CTLTYPE_NODE }, \ 167 { "pup", CTLTYPE_NODE }, \ 168 { "chaos", CTLTYPE_NODE }, \ 169 { "xerox_ns", CTLTYPE_NODE }, \ 170 { "iso", CTLTYPE_NODE }, \ 171 { "emca", CTLTYPE_NODE }, \ 172 { "datakit", CTLTYPE_NODE }, \ 173 { "ccitt", CTLTYPE_NODE }, \ 174 { "ibm_sna", CTLTYPE_NODE }, \ 175 { "decnet", CTLTYPE_NODE }, \ 176 { "dec_dli", CTLTYPE_NODE }, \ 177 { "lat", CTLTYPE_NODE }, \ 178 { "hylink", CTLTYPE_NODE }, \ 179 { "appletalk", CTLTYPE_NODE }, \ 180 { "route", CTLTYPE_NODE }, \ 181 { "link_layer", CTLTYPE_NODE }, \ 182 { "xtp", CTLTYPE_NODE }, \ 183 { "coip", CTLTYPE_NODE }, \ 184 { "cnt", CTLTYPE_NODE }, \ 185 { "rtip", CTLTYPE_NODE }, \ 186 { "ipx", CTLTYPE_NODE }, \ 187 { "sip", CTLTYPE_NODE }, \ 188 { "pip", CTLTYPE_NODE }, \ 189 } 190 191 /* 192 * PF_ROUTE - Routing table 193 * 194 * Three additional levels are defined: 195 * Fourth: address family, 0 is wildcard 196 * Fifth: type of info, defined below 197 * Sixth: flag(s) to mask with for NET_RT_FLAGS 198 */ 199 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */ 200 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ 201 #define NET_RT_IFLIST 3 /* survey interface list */ 202 #define NET_RT_MAXID 4 203 204 #define CTL_NET_RT_NAMES { \ 205 { 0, 0 }, \ 206 { "dump", CTLTYPE_STRUCT }, \ 207 { "flags", CTLTYPE_STRUCT }, \ 208 { "iflist", CTLTYPE_STRUCT }, \ 209 } 210 211 /* 212 * Maximum queue length specifiable by listen. 213 */ 214 #define SOMAXCONN 5 215 216 /* 217 * Message header for recvmsg and sendmsg calls. 218 * Used value-result for recvmsg, value only for sendmsg. 219 */ 220 struct msghdr { 221 caddr_t msg_name; /* optional address */ 222 u_int msg_namelen; /* size of address */ 223 struct iovec *msg_iov; /* scatter/gather array */ 224 u_int msg_iovlen; /* # elements in msg_iov */ 225 caddr_t msg_control; /* ancillary data, see below */ 226 u_int msg_controllen; /* ancillary data buffer len */ 227 int msg_flags; /* flags on received message */ 228 }; 229 230 #define MSG_OOB 0x1 /* process out-of-band data */ 231 #define MSG_PEEK 0x2 /* peek at incoming message */ 232 #define MSG_DONTROUTE 0x4 /* send without using routing tables */ 233 #define MSG_EOR 0x8 /* data completes record */ 234 #define MSG_TRUNC 0x10 /* data discarded before delivery */ 235 #define MSG_CTRUNC 0x20 /* control data lost before delivery */ 236 #define MSG_WAITALL 0x40 /* wait for full request or error */ 237 #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ 238 239 /* 240 * Header for ancillary data objects in msg_control buffer. 241 * Used for additional information with/about a datagram 242 * not expressible by flags. The format is a sequence 243 * of message elements headed by cmsghdr structures. 244 */ 245 struct cmsghdr { 246 u_int cmsg_len; /* data byte count, including hdr */ 247 int cmsg_level; /* originating protocol */ 248 int cmsg_type; /* protocol-specific type */ 249 /* followed by u_char cmsg_data[]; */ 250 }; 251 252 /* given pointer to struct cmsghdr, return pointer to data */ 253 #define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1)) 254 255 /* given pointer to struct cmsghdr, return pointer to next cmsghdr */ 256 #define CMSG_NXTHDR(mhdr, cmsg) \ 257 (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \ 258 (mhdr)->msg_control + (mhdr)->msg_controllen) ? \ 259 (struct cmsghdr *)NULL : \ 260 (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len))) 261 262 #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control) 263 264 /* "Socket"-level control message types: */ 265 #define SCM_RIGHTS 0x01 /* access rights (array of int) */ 266 267 /* 268 * 4.3 compat sockaddr, move to compat file later 269 */ 270 struct osockaddr { 271 u_short sa_family; /* address family */ 272 char sa_data[14]; /* up to 14 bytes of direct address */ 273 }; 274 275 /* 276 * 4.3-compat message header (move to compat file later). 277 */ 278 struct omsghdr { 279 caddr_t msg_name; /* optional address */ 280 int msg_namelen; /* size of address */ 281 struct iovec *msg_iov; /* scatter/gather array */ 282 int msg_iovlen; /* # elements in msg_iov */ 283 caddr_t msg_accrights; /* access rights sent/received */ 284 int msg_accrightslen; 285 }; 286 287 #ifndef KERNEL 288 289 #include <sys/cdefs.h> 290 291 __BEGIN_DECLS 292 int accept __P((int, struct sockaddr *, int *)); 293 int bind __P((int, const struct sockaddr *, int)); 294 int connect __P((int, const struct sockaddr *, int)); 295 int getpeername __P((int, struct sockaddr *, int *)); 296 int getsockname __P((int, struct sockaddr *, int *)); 297 int getsockopt __P((int, int, int, void *, int *)); 298 int listen __P((int, int)); 299 ssize_t recv __P((int, void *, size_t, int)); 300 ssize_t recvfrom __P((int, void *, size_t, int, struct sockaddr *, int *)); 301 ssize_t recvmsg __P((int, struct msghdr *, int)); 302 ssize_t send __P((int, const void *, size_t, int)); 303 ssize_t sendto __P((int, const void *, 304 size_t, int, const struct sockaddr *, int)); 305 ssize_t sendmsg __P((int, const struct msghdr *, int)); 306 int setsockopt __P((int, int, int, const void *, int)); 307 int shutdown __P((int, int)); 308 int socket __P((int, int, int)); 309 int socketpair __P((int, int, int, int *)); 310 __END_DECLS 311 312 #endif /* !KERNEL */ 313 #endif /* !_SYS_SOCKET_H_ */ 314