1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #ifndef _SYS_SOCKET_H_
36 #define _SYS_SOCKET_H_
37
38
39
40
41 #include <machine/param.h>
42
43
44
45
46
47
48
49
50 #define SOCK_STREAM 1
51 #define SOCK_DGRAM 2
52 #define SOCK_RAW 3
53 #define SOCK_RDM 4
54 #define SOCK_SEQPACKET 5
55
56
57
58
59 #define SO_DEBUG 0x0001
60 #define SO_ACCEPTCONN 0x0002
61 #define SO_REUSEADDR 0x0004
62 #define SO_KEEPALIVE 0x0008
63 #define SO_DONTROUTE 0x0010
64 #define SO_BROADCAST 0x0020
65 #define SO_USELOOPBACK 0x0040
66 #define SO_LINGER 0x0080
67 #define SO_OOBINLINE 0x0100
68 #define SO_REUSEPORT 0x0200
69 #define SO_JUMBO 0x0400
70
71
72
73
74 #define SO_SNDBUF 0x1001
75 #define SO_RCVBUF 0x1002
76 #define SO_SNDLOWAT 0x1003
77 #define SO_RCVLOWAT 0x1004
78 #define SO_SNDTIMEO 0x1005
79 #define SO_RCVTIMEO 0x1006
80 #define SO_ERROR 0x1007
81 #define SO_TYPE 0x1008
82 #define SO_NETPROC 0x1020
83
84
85
86
87 struct linger {
88 int l_onoff;
89 int l_linger;
90 };
91
92
93
94
95 #define SOL_SOCKET 0xffff
96
97
98
99
100 #define AF_UNSPEC 0
101 #define AF_LOCAL 1
102 #define AF_UNIX AF_LOCAL
103 #define AF_INET 2
104 #define AF_IMPLINK 3
105 #define AF_PUP 4
106 #define AF_CHAOS 5
107 #define AF_NS 6
108 #define AF_ISO 7
109 #define AF_OSI AF_ISO
110 #define AF_ECMA 8
111 #define AF_DATAKIT 9
112 #define AF_CCITT 10
113 #define AF_SNA 11
114 #define AF_DECnet 12
115 #define AF_DLI 13
116 #define AF_LAT 14
117 #define AF_HYLINK 15
118 #define AF_APPLETALK 16
119 #define AF_ROUTE 17
120 #define AF_LINK 18
121 #define pseudo_AF_XTP 19
122 #define AF_COIP 20
123 #define AF_CNT 21
124 #define pseudo_AF_RTIP 22
125 #define AF_IPX 23
126 #define AF_INET6 24
127 #define pseudo_AF_PIP 25
128 #define AF_ISDN 26
129 #define AF_E164 AF_ISDN
130 #define AF_NATM 27
131 #define AF_ENCAP 28
132 #define AF_SIP 29
133 #define AF_KEY 30
134 #define pseudo_AF_HDRCMPLT 31
135
136 #define AF_BLUETOOTH 32
137
138 #define AF_MAX 33
139
140
141
142
143
144 struct sockaddr {
145 u_int8_t sa_len;
146 sa_family_t sa_family;
147 char sa_data[14];
148 };
149
150
151
152
153
154
155
156
157
158
159
160
161
162 struct sockaddr_storage {
163 u_int8_t ss_len;
164 sa_family_t ss_family;
165 unsigned char __ss_pad1[6];
166 u_int64_t __ss_pad2;
167 unsigned char __ss_pad3[240];
168 };
169
170
171
172
173
174 struct sockproto {
175 unsigned short sp_family;
176 unsigned short sp_protocol;
177 };
178
179
180
181
182 #define PF_UNSPEC AF_UNSPEC
183 #define PF_LOCAL AF_LOCAL
184 #define PF_UNIX PF_LOCAL
185 #define PF_INET AF_INET
186 #define PF_IMPLINK AF_IMPLINK
187 #define PF_PUP AF_PUP
188 #define PF_CHAOS AF_CHAOS
189 #define PF_NS AF_NS
190 #define PF_ISO AF_ISO
191 #define PF_OSI AF_ISO
192 #define PF_ECMA AF_ECMA
193 #define PF_DATAKIT AF_DATAKIT
194 #define PF_CCITT AF_CCITT
195 #define PF_SNA AF_SNA
196 #define PF_DECnet AF_DECnet
197 #define PF_DLI AF_DLI
198 #define PF_LAT AF_LAT
199 #define PF_HYLINK AF_HYLINK
200 #define PF_APPLETALK AF_APPLETALK
201 #define PF_ROUTE AF_ROUTE
202 #define PF_LINK AF_LINK
203 #define PF_XTP pseudo_AF_XTP
204 #define PF_COIP AF_COIP
205 #define PF_CNT AF_CNT
206 #define PF_IPX AF_IPX
207 #define PF_INET6 AF_INET6
208 #define PF_RTIP pseudo_AF_RTIP
209 #define PF_PIP pseudo_AF_PIP
210 #define PF_ISDN AF_ISDN
211 #define PF_NATM AF_NATM
212 #define PF_ENCAP AF_ENCAP
213 #define PF_SIP AF_SIP
214 #define PF_KEY AF_KEY
215 #define PF_BPF pseudo_AF_HDRCMPLT
216 #define PF_BLUETOOTH AF_BLUETOOTH
217 #define PF_MAX AF_MAX
218
219
220
221
222 #define SHUT_RD 0
223 #define SHUT_WR 1
224 #define SHUT_RDWR 2
225
226
227
228
229 struct sockcred {
230 uid_t sc_uid;
231 uid_t sc_euid;
232 gid_t sc_gid;
233 gid_t sc_egid;
234 int sc_ngroups;
235 gid_t sc_groups[1];
236 };
237
238
239
240
241 #define SOCKCREDSIZE(ngrps) \
242 (sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
243
244
245
246
247
248
249
250
251
252 #define NET_MAXID AF_MAX
253
254 #define CTL_NET_NAMES { \
255 { 0, 0 }, \
256 { "unix", CTLTYPE_NODE }, \
257 { "inet", CTLTYPE_NODE }, \
258 { "implink", CTLTYPE_NODE }, \
259 { "pup", CTLTYPE_NODE }, \
260 { "chaos", CTLTYPE_NODE }, \
261 { "xerox_ns", CTLTYPE_NODE }, \
262 { "iso", CTLTYPE_NODE }, \
263 { "emca", CTLTYPE_NODE }, \
264 { "datakit", CTLTYPE_NODE }, \
265 { "ccitt", CTLTYPE_NODE }, \
266 { "ibm_sna", CTLTYPE_NODE }, \
267 { "decnet", CTLTYPE_NODE }, \
268 { "dec_dli", CTLTYPE_NODE }, \
269 { "lat", CTLTYPE_NODE }, \
270 { "hylink", CTLTYPE_NODE }, \
271 { "appletalk", CTLTYPE_NODE }, \
272 { "route", CTLTYPE_NODE }, \
273 { "link_layer", CTLTYPE_NODE }, \
274 { "xtp", CTLTYPE_NODE }, \
275 { "coip", CTLTYPE_NODE }, \
276 { "cnt", CTLTYPE_NODE }, \
277 { "rtip", CTLTYPE_NODE }, \
278 { "ipx", CTLTYPE_NODE }, \
279 { "inet6", CTLTYPE_NODE }, \
280 { "pip", CTLTYPE_NODE }, \
281 { "isdn", CTLTYPE_NODE }, \
282 { "natm", CTLTYPE_NODE }, \
283 { "encap", CTLTYPE_NODE }, \
284 { "sip", CTLTYPE_NODE }, \
285 { "key", CTLTYPE_NODE }, \
286 { "bpf", CTLTYPE_NODE }, \
287 }
288
289
290
291
292
293
294
295
296
297 #define NET_RT_DUMP 1
298 #define NET_RT_FLAGS 2
299 #define NET_RT_IFLIST 3
300 #define NET_RT_STATS 4
301 #define NET_RT_MAXID 5
302
303 #define CTL_NET_RT_NAMES { \
304 { 0, 0 }, \
305 { "dump", CTLTYPE_STRUCT }, \
306 { "flags", CTLTYPE_STRUCT }, \
307 { "iflist", CTLTYPE_STRUCT }, \
308 { "stats", CTLTYPE_STRUCT }, \
309 }
310
311
312
313
314 #define NET_KEY_SADB_DUMP 1
315 #define NET_KEY_SPD_DUMP 2
316 #define NET_KEY_MAXID 3
317
318 #define CTL_NET_KEY_NAMES { \
319 { 0, 0 }, \
320 { "sadb_dump", CTLTYPE_STRUCT }, \
321 { "spd_dump", CTLTYPE_STRUCT }, \
322 }
323
324
325
326
327 #define NET_BPF_BUFSIZE 1
328 #define NET_BPF_MAXBUFSIZE 2
329 #define NET_BPF_MAXID 3
330
331 #define CTL_NET_BPF_NAMES { \
332 { 0, 0 }, \
333 { "bufsize", CTLTYPE_INT }, \
334 { "maxbufsize", CTLTYPE_INT }, \
335 }
336
337
338
339
340 #define SOMAXCONN 128
341
342
343
344
345
346 struct msghdr {
347 void *msg_name;
348 socklen_t msg_namelen;
349 struct iovec *msg_iov;
350 unsigned int msg_iovlen;
351 void *msg_control;
352 socklen_t msg_controllen;
353 int msg_flags;
354 };
355
356 #define MSG_OOB 0x1
357 #define MSG_PEEK 0x2
358 #define MSG_DONTROUTE 0x4
359 #define MSG_EOR 0x8
360 #define MSG_TRUNC 0x10
361 #define MSG_CTRUNC 0x20
362 #define MSG_WAITALL 0x40
363 #define MSG_DONTWAIT 0x80
364 #define MSG_BCAST 0x100
365 #define MSG_MCAST 0x200
366
367
368
369
370
371
372
373 struct cmsghdr {
374 socklen_t cmsg_len;
375 int cmsg_level;
376 int cmsg_type;
377
378 };
379
380
381 #define CMSG_DATA(cmsg) \
382 ((u_char *)(cmsg) + __CMSG_ALIGN(sizeof(struct cmsghdr)))
383
384
385 #define CMSG_NXTHDR(mhdr, cmsg) \
386 (((caddr_t)(cmsg) + __CMSG_ALIGN((cmsg)->cmsg_len) + \
387 __CMSG_ALIGN(sizeof(struct cmsghdr)) > \
388 ((caddr_t)(mhdr)->msg_control) + (mhdr)->msg_controllen) ? \
389 (struct cmsghdr *)NULL : \
390 (struct cmsghdr *)((caddr_t)(cmsg) + __CMSG_ALIGN((cmsg)->cmsg_len)))
391
392
393
394
395
396 #define CMSG_FIRSTHDR(mhdr) \
397 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
398 (struct cmsghdr *)(mhdr)->msg_control : \
399 (struct cmsghdr *)NULL)
400
401
402 #define __CMSG_ALIGN(len) ALIGN(len)
403 #ifdef _KERNEL
404 #define CMSG_ALIGN(n) __CMSG_ALIGN(n)
405 #endif
406
407
408 #define CMSG_LEN(len) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
409
410
411 #define CMSG_SPACE(len) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(len))
412
413
414 #define SCM_RIGHTS 0x01
415 #define SCM_CREDS 0x02
416
417
418
419
420 struct osockaddr {
421 unsigned short sa_family;
422 char sa_data[14];
423 };
424
425
426
427
428 struct omsghdr {
429 caddr_t msg_name;
430 int msg_namelen;
431 struct iovec *msg_iov;
432 int msg_iovlen;
433 caddr_t msg_accrights;
434 int msg_accrightslen;
435 };
436
437 #define SA_LEN(x) ((x)->sa_len)
438
439 #ifndef _KERNEL
440
441 #include <sys/cdefs.h>
442
443 __BEGIN_DECLS
444 int accept(int, struct sockaddr *, socklen_t *);
445 int bind(int, const struct sockaddr *, socklen_t);
446 int connect(int, const struct sockaddr *, socklen_t);
447 int getpeereid(int, uid_t *, gid_t *);
448 int getpeername(int, struct sockaddr *, socklen_t *);
449 int getsockname(int, struct sockaddr *, socklen_t *);
450 int getsockopt(int, int, int, void *, socklen_t *);
451 int listen(int, int);
452 ssize_t recv(int, void *, size_t, int);
453 ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
454 ssize_t recvmsg(int, struct msghdr *, int);
455 ssize_t send(int, const void *, size_t, int);
456 ssize_t sendto(int, const void *,
457 size_t, int, const struct sockaddr *, socklen_t);
458 ssize_t sendmsg(int, const struct msghdr *, int);
459 int setsockopt(int, int, int, const void *, socklen_t);
460 int shutdown(int, int);
461 int socket(int, int, int);
462 int socketpair(int, int, int, int *);
463 __END_DECLS
464 #else
465 # if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_LINUX) || \
466 defined(COMPAT_HPUX) || defined(COMPAT_FREEBSD) || defined(COMPAT_BSDOS) \
467 || defined(COMPAT_OSF1)
468 # define COMPAT_OLDSOCK
469 # define MSG_COMPAT 0x8000
470 # endif
471
472 void pfctlinput(int, struct sockaddr *);
473 #endif
474
475 #endif