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