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.14 (Berkeley) 09/05/91 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 36 /* 37 * Additional options, not kept in so_options. 38 */ 39 #define SO_SNDBUF 0x1001 /* send buffer size */ 40 #define SO_RCVBUF 0x1002 /* receive buffer size */ 41 #define SO_SNDLOWAT 0x1003 /* send low-water mark */ 42 #define SO_RCVLOWAT 0x1004 /* receive low-water mark */ 43 #define SO_SNDTIMEO 0x1005 /* send timeout */ 44 #define SO_RCVTIMEO 0x1006 /* receive timeout */ 45 #define SO_ERROR 0x1007 /* get error status and clear */ 46 #define SO_TYPE 0x1008 /* get socket type */ 47 48 /* 49 * Structure used for manipulating linger option. 50 */ 51 struct linger { 52 int l_onoff; /* option on/off */ 53 int l_linger; /* linger time */ 54 }; 55 56 /* 57 * Level number for (get/set)sockopt() to apply to socket itself. 58 */ 59 #define SOL_SOCKET 0xffff /* options for socket level */ 60 61 /* 62 * Address families. 63 */ 64 #define AF_UNSPEC 0 /* unspecified */ 65 #define AF_UNIX 1 /* local to host (pipes, portals) */ 66 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 67 #define AF_IMPLINK 3 /* arpanet imp addresses */ 68 #define AF_PUP 4 /* pup protocols: e.g. BSP */ 69 #define AF_CHAOS 5 /* mit CHAOS protocols */ 70 #define AF_NS 6 /* XEROX NS protocols */ 71 #define AF_ISO 7 /* ISO protocols */ 72 #define AF_OSI AF_ISO 73 #define AF_ECMA 8 /* european computer manufacturers */ 74 #define AF_DATAKIT 9 /* datakit protocols */ 75 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 76 #define AF_SNA 11 /* IBM SNA */ 77 #define AF_DECnet 12 /* DECnet */ 78 #define AF_DLI 13 /* DEC Direct data link interface */ 79 #define AF_LAT 14 /* LAT */ 80 #define AF_HYLINK 15 /* NSC Hyperchannel */ 81 #define AF_APPLETALK 16 /* Apple Talk */ 82 #define AF_ROUTE 17 /* Internal Routing Protocol */ 83 #define AF_LINK 18 /* Link layer interface */ 84 #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ 85 #define AF_COIP 20 /* connection-oriented IP, aka ST II */ 86 87 #define AF_MAX 21 88 89 /* 90 * Structure used by kernel to store most 91 * addresses. 92 */ 93 struct sockaddr { 94 u_char sa_len; /* total length */ 95 u_char sa_family; /* address family */ 96 char sa_data[14]; /* actually longer; address value */ 97 }; 98 99 /* 100 * Structure used by kernel to pass protocol 101 * information in raw sockets. 102 */ 103 struct sockproto { 104 u_short sp_family; /* address family */ 105 u_short sp_protocol; /* protocol */ 106 }; 107 108 /* 109 * Protocol families, same as address families for now. 110 */ 111 #define PF_UNSPEC AF_UNSPEC 112 #define PF_UNIX AF_UNIX 113 #define PF_INET AF_INET 114 #define PF_IMPLINK AF_IMPLINK 115 #define PF_PUP AF_PUP 116 #define PF_CHAOS AF_CHAOS 117 #define PF_NS AF_NS 118 #define PF_ISO AF_ISO 119 #define PF_OSI AF_ISO 120 #define PF_ECMA AF_ECMA 121 #define PF_DATAKIT AF_DATAKIT 122 #define PF_CCITT AF_CCITT 123 #define PF_SNA AF_SNA 124 #define PF_DECnet AF_DECnet 125 #define PF_DLI AF_DLI 126 #define PF_LAT AF_LAT 127 #define PF_HYLINK AF_HYLINK 128 #define PF_APPLETALK AF_APPLETALK 129 #define PF_ROUTE AF_ROUTE 130 #define PF_LINK AF_LINK 131 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ 132 #define PF_COIP AF_COIP 133 134 #define PF_MAX AF_MAX 135 136 /* 137 * Maximum queue length specifiable by listen. 138 */ 139 #define SOMAXCONN 5 140 141 /* 142 * Message header for recvmsg and sendmsg calls. 143 * Used value-result for recvmsg, value only for sendmsg. 144 */ 145 struct msghdr { 146 caddr_t msg_name; /* optional address */ 147 u_int msg_namelen; /* size of address */ 148 struct iovec *msg_iov; /* scatter/gather array */ 149 u_int msg_iovlen; /* # elements in msg_iov */ 150 caddr_t msg_control; /* ancillary data, see below */ 151 u_int msg_controllen; /* ancillary data buffer len */ 152 int msg_flags; /* flags on received message */ 153 }; 154 155 #define MSG_OOB 0x1 /* process out-of-band data */ 156 #define MSG_PEEK 0x2 /* peek at incoming message */ 157 #define MSG_DONTROUTE 0x4 /* send without using routing tables */ 158 #define MSG_EOR 0x8 /* data completes record */ 159 #define MSG_TRUNC 0x10 /* data discarded before delivery */ 160 #define MSG_CTRUNC 0x20 /* control data lost before delivery */ 161 #define MSG_WAITALL 0x40 /* wait for full request or error */ 162 163 /* 164 * Header for ancillary data objects in msg_control buffer. 165 * Used for additional information with/about a datagram 166 * not expressible by flags. The format is a sequence 167 * of message elements headed by cmsghdr structures. 168 */ 169 struct cmsghdr { 170 u_int cmsg_len; /* data byte count, including hdr */ 171 int cmsg_level; /* originating protocol */ 172 int cmsg_type; /* protocol-specific type */ 173 /* followed by u_char cmsg_data[]; */ 174 }; 175 176 /* given pointer to struct adatahdr, return pointer to data */ 177 #define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1)) 178 179 /* given pointer to struct adatahdr, return pointer to next adatahdr */ 180 #define CMSG_NXTHDR(mhdr, cmsg) \ 181 (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \ 182 (mhdr)->msg_control + (mhdr)->msg_controllen) ? \ 183 (struct cmsghdr *)NULL : \ 184 (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len))) 185 186 #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control) 187 188 /* "Socket"-level control message types: */ 189 #define SCM_RIGHTS 0x01 /* access rights (array of int) */ 190 191 /* 192 * 4.3 compat sockaddr, move to compat file later 193 */ 194 struct osockaddr { 195 u_short sa_family; /* address family */ 196 char sa_data[14]; /* up to 14 bytes of direct address */ 197 }; 198 199 /* 200 * 4.3-compat message header (move to compat file later). 201 */ 202 struct omsghdr { 203 caddr_t msg_name; /* optional address */ 204 int msg_namelen; /* size of address */ 205 struct iovec *msg_iov; /* scatter/gather array */ 206 int msg_iovlen; /* # elements in msg_iov */ 207 caddr_t msg_accrights; /* access rights sent/received */ 208 int msg_accrightslen; 209 }; 210 211 #ifndef KERNEL 212 213 #include <sys/cdefs.h> 214 215 __BEGIN_DECLS 216 int accept __P((int, struct sockaddr *, int *)); 217 int bind __P((int, const struct sockaddr *, int)); 218 int connect __P((int, const struct sockaddr *, int)); 219 int getpeername __P((int, struct sockaddr *, int *)); 220 int getsockname __P((int, struct sockaddr *, int *)); 221 int getsockopt __P((int, int, int, void *, int *)); 222 int listen __P((int, int)); 223 int recv __P((int, void *, int, int)); 224 int recvfrom __P((int, void *, int, int, 225 struct sockaddr *, int *)); 226 int recvmsg __P((int, struct msghdr *, int)); 227 int send __P((int, const void *, int, int)); 228 int sendto __P((int, const void *, int, int, const struct sockaddr *, int)); 229 int sendmsg __P((int, const struct msghdr *, int)); 230 int setsockopt __P((int, int, int, const void *, int)); 231 int shutdown __P((int, int)); 232 int socket __P((int, int, int)); 233 int socketpair __P((int, int, int, int *)); 234 __END_DECLS 235 236 #endif /* !KERNEL */ 237