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.12 (Berkeley) 03/04/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 86 #define AF_MAX 20 87 88 /* 89 * Structure used by kernel to store most 90 * addresses. 91 */ 92 struct sockaddr { 93 u_char sa_len; /* total length */ 94 u_char sa_family; /* address family */ 95 char sa_data[14]; /* actually longer; address value */ 96 }; 97 98 /* 99 * Structure used by kernel to pass protocol 100 * information in raw sockets. 101 */ 102 struct sockproto { 103 u_short sp_family; /* address family */ 104 u_short sp_protocol; /* protocol */ 105 }; 106 107 /* 108 * Protocol families, same as address families for now. 109 */ 110 #define PF_UNSPEC AF_UNSPEC 111 #define PF_UNIX AF_UNIX 112 #define PF_INET AF_INET 113 #define PF_IMPLINK AF_IMPLINK 114 #define PF_PUP AF_PUP 115 #define PF_CHAOS AF_CHAOS 116 #define PF_NS AF_NS 117 #define PF_ISO AF_ISO 118 #define PF_OSI AF_ISO 119 #define PF_ECMA AF_ECMA 120 #define PF_DATAKIT AF_DATAKIT 121 #define PF_CCITT AF_CCITT 122 #define PF_SNA AF_SNA 123 #define PF_DECnet AF_DECnet 124 #define PF_DLI AF_DLI 125 #define PF_LAT AF_LAT 126 #define PF_HYLINK AF_HYLINK 127 #define PF_APPLETALK AF_APPLETALK 128 #define PF_ROUTE AF_ROUTE 129 #define PF_LINK AF_LINK 130 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ 131 132 #define PF_MAX AF_MAX 133 134 /* 135 * Maximum queue length specifiable by listen. 136 */ 137 #define SOMAXCONN 5 138 139 /* 140 * Message header for recvmsg and sendmsg calls. 141 * Used value-result for recvmsg, value only for sendmsg. 142 */ 143 struct msghdr { 144 caddr_t msg_name; /* optional address */ 145 u_int msg_namelen; /* size of address */ 146 struct iovec *msg_iov; /* scatter/gather array */ 147 u_int msg_iovlen; /* # elements in msg_iov */ 148 caddr_t msg_control; /* ancillary data, see below */ 149 u_int msg_controllen; /* ancillary data buffer len */ 150 int msg_flags; /* flags on received message */ 151 }; 152 153 #define MSG_OOB 0x1 /* process out-of-band data */ 154 #define MSG_PEEK 0x2 /* peek at incoming message */ 155 #define MSG_DONTROUTE 0x4 /* send without using routing tables */ 156 #define MSG_EOR 0x8 /* data completes record */ 157 #define MSG_TRUNC 0x10 /* data discarded before delivery */ 158 #define MSG_CTRUNC 0x20 /* control data lost before delivery */ 159 #define MSG_WAITALL 0x40 /* wait for full request or error */ 160 161 /* 162 * Header for ancillary data objects in msg_control buffer. 163 * Used for additional information with/about a datagram 164 * not expressible by flags. The format is a sequence 165 * of message elements headed by cmsghdr structures. 166 */ 167 struct cmsghdr { 168 u_int cmsg_len; /* data byte count, including hdr */ 169 int cmsg_level; /* originating protocol */ 170 int cmsg_type; /* protocol-specific type */ 171 /* followed by u_char cmsg_data[]; */ 172 }; 173 174 /* given pointer to struct adatahdr, return pointer to data */ 175 #define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1)) 176 177 /* given pointer to struct adatahdr, return pointer to next adatahdr */ 178 #define CMSG_NXTHDR(mhdr, cmsg) \ 179 (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \ 180 (mhdr)->msg_control + (mhdr)->msg_controllen) ? \ 181 (struct cmsghdr *)NULL : \ 182 (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len))) 183 184 #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control) 185 186 /* "Socket"-level control message types: */ 187 #define SCM_RIGHTS 0x01 /* access rights (array of int) */ 188 189 /* 190 * 4.3 compat sockaddr, move to compat file later 191 */ 192 struct osockaddr { 193 u_short sa_family; /* address family */ 194 char sa_data[14]; /* up to 14 bytes of direct address */ 195 }; 196 197 /* 198 * 4.3-compat message header (move to compat file later). 199 */ 200 struct omsghdr { 201 caddr_t msg_name; /* optional address */ 202 int msg_namelen; /* size of address */ 203 struct iovec *msg_iov; /* scatter/gather array */ 204 int msg_iovlen; /* # elements in msg_iov */ 205 caddr_t msg_accrights; /* access rights sent/received */ 206 int msg_accrightslen; 207 }; 208 209 #ifndef KERNEL 210 211 #include <sys/cdefs.h> 212 213 __BEGIN_DECLS 214 int accept __P((int, struct sockaddr *, int *)); 215 int bind __P((int, const struct sockaddr *, int)); 216 int connect __P((int, const struct sockaddr *, int)); 217 int getpeername __P((int, struct sockaddr *, int *)); 218 int getsockname __P((int, struct sockaddr *, int *)); 219 int getsockopt __P((int, int, int, void *, int *)); 220 int listen __P((int, int)); 221 int recv __P((int, void *, int, int)); 222 int recvfrom __P((int, void *, int, int, 223 struct sockaddr *, int *)); 224 int recvmsg __P((int, const struct msghdr *, int)); 225 int send __P((int, const void *, int, int)); 226 int sendto __P((int, const void *, int, int, const struct sockaddr *, int)); 227 int sendmsg __P((int, const struct msghdr *, int)); 228 int setsockopt __P((int, int, int, const void *, int)); 229 int shutdown __P((int, int)); 230 int socket __P((int, int, int)); 231 int socketpair __P((int, int, int, int *)); 232 __END_DECLS 233 234 #endif /* !KERNEL */ 235