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