BSD 4_3_Reno release
[unix-history] / usr / src / sys / sys / socket.h
CommitLineData
da7c5cc6 1/*
1d271b44 2 * Copyright (c) 1982,1985,1986,1988 Regents of the University of California.
5b519e94 3 * All rights reserved.
da7c5cc6 4 *
1c15e888
C
5 * Redistribution is only permitted until one year after the first shipment
6 * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and
7 * binary forms are permitted provided that: (1) source distributions retain
8 * this entire copyright notice and comment, and (2) distributions including
9 * binaries display the following acknowledgement: This product includes
10 * software developed by the University of California, Berkeley and its
11 * contributors'' in the documentation or other materials provided with the
12 * distribution and in all advertising materials mentioning features or use
13 * of this software. Neither the name of the University nor the names of
14 * its contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
5b519e94 19 *
1c15e888 20 * @(#)socket.h 7.10 (Berkeley) 6/28/90
da7c5cc6 21 */
d47ff4b1
BJ
22
23/*
d6d65f4d 24 * Definitions related to sockets: types, address families, options.
541352f0
BJ
25 */
26
27/*
d6d65f4d 28 * Types
d47ff4b1 29 */
2b4b57cd
BJ
30#define SOCK_STREAM 1 /* stream socket */
31#define SOCK_DGRAM 2 /* datagram socket */
32#define SOCK_RAW 3 /* raw-protocol interface */
33#define SOCK_RDM 4 /* reliably-delivered message */
d6d65f4d 34#define SOCK_SEQPACKET 5 /* sequenced packet stream */
d47ff4b1 35
f5d87a9a
BJ
36/*
37 * Option flags per-socket.
38 */
97c8f6a8
MK
39#define SO_DEBUG 0x0001 /* turn on debugging info recording */
40#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
41#define SO_REUSEADDR 0x0004 /* allow local address reuse */
42#define SO_KEEPALIVE 0x0008 /* keep connections alive */
43#define SO_DONTROUTE 0x0010 /* just use interface addresses */
44#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
45#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
46#define SO_LINGER 0x0080 /* linger on close if data present */
47#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
11b83d3b 48
3062cca6
MK
49/*
50 * Additional options, not kept in so_options.
51 */
52#define SO_SNDBUF 0x1001 /* send buffer size */
53#define SO_RCVBUF 0x1002 /* receive buffer size */
54#define SO_SNDLOWAT 0x1003 /* send low-water mark */
55#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
56#define SO_SNDTIMEO 0x1005 /* send timeout */
57#define SO_RCVTIMEO 0x1006 /* receive timeout */
ce4aafa1 58#define SO_ERROR 0x1007 /* get error status and clear */
5872461b 59#define SO_TYPE 0x1008 /* get socket type */
3062cca6 60
11b83d3b 61/*
4f4e8d81 62 * Structure used for manipulating linger option.
11b83d3b 63 */
4f4e8d81
SL
64struct linger {
65 int l_onoff; /* option on/off */
66 int l_linger; /* linger time */
67};
68
69/*
70 * Level number for (get/set)sockopt() to apply to socket itself.
71 */
72#define SOL_SOCKET 0xffff /* options for socket level */
2b4b57cd
BJ
73
74/*
d6d65f4d 75 * Address families.
2b4b57cd 76 */
d6d65f4d
SL
77#define AF_UNSPEC 0 /* unspecified */
78#define AF_UNIX 1 /* local to host (pipes, portals) */
79#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
80#define AF_IMPLINK 3 /* arpanet imp addresses */
81#define AF_PUP 4 /* pup protocols: e.g. BSP */
82#define AF_CHAOS 5 /* mit CHAOS protocols */
83#define AF_NS 6 /* XEROX NS protocols */
c39aec4e 84#define AF_ISO 7 /* ISO protocols */
cb992683 85#define AF_OSI AF_ISO
d6d65f4d
SL
86#define AF_ECMA 8 /* european computer manufacturers */
87#define AF_DATAKIT 9 /* datakit protocols */
88#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
89#define AF_SNA 11 /* IBM SNA */
92ca08e6 90#define AF_DECnet 12 /* DECnet */
cb992683 91#define AF_DLI 13 /* DEC Direct data link interface */
92ca08e6
MK
92#define AF_LAT 14 /* LAT */
93#define AF_HYLINK 15 /* NSC Hyperchannel */
581af202 94#define AF_APPLETALK 16 /* Apple Talk */
c39aec4e 95#define AF_ROUTE 17 /* Internal Routing Protocol */
cb992683
MK
96#define AF_LINK 18 /* Link layer interface */
97#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
2b4b57cd 98
cb992683 99#define AF_MAX 20
2b4b57cd
BJ
100
101/*
d6d65f4d
SL
102 * Structure used by kernel to store most
103 * addresses.
2b4b57cd 104 */
1d271b44
KS
105struct sockaddr {
106 u_char sa_len; /* total length */
107 u_char sa_family; /* address family */
c39aec4e 108 char sa_data[14]; /* actually longer; address value */
1d271b44 109};
2b4b57cd
BJ
110
111/*
d6d65f4d
SL
112 * Structure used by kernel to pass protocol
113 * information in raw sockets.
2b4b57cd 114 */
d6d65f4d
SL
115struct sockproto {
116 u_short sp_family; /* address family */
117 u_short sp_protocol; /* protocol */
118};
f13cea3e 119
d6d65f4d
SL
120/*
121 * Protocol families, same as address families for now.
122 */
123#define PF_UNSPEC AF_UNSPEC
124#define PF_UNIX AF_UNIX
125#define PF_INET AF_INET
126#define PF_IMPLINK AF_IMPLINK
127#define PF_PUP AF_PUP
128#define PF_CHAOS AF_CHAOS
129#define PF_NS AF_NS
c39aec4e 130#define PF_ISO AF_ISO
cb992683 131#define PF_OSI AF_ISO
d6d65f4d
SL
132#define PF_ECMA AF_ECMA
133#define PF_DATAKIT AF_DATAKIT
134#define PF_CCITT AF_CCITT
135#define PF_SNA AF_SNA
92ca08e6
MK
136#define PF_DECnet AF_DECnet
137#define PF_DLI AF_DLI
138#define PF_LAT AF_LAT
139#define PF_HYLINK AF_HYLINK
581af202 140#define PF_APPLETALK AF_APPLETALK
c39aec4e 141#define PF_ROUTE AF_ROUTE
cb992683
MK
142#define PF_LINK AF_LINK
143#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
dc44a5d7 144
92ca08e6 145#define PF_MAX AF_MAX
d6d65f4d 146
d6d65f4d
SL
147/*
148 * Maximum queue length specifiable by listen.
149 */
150#define SOMAXCONN 5
151
152/*
153 * Message header for recvmsg and sendmsg calls.
1d271b44 154 * Used value-result for recvmsg, value only for sendmsg.
d6d65f4d
SL
155 */
156struct msghdr {
157 caddr_t msg_name; /* optional address */
383174ba 158 u_int msg_namelen; /* size of address */
d6d65f4d 159 struct iovec *msg_iov; /* scatter/gather array */
383174ba 160 u_int msg_iovlen; /* # elements in msg_iov */
cb992683 161 caddr_t msg_control; /* ancillary data, see below */
383174ba 162 u_int msg_controllen; /* ancillary data buffer len */
1d271b44 163 int msg_flags; /* flags on received message */
d6d65f4d
SL
164};
165
166#define MSG_OOB 0x1 /* process out-of-band data */
167#define MSG_PEEK 0x2 /* peek at incoming message */
168#define MSG_DONTROUTE 0x4 /* send without using routing tables */
1d271b44
KS
169#define MSG_EOR 0x8 /* data completes record */
170#define MSG_TRUNC 0x10 /* data discarded before delivery */
171#define MSG_CTRUNC 0x20 /* control data lost before delivery */
cb992683
MK
172#define MSG_WAITALL 0x40 /* wait for full request or error */
173
cb992683
MK
174/*
175 * Header for ancillary data objects in msg_control buffer.
176 * Used for additional information with/about a datagram
177 * not expressible by flags. The format is a sequence
178 * of message elements headed by cmsghdr structures.
179 */
180struct cmsghdr {
181 u_int cmsg_len; /* data byte count, including hdr */
383174ba
KS
182 int cmsg_level; /* originating protocol */
183 int cmsg_type; /* protocol-specific type */
cb992683
MK
184/* followed by u_char cmsg_data[]; */
185};
186
187/* given pointer to struct adatahdr, return pointer to data */
188#define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1))
189
190/* given pointer to struct adatahdr, return pointer to next adatahdr */
191#define CMSG_NXTHDR(mhdr, cmsg) \
192 (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
193 (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
194 (struct cmsghdr *)NULL : \
195 (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
196
197#define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
198
199/* "Socket"-level control message types: */
200#define SCM_RIGHTS 0x01 /* access rights (array of int) */
201
202/*
203 * 4.3 compat sockaddr, move to compat file later
204 */
205struct osockaddr {
206 u_short sa_family; /* address family */
207 char sa_data[14]; /* up to 14 bytes of direct address */
208};
1d271b44
KS
209
210/*
211 * 4.3-compat message header (move to compat file later).
212 */
213struct omsghdr {
214 caddr_t msg_name; /* optional address */
215 int msg_namelen; /* size of address */
216 struct iovec *msg_iov; /* scatter/gather array */
217 int msg_iovlen; /* # elements in msg_iov */
218 caddr_t msg_accrights; /* access rights sent/received */
219 int msg_accrightslen;
220};