1a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
2a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
3a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *	The Regents of the University of California.  All rights reserved.
4a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *
5a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without
6a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * modification, are permitted provided that the following conditions
7a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * are met:
8a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * 1. Redistributions of source code must retain the above copyright
9a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
10a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright
11a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
12a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *    documentation and/or other materials provided with the distribution.
13a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * 4. Neither the name of the University nor the names of its contributors
14a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *    may be used to endorse or promote products derived from this software
15a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *    without specific prior written permission.
16a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *
17a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * SUCH DAMAGE.
28a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *
29a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *	@(#)socket.h	8.4 (Berkeley) 2/21/94
30a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * $FreeBSD: src/sys/sys/socket.h,v 1.60 2002/04/20 02:24:35 mike Exp $
31a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
32a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
33a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#ifndef _SYS_SOCKET_H_
34a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	_SYS_SOCKET_H_
35a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
36a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include <sys/types.h>
37a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include <sys/_types.h>
38a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include <netinet/in.h>
39a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include <netdb.h>
40a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
41a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/* Needed by linuxthreads. */
42a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
43a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)# define __SOCKADDR_ARG		struct sockaddr *__restrict
44a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)# define __CONST_SOCKADDR_ARG	__const struct sockaddr *
45a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
46a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
47a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Definitions related to sockets: types, address families, options.
48a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
49a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
50a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
51a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Data types.
52a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
53a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#ifdef _BSD_SA_FAMILY_T_
54a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)typedef	_BSD_SA_FAMILY_T_	sa_family_t;
55a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#undef _BSD_SA_FAMILY_T_
56a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#endif
57a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
58a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#ifdef	_BSD_SOCKLEN_T_
59a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)typedef	_BSD_SOCKLEN_T_	socklen_t;
60a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#undef	_BSD_SOCKLEN_T_
61a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#endif
621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
63a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
64a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Types
65a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
66a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SOCK_STREAM	1		/* stream socket */
67a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SOCK_DGRAM	2		/* datagram socket */
68a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SOCK_RAW	3		/* raw-protocol interface */
69a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SOCK_RDM	4		/* reliably-delivered message */
70a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SOCK_SEQPACKET	5		/* sequenced packet stream */
71a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)/* Socket type flags that can be or'd with the above types */
73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define SOCK_CLOEXEC 0x100
74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define SOCK_NONBLOCK 0x200
75f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Option flags per-socket.
78a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
79a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_DEBUG	0x0001		/* turn on debugging info recording */
80a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_ACCEPTCONN	0x0002		/* socket has had listen() */
81a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_REUSEADDR	0x0004		/* allow local address reuse */
82a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_KEEPALIVE	0x0008		/* keep connections alive */
83a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_DONTROUTE	0x0010		/* just use interface addresses */
84a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_BROADCAST	0x0020		/* permit sending of broadcast msgs */
85a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_USELOOPBACK	0x0040		/* bypass hardware when possible */
86a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_LINGER	0x0080		/* linger on close if data present */
87a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_OOBINLINE	0x0100		/* leave received OOB data in line */
88a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_REUSEPORT	0x0200		/* allow local address & port reuse */
89a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_TIMESTAMP	0x0400		/* timestamp received dgram traffic */
90a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_ACCEPTFILTER	0x1000		/* there is an accept filter */
91a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
92a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
93a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Additional options, not kept in so_options.
94a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
95a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define SO_SNDBUF	0x1001		/* send buffer size */
96a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define SO_RCVBUF	0x1002		/* receive buffer size */
97a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define SO_SNDLOWAT	0x1003		/* send low-water mark */
98a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define SO_RCVLOWAT	0x1004		/* receive low-water mark */
99a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define SO_SNDTIMEO	0x1005		/* send timeout */
100a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define SO_RCVTIMEO	0x1006		/* receive timeout */
101a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_ERROR	0x1007		/* get error status and clear */
102a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SO_TYPE		0x1008		/* get socket type */
103a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*efine	SO_PRIVSTATE	0x1009		   get/deny privileged state */
104a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
105a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
106a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Structure used for manipulating linger option.
107a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
108a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)struct linger {
109a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	int	l_onoff;		/* option on/off */
110a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	int	l_linger;		/* linger time */
111a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
112a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
113a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)struct accept_filter_arg {
114a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	char	af_name[16];
115a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	char	af_arg[256-16];
116a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
117a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
118a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
119a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Level number for (get/set)sockopt() to apply to socket itself.
120a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
121a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SOL_SOCKET	0xffff		/* options for socket level */
122a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
123a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/* Protocol families.  */
124a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_UNSPEC	0	/* Unspecified.  */
125a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_LOCAL	1	/* Local to host (pipes and file-domain).  */
126a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_UNIX		PF_LOCAL /* Old BSD name for PF_LOCAL.  */
127a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_FILE		PF_LOCAL /* Another non-standard name for PF_LOCAL.  */
128a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_INET		2	/* IP protocol family.  */
129a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_AX25		3	/* Amateur Radio AX.25.  */
130a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_IPX		4	/* Novell Internet Protocol.  */
131a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_APPLETALK	5	/* Appletalk DDP.  */
132a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_NETROM	6	/* Amateur radio NetROM.  */
133a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_BRIDGE	7	/* Multiprotocol bridge.  */
134a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_ATMPVC	8	/* ATM PVCs.  */
135a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_X25		9	/* Reserved for X.25 project.  */
136a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_INET6	10	/* IP version 6.  */
137a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_ROSE		11	/* Amateur Radio X.25 PLP.  */
138a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_DECnet	12	/* Reserved for DECnet project.  */
139a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_NETBEUI	13	/* Reserved for 802.2LLC project.  */
140a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_SECURITY	14	/* Security callback pseudo AF.  */
141a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_KEY		15	/* PF_KEY key management API.  */
142a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_NETLINK	16
143a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_ROUTE	PF_NETLINK /* Alias to emulate 4.4BSD.  */
144a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_PACKET	17	/* Packet family.  */
145a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_ASH		18	/* Ash.  */
146a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_ECONET	19	/* Acorn Econet.  */
147a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_ATMSVC	20	/* ATM SVCs.  */
148a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_SNA		22	/* Linux SNA Project */
149a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_IRDA		23	/* IRDA sockets.  */
150a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_PPPOX	24	/* PPPoX sockets.  */
151a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_WANPIPE	25	/* Wanpipe API sockets.  */
152a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_BLUETOOTH	31	/* Bluetooth sockets.  */
153a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	PF_MAX		32	/* For now..  */
154a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
155a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/* Address families.  */
156a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_UNSPEC	PF_UNSPEC
157a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_LOCAL	PF_LOCAL
158a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_UNIX		PF_UNIX
159a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_FILE		PF_FILE
160a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_INET		PF_INET
161a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_AX25		PF_AX25
162a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_IPX		PF_IPX
163a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_APPLETALK	PF_APPLETALK
164a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_NETROM	PF_NETROM
165a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_BRIDGE	PF_BRIDGE
166a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_ATMPVC	PF_ATMPVC
167a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_X25		PF_X25
168a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_INET6	PF_INET6
169a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_ROSE		PF_ROSE
170a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_DECnet	PF_DECnet
171a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_NETBEUI	PF_NETBEUI
172a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_SECURITY	PF_SECURITY
173a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_KEY		PF_KEY
174a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_NETLINK	PF_NETLINK
175a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_ROUTE	PF_ROUTE
176a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_PACKET	PF_PACKET
177a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_ASH		PF_ASH
178a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_ECONET	PF_ECONET
179a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_ATMSVC	PF_ATMSVC
180a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_SNA		PF_SNA
181a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_IRDA		PF_IRDA
182a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_PPPOX	PF_PPPOX
183a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_WANPIPE	PF_WANPIPE
184a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_BLUETOOTH	PF_BLUETOOTH
185a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	AF_MAX		PF_MAX
186a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
187a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
188a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Structure used by kernel to store most
189a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * addresses.
190a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
191a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)struct sockaddr {
192a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	sa_family_t	sa_family;	/* address family */
193a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	char		sa_data[14];	/* actually longer; address value */
194a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
195a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SOCK_MAXADDRLEN	255		/* longest possible addresses */
196a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
197a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
198a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Structure used by kernel to pass protocol
199a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * information in raw sockets.
200a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
201a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)struct sockproto {
202a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	u_short	sp_family;		/* address family */
203a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	u_short	sp_protocol;		/* protocol */
204a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
205a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
206a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
207a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * RFC 2553: protocol-independent placeholder for socket addresses
208a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
209a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	_SS_MAXSIZE	128U
210a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	_SS_ALIGNSIZE	(sizeof(int64_t))
211a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	_SS_PAD1SIZE	(_SS_ALIGNSIZE - sizeof(unsigned char) - sizeof(sa_family_t))
212a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	_SS_PAD2SIZE	(_SS_MAXSIZE - sizeof(unsigned char) - sizeof(sa_family_t) - \
213a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)				_SS_PAD1SIZE - _SS_ALIGNSIZE)
214a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
215a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)struct sockaddr_storage {
216a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	sa_family_t	ss_family;	/* address family */
217a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	char		__ss_pad1[_SS_PAD1SIZE];
218a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	int64_t		__ss_align;	/* force desired structure storage alignment */
219a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	char		__ss_pad2[_SS_PAD2SIZE];
220a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
221a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
222a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
223a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Definitions for network related sysctl, CTL_NET.
224a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *
225a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Second level is protocol family.
226a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Third level is protocol number.
227a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *
228a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Further levels are defined by the individual families below.
229a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
230a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define NET_MAXID	AF_MAX
231a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
232a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define CTL_NET_NAMES { \
233a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ 0, 0 }, \
234a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "unix", CTLTYPE_NODE }, \
235a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "inet", CTLTYPE_NODE }, \
236a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "implink", CTLTYPE_NODE }, \
237a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "pup", CTLTYPE_NODE }, \
238a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "chaos", CTLTYPE_NODE }, \
239a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "xerox_ns", CTLTYPE_NODE }, \
240a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "iso", CTLTYPE_NODE }, \
241a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "emca", CTLTYPE_NODE }, \
242a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "datakit", CTLTYPE_NODE }, \
243a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "ccitt", CTLTYPE_NODE }, \
244a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "ibm_sna", CTLTYPE_NODE }, \
245a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "decnet", CTLTYPE_NODE }, \
246a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "dec_dli", CTLTYPE_NODE }, \
247a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "lat", CTLTYPE_NODE }, \
248a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "hylink", CTLTYPE_NODE }, \
249a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "appletalk", CTLTYPE_NODE }, \
250a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "route", CTLTYPE_NODE }, \
251a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "link_layer", CTLTYPE_NODE }, \
252a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "xtp", CTLTYPE_NODE }, \
253a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "coip", CTLTYPE_NODE }, \
254a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "cnt", CTLTYPE_NODE }, \
255a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "rtip", CTLTYPE_NODE }, \
256a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "ipx", CTLTYPE_NODE }, \
257a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "sip", CTLTYPE_NODE }, \
258a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "pip", CTLTYPE_NODE }, \
259a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "isdn", CTLTYPE_NODE }, \
260a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "key", CTLTYPE_NODE }, \
261a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "inet6", CTLTYPE_NODE }, \
262a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "natm", CTLTYPE_NODE }, \
263a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "atm", CTLTYPE_NODE }, \
264a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "hdrcomplete", CTLTYPE_NODE }, \
265a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "netgraph", CTLTYPE_NODE }, \
266a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "snp", CTLTYPE_NODE }, \
267a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "scp", CTLTYPE_NODE }, \
268a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
269a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
270a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
271a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * PF_ROUTE - Routing table
272a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *
273a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Three additional levels are defined:
274a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *	Fourth: address family, 0 is wildcard
275a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *	Fifth: type of info, defined below
276a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) *	Sixth: flag(s) to mask with for NET_RT_FLAGS
277a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
278a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define NET_RT_DUMP	1		/* dump; may limit to a.f. */
279a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define NET_RT_FLAGS	2		/* by flags, e.g. RESOLVING */
280a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define NET_RT_IFLIST	3		/* survey interface list */
281a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	NET_RT_MAXID	4
282a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
283a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define CTL_NET_RT_NAMES { \
284a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ 0, 0 }, \
285a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "dump", CTLTYPE_STRUCT }, \
286a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "flags", CTLTYPE_STRUCT }, \
287a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	{ "iflist", CTLTYPE_STRUCT }, \
288a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
289a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
290a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
291a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Maximum queue length specifiable by listen.
292a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
293a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#ifndef	SOMAXCONN
294a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SOMAXCONN	128
295a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#endif
296a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
297a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
298a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Message header for recvmsg and sendmsg calls.
299a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Used value-result for recvmsg, value only for sendmsg.
300a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
301a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)struct msghdr {
302a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	void		*msg_name;		/* optional address */
303a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	socklen_t	 msg_namelen;		/* size of address */
304a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	struct iovec	*msg_iov;		/* scatter/gather array */
305a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	int		 msg_iovlen;		/* # elements in msg_iov */
306a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	void		*msg_control;		/* ancillary data, see below */
307a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	socklen_t	 msg_controllen;	/* ancillary data buffer len */
308a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	int		 msg_flags;		/* flags on received message */
309a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
310a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
311a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	MSG_OOB		0x1		/* process out-of-band data */
312a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	MSG_PEEK	0x2		/* peek at incoming message */
313a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	MSG_DONTROUTE	0x4		/* send without using routing tables */
314a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	MSG_EOR		0x8		/* data completes record */
315a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	MSG_TRUNC	0x10		/* data discarded before delivery */
316a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	MSG_CTRUNC	0x20		/* control data lost before delivery */
317a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	MSG_WAITALL	0x40		/* wait for full request or error */
318a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	MSG_DONTWAIT	0x80		/* this message should be nonblocking */
319a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	MSG_EOF		0x100		/* data completes connection */
320a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define MSG_COMPAT      0x8000		/* used in sendit() */
321a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
322a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
323a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Header for ancillary data objects in msg_control buffer.
324a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Used for additional information with/about a datagram
325a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * not expressible by flags.  The format is a sequence
326a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * of message elements headed by cmsghdr structures.
327a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
328a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)struct cmsghdr {
329a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	socklen_t	cmsg_len;		/* data byte count, including hdr */
330a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	int		cmsg_level;		/* originating protocol */
331a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	int		cmsg_type;		/* protocol-specific type */
332a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/* followed by	unsigned char  cmsg_data[]; */
333a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
334a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
335a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
336a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * While we may have more groups than this, the cmsgcred struct must
337a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
338a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * this.
339a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)*/
340a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define CMGROUP_MAX 16
341a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
342a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
343a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * Credentials structure, used to verify the identity of a peer
344a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * process that has sent us a message. This is allocated by the
345a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * peer process but filled in by the kernel. This prevents the
346a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * peer from lying about its identity. (Note that cmcred_groups[0]
347a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * is the effective GID.)
348a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
349a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)struct cmsgcred {
350a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	pid_t	cmcred_pid;		/* PID of sending process */
351a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	uid_t	cmcred_uid;		/* real UID of sending process */
352a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	uid_t	cmcred_euid;		/* effective UID of sending process */
353a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	gid_t	cmcred_gid;		/* real GID of sending process */
354a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	short	cmcred_ngroups;		/* number or groups */
355a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	gid_t	cmcred_groups[CMGROUP_MAX];	/* groups */
356a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
357a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
3581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci/*
3591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * Round p (pointer or byte index) up to a correctly-aligned value
3601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * for all data types (int, long, ...).   The result is unsigned int
3611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * and must be cast to any desired pointer type.
3621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci */
3631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#ifndef _ALIGNBYTES
3641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define _ALIGNBYTES (sizeof(int) - 1)
3651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif
3661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#ifndef _ALIGN
3671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define _ALIGN(p) (((unsigned)(p) + _ALIGNBYTES) & ~_ALIGNBYTES)
3681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif
3691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
370a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/* given pointer to struct cmsghdr, return pointer to data */
371a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	CMSG_DATA(cmsg)		((unsigned char *)(cmsg) + \
372a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)				 _ALIGN(sizeof(struct cmsghdr)))
373a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
374a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
375a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	CMSG_NXTHDR(mhdr, cmsg)	\
376a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	(((caddr_t)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \
377a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	  _ALIGN(sizeof(struct cmsghdr)) > \
378a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	    (caddr_t)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
379a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	    (struct cmsghdr *)NULL : \
380a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	    (struct cmsghdr *)((caddr_t)(cmsg) + _ALIGN((cmsg)->cmsg_len)))
381a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
382a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	CMSG_FIRSTHDR(mhdr)	((struct cmsghdr *)(mhdr)->msg_control)
383a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
384a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/* RFC 2292 additions */
3851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
386a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	CMSG_SPACE(l)		(_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l))
387a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	CMSG_LEN(l)		(_ALIGN(sizeof(struct cmsghdr)) + (l))
388a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
389a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#ifdef _KERNEL
390a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	CMSG_ALIGN(n)	_ALIGN(n)
391a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#endif
392a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
393a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/* "Socket"-level control message types: */
394a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SCM_RIGHTS	0x01		/* access rights (array of int) */
395a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SCM_TIMESTAMP	0x02		/* timestamp (struct timeval) */
396a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SCM_CREDS	0x03		/* process creds (struct cmsgcred) */
397a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
398a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
399a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * 4.3 compat sockaddr, move to compat file later
400a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
401a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)struct osockaddr {
402a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	u_short	sa_family;		/* address family */
403a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	char	sa_data[14];		/* up to 14 bytes of direct address */
404a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
405a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
406a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
407a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * 4.3-compat message header (move to compat file later).
408a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
409a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)struct omsghdr {
410a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	caddr_t	msg_name;		/* optional address */
411a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	int	msg_namelen;		/* size of address */
412a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	struct	iovec *msg_iov;		/* scatter/gather array */
413a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	int	msg_iovlen;		/* # elements in msg_iov */
414a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	caddr_t	msg_accrights;		/* access rights sent/received */
415a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	int	msg_accrightslen;
416a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
417a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
418a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
419a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * howto arguments for shutdown(2), specified by Posix.1g.
420a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
421a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SHUT_RD		0		/* shut down the reading side */
422a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SHUT_WR		1		/* shut down the writing side */
423a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define	SHUT_RDWR	2		/* shut down both sides */
424a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
425a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)/*
426a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) * sendfile(2) header/trailer struct
427a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) */
428a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)struct sf_hdtr {
429a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	struct iovec *headers;	/* pointer to an array of header struct iovec's */
430a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	int hdr_cnt;		/* number of header iovec's */
431a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	struct iovec *trailers;	/* pointer to an array of trailer struct iovec's */
432a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	int trl_cnt;		/* number of trailer iovec's */
433a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
434a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
435a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include <sys/cdefs.h>
436a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
437a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)__BEGIN_DECLS
438a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)int	accept(int, struct sockaddr *, socklen_t *);
439a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)int	bind(int, const struct sockaddr *, socklen_t);
440a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)int	connect(int, const struct sockaddr *, socklen_t);
441a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)int	getpeername(int, struct sockaddr *, socklen_t *);
442a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)int	getsockname(int, struct sockaddr *, socklen_t *);
443a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)int	getsockopt(int, int, int, void *, socklen_t *);
444a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)int	listen(int, int);
445a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)ssize_t	recv(int, void *, size_t, int);
446a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)ssize_t	recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
447a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)ssize_t	recvmsg(int, struct msghdr *, int);
448a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)ssize_t	send(int, const void *, size_t, int);
449a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)ssize_t	sendto(int, const void *,
450a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)	    size_t, int, const struct sockaddr *, socklen_t);
451a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)ssize_t	sendmsg(int, const struct msghdr *, int);
452a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)int	sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int);
453a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)int	setsockopt(int, int, int, const void *, socklen_t);
454a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)int	shutdown(int, int);
455a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)int	socket(int, int, int);
456a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)int	socketpair(int, int, int, int *);
457a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)__END_DECLS
458a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
459a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#endif /* !_SYS_SOCKET_H_ */
460