xref: /freebsd/contrib/libpcap/rpcap-protocol.h (revision afdbf109c6a661a729938f68211054a0a50d38ac)
1b00ab754SHans Petter Selasky /*
2b00ab754SHans Petter Selasky  * Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
3b00ab754SHans Petter Selasky  * Copyright (c) 2005 - 2008 CACE Technologies, Davis (California)
4b00ab754SHans Petter Selasky  * All rights reserved.
5b00ab754SHans Petter Selasky  *
6b00ab754SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
7b00ab754SHans Petter Selasky  * modification, are permitted provided that the following conditions
8b00ab754SHans Petter Selasky  * are met:
9b00ab754SHans Petter Selasky  *
10b00ab754SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
11b00ab754SHans Petter Selasky  * notice, this list of conditions and the following disclaimer.
12b00ab754SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
13b00ab754SHans Petter Selasky  * notice, this list of conditions and the following disclaimer in the
14b00ab754SHans Petter Selasky  * documentation and/or other materials provided with the distribution.
15b00ab754SHans Petter Selasky  * 3. Neither the name of the Politecnico di Torino, CACE Technologies
16b00ab754SHans Petter Selasky  * nor the names of its contributors may be used to endorse or promote
17b00ab754SHans Petter Selasky  * products derived from this software without specific prior written
18b00ab754SHans Petter Selasky  * permission.
19b00ab754SHans Petter Selasky  *
20b00ab754SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21b00ab754SHans Petter Selasky  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22b00ab754SHans Petter Selasky  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23b00ab754SHans Petter Selasky  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24b00ab754SHans Petter Selasky  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25b00ab754SHans Petter Selasky  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26b00ab754SHans Petter Selasky  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27b00ab754SHans Petter Selasky  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28b00ab754SHans Petter Selasky  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29b00ab754SHans Petter Selasky  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30b00ab754SHans Petter Selasky  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31b00ab754SHans Petter Selasky  *
32b00ab754SHans Petter Selasky  */
33b00ab754SHans Petter Selasky 
34b00ab754SHans Petter Selasky #ifndef __RPCAP_PROTOCOL_H__
35b00ab754SHans Petter Selasky #define __RPCAP_PROTOCOL_H__
36b00ab754SHans Petter Selasky 
37b00ab754SHans Petter Selasky #define RPCAP_DEFAULT_NETPORT "2002" /* Default port on which the RPCAP daemon is waiting for connections. */
38b00ab754SHans Petter Selasky /* Default port on which the client workstation is waiting for connections in case of active mode. */
39b00ab754SHans Petter Selasky #define RPCAP_DEFAULT_NETPORT_ACTIVE "2003"
40b00ab754SHans Petter Selasky #define RPCAP_DEFAULT_NETADDR ""	/* Default network address on which the RPCAP daemon binds to. */
41b00ab754SHans Petter Selasky 
42b00ab754SHans Petter Selasky /*
43b00ab754SHans Petter Selasky  * Minimum and maximum supported versions of the protocol.
44b00ab754SHans Petter Selasky  *
45b00ab754SHans Petter Selasky  * If new message types are added, the protocol version MUST be changed,
46b00ab754SHans Petter Selasky  * so that a client knows, from the negotiated protocol version, what
47b00ab754SHans Petter Selasky  * messages can be sent to the server.
48b00ab754SHans Petter Selasky  *
49b00ab754SHans Petter Selasky  * If the format of an existing message type is changed, the protocol
50b00ab754SHans Petter Selasky  * version MUST be changed, so that each side knows, from the negotiated
51b00ab754SHans Petter Selasky  * protocol version, what format should be used.
52b00ab754SHans Petter Selasky  *
53b00ab754SHans Petter Selasky  * The RPCAP_MSG_ERROR format MUST not change, as it's used to, among
54b00ab754SHans Petter Selasky  * other things, report "incorrect version number" errors, where, if
55b00ab754SHans Petter Selasky  * the format changed, the sender of the message might not know what
56b00ab754SHans Petter Selasky  * versions the recipient would understand, or might know a version
57b00ab754SHans Petter Selasky  * they support (the version number they sent) but might not know
58b00ab754SHans Petter Selasky  * the format of the message in that version.
59b00ab754SHans Petter Selasky  *
60b00ab754SHans Petter Selasky  * Other message versions SHOULD not change, as that would complicate
61b00ab754SHans Petter Selasky  * the process of interpreting the message, making it version-dependent.
62b00ab754SHans Petter Selasky  * Introducing a new message with a new format is preferable.
63b00ab754SHans Petter Selasky  *
64b00ab754SHans Petter Selasky  * Version negotiation is done as part of the authentication process:
65b00ab754SHans Petter Selasky  *
6657e22627SCy Schubert  * The client sends an authentication request, with a version number
6757e22627SCy Schubert  * of 0.  All servers must accept authentication requests with a version
6857e22627SCy Schubert  * number of 0, even if they don't support version 0 for any other
6957e22627SCy Schubert  * requests.
70b00ab754SHans Petter Selasky  *
7157e22627SCy Schubert  * The server attempts to authenticate the client.  If that succeeds,
7257e22627SCy Schubert  * older servers - which only support version 0 - will send an
7357e22627SCy Schubert  * authentication reply with no payload.  Newer servers - which might
7457e22627SCy Schubert  * support other versions - will send an authentication reply with
7557e22627SCy Schubert  * a payload giving the minimum and maximum versions it supports.
76b00ab754SHans Petter Selasky  *
7757e22627SCy Schubert  * The client attempts to find the largest version number that is
7857e22627SCy Schubert  * in both its range of supported versions and the server's supported
7957e22627SCy Schubert  * versions.  If it fails, it gives up; otherwise, it uses that version.
80b00ab754SHans Petter Selasky  */
81b00ab754SHans Petter Selasky #define RPCAP_MIN_VERSION 0
82b00ab754SHans Petter Selasky #define RPCAP_MAX_VERSION 0
83b00ab754SHans Petter Selasky 
84b00ab754SHans Petter Selasky /*
85b00ab754SHans Petter Selasky  * Version numbers are unsigned, so if RPCAP_MIN_VERSION is 0, they
86b00ab754SHans Petter Selasky  * are >= the minimum version, by definition; don't check against
87b00ab754SHans Petter Selasky  * RPCAP_MIN_VERSION, as you may get compiler warnings that the
88b00ab754SHans Petter Selasky  * comparison will always succeed.
89b00ab754SHans Petter Selasky  */
90b00ab754SHans Petter Selasky #if RPCAP_MIN_VERSION == 0
9157e22627SCy Schubert #define RPCAP_VERSION_IS_SUPPORTED(v)	\
9257e22627SCy Schubert 	((v) <= RPCAP_MAX_VERSION)
93b00ab754SHans Petter Selasky #else
94b00ab754SHans Petter Selasky #define RPCAP_VERSION_IS_SUPPORTED(v)	\
95b00ab754SHans Petter Selasky 	((v) >= RPCAP_MIN_VERSION && (v) <= RPCAP_MAX_VERSION)
96b00ab754SHans Petter Selasky #endif
97b00ab754SHans Petter Selasky 
98b00ab754SHans Petter Selasky /*
99b00ab754SHans Petter Selasky  * Separators used for the host list.
100b00ab754SHans Petter Selasky  *
101b00ab754SHans Petter Selasky  * It is used:
102b00ab754SHans Petter Selasky  * - by the rpcapd daemon, when you types a list of allowed connecting hosts
103b00ab754SHans Petter Selasky  * - by the rpcap client in active mode, when the client waits for incoming
104b00ab754SHans Petter Selasky  * connections from other hosts
105b00ab754SHans Petter Selasky  */
106b00ab754SHans Petter Selasky #define RPCAP_HOSTLIST_SEP " ,;\n\r"
107b00ab754SHans Petter Selasky 
108b00ab754SHans Petter Selasky /*********************************************************
109b00ab754SHans Petter Selasky  *                                                       *
110b00ab754SHans Petter Selasky  * Protocol messages formats                             *
111b00ab754SHans Petter Selasky  *                                                       *
112b00ab754SHans Petter Selasky  *********************************************************/
113b00ab754SHans Petter Selasky /*
114b00ab754SHans Petter Selasky  * WARNING: This file defines some structures that are used to transfer
115b00ab754SHans Petter Selasky  * data on the network.
116b00ab754SHans Petter Selasky  * Note that your compiler MUST not insert padding into these structures
117b00ab754SHans Petter Selasky  * for better alignment.
118b00ab754SHans Petter Selasky  * These structures have been created in order to be correctly aligned to
119b00ab754SHans Petter Selasky  * a 32-bit boundary, but be careful in any case.
12057e22627SCy Schubert  *
12157e22627SCy Schubert  * The layout of these structures MUST not be changed.  If a packet
12257e22627SCy Schubert  * format is different in different versions of the protocol, versions
12357e22627SCy Schubert  * of the structure should be provided for all the different versions or
12457e22627SCy Schubert  * version ranges (if more than one version of the protocol has the same
12557e22627SCy Schubert  * layout) that we support.
126b00ab754SHans Petter Selasky  */
127b00ab754SHans Petter Selasky 
128b00ab754SHans Petter Selasky /*
129b00ab754SHans Petter Selasky  * WARNING: These typedefs MUST be of a specific size.
130b00ab754SHans Petter Selasky  * You might have to change them on your platform.
131b00ab754SHans Petter Selasky  *
132b00ab754SHans Petter Selasky  * XXX - use the C99 types?  Microsoft's newer versions of Visual Studio
133b00ab754SHans Petter Selasky  * support them.
134b00ab754SHans Petter Selasky  */
1356f9cba8fSJoseph Mingrone #ifndef __HAIKU__
136b00ab754SHans Petter Selasky typedef unsigned char uint8;	/* 8-bit unsigned integer */
137b00ab754SHans Petter Selasky typedef unsigned short uint16;	/* 16-bit unsigned integer */
138b00ab754SHans Petter Selasky typedef unsigned int uint32;	/* 32-bit unsigned integer */
139b00ab754SHans Petter Selasky typedef int int32;		/* 32-bit signed integer */
140*afdbf109SJoseph Mingrone #else
141*afdbf109SJoseph Mingrone #include <os/support/SupportDefs.h>
1426f9cba8fSJoseph Mingrone #endif
143b00ab754SHans Petter Selasky 
144b00ab754SHans Petter Selasky /* Common header for all the RPCAP messages */
145b00ab754SHans Petter Selasky struct rpcap_header
146b00ab754SHans Petter Selasky {
147b00ab754SHans Petter Selasky 	uint8 ver;	/* RPCAP version number */
148b00ab754SHans Petter Selasky 	uint8 type;	/* RPCAP message type (error, findalldevs, ...) */
149b00ab754SHans Petter Selasky 	uint16 value;	/* Message-dependent value (not always used) */
150b00ab754SHans Petter Selasky 	uint32 plen;	/* Length of the payload of this RPCAP message */
151b00ab754SHans Petter Selasky };
152b00ab754SHans Petter Selasky 
15357e22627SCy Schubert /*
15457e22627SCy Schubert  * Format of data that may appear at the end of an authentication reply,
15557e22627SCy Schubert  * giving the minimum and maximum versions of the protocol that the
15657e22627SCy Schubert  * server supports.
15757e22627SCy Schubert  *
15857e22627SCy Schubert  * Older servers don't provide this; they support only version 0.
15957e22627SCy Schubert  */
16057e22627SCy Schubert struct rpcap_authreply
16157e22627SCy Schubert {
16257e22627SCy Schubert 	uint8 minvers;			/* Minimum version supported */
16357e22627SCy Schubert 	uint8 maxvers;			/* Maximum version supported */
1646f9cba8fSJoseph Mingrone 	uint8 pad[2];			/* Pad to 4-byte boundary **/
1656f9cba8fSJoseph Mingrone 	uint32 byte_order_magic;	/* RPCAP_BYTE_ORDER_MAGIC, in server byte order */
1666f9cba8fSJoseph Mingrone };
1676f9cba8fSJoseph Mingrone 
1686f9cba8fSJoseph Mingrone /*
1696f9cba8fSJoseph Mingrone  * Any resemblance between this and the pcap file magic number
1706f9cba8fSJoseph Mingrone  * is purely coincidental, trust me.
1716f9cba8fSJoseph Mingrone  */
1726f9cba8fSJoseph Mingrone #define RPCAP_BYTE_ORDER_MAGIC		0xa1b2c3d4U
1736f9cba8fSJoseph Mingrone #define RPCAP_BYTE_ORDER_MAGIC_SWAPPED	0xd4c3b2a1U
1746f9cba8fSJoseph Mingrone 
1756f9cba8fSJoseph Mingrone /*
1766f9cba8fSJoseph Mingrone  * Older version of authentication reply, without byte order indication
1776f9cba8fSJoseph Mingrone  * and padding.
1786f9cba8fSJoseph Mingrone  */
1796f9cba8fSJoseph Mingrone struct rpcap_authreply_old
1806f9cba8fSJoseph Mingrone {
1816f9cba8fSJoseph Mingrone 	uint8 minvers;	/* Minimum version supported */
1826f9cba8fSJoseph Mingrone 	uint8 maxvers;	/* Maximum version supported */
18357e22627SCy Schubert };
18457e22627SCy Schubert 
185b00ab754SHans Petter Selasky /* Format of the message for the interface description (findalldevs command) */
186b00ab754SHans Petter Selasky struct rpcap_findalldevs_if
187b00ab754SHans Petter Selasky {
188b00ab754SHans Petter Selasky 	uint16 namelen;	/* Length of the interface name */
189b00ab754SHans Petter Selasky 	uint16 desclen;	/* Length of the interface description */
190b00ab754SHans Petter Selasky 	uint32 flags;	/* Interface flags */
191b00ab754SHans Petter Selasky 	uint16 naddr;	/* Number of addresses */
192b00ab754SHans Petter Selasky 	uint16 dummy;	/* Must be zero */
193b00ab754SHans Petter Selasky };
194b00ab754SHans Petter Selasky 
195b00ab754SHans Petter Selasky /*
196b00ab754SHans Petter Selasky  * Format of an address as sent over the wire.
197b00ab754SHans Petter Selasky  *
198b00ab754SHans Petter Selasky  * Do *NOT* use struct sockaddr_storage, as the layout for that is
199b00ab754SHans Petter Selasky  * machine-dependent.
200b00ab754SHans Petter Selasky  *
201b00ab754SHans Petter Selasky  * RFC 2553 gives two sample layouts, both of which are 128 bytes long,
202b00ab754SHans Petter Selasky  * both of which are aligned on an 8-byte boundary, and both of which
203b00ab754SHans Petter Selasky  * have 2 bytes before the address data.
204b00ab754SHans Petter Selasky  *
205b00ab754SHans Petter Selasky  * However, one has a 2-byte address family value at the beginning
206b00ab754SHans Petter Selasky  * and the other has a 1-byte address length value and a 1-byte
207b00ab754SHans Petter Selasky  * address family value; this reflects the fact that the original
208b00ab754SHans Petter Selasky  * BSD sockaddr structure had a 2-byte address family value, which
209b00ab754SHans Petter Selasky  * was later changed to a 1-byte address length value and a 1-byte
210b00ab754SHans Petter Selasky  * address family value, when support for variable-length OSI
211b00ab754SHans Petter Selasky  * network-layer addresses was added.
212b00ab754SHans Petter Selasky  *
213b00ab754SHans Petter Selasky  * Furthermore, Solaris's struct sockaddr_storage is 256 bytes
214b00ab754SHans Petter Selasky  * long.
215b00ab754SHans Petter Selasky  *
216b00ab754SHans Petter Selasky  * This structure is supposed to be aligned on an 8-byte boundary;
217b00ab754SHans Petter Selasky  * the message header is 8 bytes long, so we don't have to do
218b00ab754SHans Petter Selasky  * anything to ensure it's aligned on that boundary within a packet,
219b00ab754SHans Petter Selasky  * so we just define it as 128 bytes long, with a 2-byte address
220b00ab754SHans Petter Selasky  * family.  (We only support IPv4 and IPv6 addresses, which are fixed-
221b00ab754SHans Petter Selasky  * length.)  That way, it's the same size as sockaddr_storage on
222b00ab754SHans Petter Selasky  * Windows, and it'll look like what an older Windows client will
223b00ab754SHans Petter Selasky  * expect.
224b00ab754SHans Petter Selasky  *
225b00ab754SHans Petter Selasky  * In addition, do *NOT* use the host's AF_ value for an address,
226b00ab754SHans Petter Selasky  * as the value for AF_INET6 is machine-dependent.  We use the
227b00ab754SHans Petter Selasky  * Windows value, so it'll look like what an older Windows client
228b00ab754SHans Petter Selasky  * will expect.
229b00ab754SHans Petter Selasky  *
230b00ab754SHans Petter Selasky  * (The Windows client is the only one that has been distributed
231b00ab754SHans Petter Selasky  * as a standard part of *pcap; UN*X clients are probably built
232b00ab754SHans Petter Selasky  * from source by the user or administrator, so they're in a
233b00ab754SHans Petter Selasky  * better position to upgrade an old client.  Therefore, we
234b00ab754SHans Petter Selasky  * try to make what goes over the wire look like what comes
235b00ab754SHans Petter Selasky  * from a Windows server.)
236b00ab754SHans Petter Selasky  */
237b00ab754SHans Petter Selasky struct rpcap_sockaddr
238b00ab754SHans Petter Selasky {
239b00ab754SHans Petter Selasky 	uint16	family;			/* Address family */
240b00ab754SHans Petter Selasky 	char	data[128-2];		/* Data */
241b00ab754SHans Petter Selasky };
242b00ab754SHans Petter Selasky 
243b00ab754SHans Petter Selasky /*
244b00ab754SHans Petter Selasky  * Format of an IPv4 address as sent over the wire.
245b00ab754SHans Petter Selasky  */
246*afdbf109SJoseph Mingrone #define RPCAP_AF_INET	2		/* Value on all OSes except for Haiku */
247b00ab754SHans Petter Selasky struct rpcap_sockaddr_in
248b00ab754SHans Petter Selasky {
249b00ab754SHans Petter Selasky 	uint16	family;			/* Address family */
250b00ab754SHans Petter Selasky 	uint16	port;			/* Port number */
251b00ab754SHans Petter Selasky 	uint32	addr;			/* IPv4 address */
252b00ab754SHans Petter Selasky 	uint8	zero[8];		/* Padding */
253b00ab754SHans Petter Selasky };
254b00ab754SHans Petter Selasky 
255b00ab754SHans Petter Selasky /*
256b00ab754SHans Petter Selasky  * Format of an IPv6 address as sent over the wire.
257b00ab754SHans Petter Selasky  */
258b00ab754SHans Petter Selasky #define RPCAP_AF_INET6	23		/* Value on Windows */
259b00ab754SHans Petter Selasky struct rpcap_sockaddr_in6
260b00ab754SHans Petter Selasky {
261b00ab754SHans Petter Selasky 	uint16	family;			/* Address family */
262b00ab754SHans Petter Selasky 	uint16	port;			/* Port number */
263b00ab754SHans Petter Selasky 	uint32	flowinfo;		/* IPv6 flow information */
264b00ab754SHans Petter Selasky 	uint8	addr[16];		/* IPv6 address */
265b00ab754SHans Petter Selasky 	uint32	scope_id;		/* Scope zone index */
266b00ab754SHans Petter Selasky };
267b00ab754SHans Petter Selasky 
268b00ab754SHans Petter Selasky /* Format of the message for the address listing (findalldevs command) */
269b00ab754SHans Petter Selasky struct rpcap_findalldevs_ifaddr
270b00ab754SHans Petter Selasky {
271b00ab754SHans Petter Selasky 	struct rpcap_sockaddr addr;		/* Network address */
272b00ab754SHans Petter Selasky 	struct rpcap_sockaddr netmask;		/* Netmask for that address */
273b00ab754SHans Petter Selasky 	struct rpcap_sockaddr broadaddr;	/* Broadcast address for that address */
274b00ab754SHans Petter Selasky 	struct rpcap_sockaddr dstaddr;		/* P2P destination address for that address */
275b00ab754SHans Petter Selasky };
276b00ab754SHans Petter Selasky 
277b00ab754SHans Petter Selasky /*
278b00ab754SHans Petter Selasky  * \brief Format of the message of the connection opening reply (open command).
279b00ab754SHans Petter Selasky  *
280b00ab754SHans Petter Selasky  * This structure transfers over the network some of the values useful on the client side.
281b00ab754SHans Petter Selasky  */
282b00ab754SHans Petter Selasky struct rpcap_openreply
283b00ab754SHans Petter Selasky {
284b00ab754SHans Petter Selasky 	int32 linktype;	/* Link type */
2856f9cba8fSJoseph Mingrone 	int32 tzoff;	/* Timezone offset - not used by newer clients */
286b00ab754SHans Petter Selasky };
287b00ab754SHans Petter Selasky 
288b00ab754SHans Petter Selasky /* Format of the message that starts a remote capture (startcap command) */
289b00ab754SHans Petter Selasky struct rpcap_startcapreq
290b00ab754SHans Petter Selasky {
291b00ab754SHans Petter Selasky 	uint32 snaplen;		/* Length of the snapshot (number of bytes to capture for each packet) */
292b00ab754SHans Petter Selasky 	uint32 read_timeout;	/* Read timeout in milliseconds */
293b00ab754SHans Petter Selasky 	uint16 flags;		/* Flags (see RPCAP_STARTCAPREQ_FLAG_xxx) */
294b00ab754SHans Petter Selasky 	uint16 portdata;	/* Network port on which the client is waiting at (if 'serveropen') */
295b00ab754SHans Petter Selasky };
296b00ab754SHans Petter Selasky 
297b00ab754SHans Petter Selasky /* Format of the reply message that devoted to start a remote capture (startcap reply command) */
298b00ab754SHans Petter Selasky struct rpcap_startcapreply
299b00ab754SHans Petter Selasky {
300b00ab754SHans Petter Selasky 	int32 bufsize;		/* Size of the user buffer allocated by WinPcap; it can be different from the one we chose */
301b00ab754SHans Petter Selasky 	uint16 portdata;	/* Network port on which the server is waiting at (passive mode only) */
302b00ab754SHans Petter Selasky 	uint16 dummy;		/* Must be zero */
303b00ab754SHans Petter Selasky };
304b00ab754SHans Petter Selasky 
305b00ab754SHans Petter Selasky /*
306b00ab754SHans Petter Selasky  * \brief Format of the header which encapsulates captured packets when transmitted on the network.
307b00ab754SHans Petter Selasky  *
308b00ab754SHans Petter Selasky  * This message requires the general header as well, since we want to be able to exchange
309b00ab754SHans Petter Selasky  * more information across the network in the future (for example statistics, and kind like that).
310b00ab754SHans Petter Selasky  */
311b00ab754SHans Petter Selasky struct rpcap_pkthdr
312b00ab754SHans Petter Selasky {
3136f9cba8fSJoseph Mingrone 	/*
3146f9cba8fSJoseph Mingrone 	 * This protocol needs to be updated with a new version before
3156f9cba8fSJoseph Mingrone 	 * 2038-01-19 03:14:07 UTC.
3166f9cba8fSJoseph Mingrone 	 */
317b00ab754SHans Petter Selasky 	uint32 timestamp_sec;	/* 'struct timeval' compatible, it represents the 'tv_sec' field */
318b00ab754SHans Petter Selasky 	uint32 timestamp_usec;	/* 'struct timeval' compatible, it represents the 'tv_usec' field */
319b00ab754SHans Petter Selasky 	uint32 caplen;		/* Length of portion present in the capture */
3206f9cba8fSJoseph Mingrone 	uint32 len;		/* Real length of this packet (off wire) */
321b00ab754SHans Petter Selasky 	uint32 npkt;		/* Ordinal number of the packet (i.e. the first one captured has '1', the second one '2', etc) */
322b00ab754SHans Petter Selasky };
323b00ab754SHans Petter Selasky 
324b00ab754SHans Petter Selasky /* General header used for the pcap_setfilter() command; keeps just the number of BPF instructions */
325b00ab754SHans Petter Selasky struct rpcap_filter
326b00ab754SHans Petter Selasky {
327b00ab754SHans Petter Selasky 	uint16 filtertype;	/* type of the filter transferred (BPF instructions, ...) */
328b00ab754SHans Petter Selasky 	uint16 dummy;		/* Must be zero */
329b00ab754SHans Petter Selasky 	uint32 nitems;		/* Number of items contained into the filter (e.g. BPF instructions for BPF filters) */
330b00ab754SHans Petter Selasky };
331b00ab754SHans Petter Selasky 
3326f9cba8fSJoseph Mingrone /* Structure that keeps a single BPF instruction; it is repeated 'ninsn' times according to the 'rpcap_filterbpf' header */
333b00ab754SHans Petter Selasky struct rpcap_filterbpf_insn
334b00ab754SHans Petter Selasky {
335b00ab754SHans Petter Selasky 	uint16 code;	/* opcode of the instruction */
336b00ab754SHans Petter Selasky 	uint8 jt;	/* relative offset to jump to in case of 'true' */
337b00ab754SHans Petter Selasky 	uint8 jf;	/* relative offset to jump to in case of 'false' */
338b00ab754SHans Petter Selasky 	int32 k;	/* instruction-dependent value */
339b00ab754SHans Petter Selasky };
340b00ab754SHans Petter Selasky 
341b00ab754SHans Petter Selasky /* Structure that keeps the data required for the authentication on the remote host */
342b00ab754SHans Petter Selasky struct rpcap_auth
343b00ab754SHans Petter Selasky {
344b00ab754SHans Petter Selasky 	uint16 type;	/* Authentication type */
345b00ab754SHans Petter Selasky 	uint16 dummy;	/* Must be zero */
346b00ab754SHans Petter Selasky 	uint16 slen1;	/* Length of the first authentication item (e.g. username) */
347b00ab754SHans Petter Selasky 	uint16 slen2;	/* Length of the second authentication item (e.g. password) */
348b00ab754SHans Petter Selasky };
349b00ab754SHans Petter Selasky 
350b00ab754SHans Petter Selasky /* Structure that keeps the statistics about the number of packets captured, dropped, etc. */
351b00ab754SHans Petter Selasky struct rpcap_stats
352b00ab754SHans Petter Selasky {
353b00ab754SHans Petter Selasky 	uint32 ifrecv;		/* Packets received by the kernel filter (i.e. pcap_stats.ps_recv) */
354b00ab754SHans Petter Selasky 	uint32 ifdrop;		/* Packets dropped by the network interface (e.g. not enough buffers) (i.e. pcap_stats.ps_ifdrop) */
355b00ab754SHans Petter Selasky 	uint32 krnldrop;	/* Packets dropped by the kernel filter (i.e. pcap_stats.ps_drop) */
356b00ab754SHans Petter Selasky 	uint32 svrcapt;		/* Packets captured by the RPCAP daemon and sent on the network */
357b00ab754SHans Petter Selasky };
358b00ab754SHans Petter Selasky 
359b00ab754SHans Petter Selasky /* Structure that is needed to set sampling parameters */
360b00ab754SHans Petter Selasky struct rpcap_sampling
361b00ab754SHans Petter Selasky {
362b00ab754SHans Petter Selasky 	uint8 method;	/* Sampling method */
363b00ab754SHans Petter Selasky 	uint8 dummy1;	/* Must be zero */
364b00ab754SHans Petter Selasky 	uint16 dummy2;	/* Must be zero */
365b00ab754SHans Petter Selasky 	uint32 value;	/* Parameter related to the sampling method */
366b00ab754SHans Petter Selasky };
367b00ab754SHans Petter Selasky 
36857e22627SCy Schubert /*
36957e22627SCy Schubert  * Messages field coding.
37057e22627SCy Schubert  *
37157e22627SCy Schubert  * These values are used in messages sent over the network, and MUST
37257e22627SCy Schubert  * not be changed.
37357e22627SCy Schubert  */
374b00ab754SHans Petter Selasky #define RPCAP_MSG_IS_REPLY		0x080	/* Flag indicating a reply */
375b00ab754SHans Petter Selasky 
3766f9cba8fSJoseph Mingrone #define RPCAP_MSG_ERROR			0x01	/* Message that keeps an error notification */
3776f9cba8fSJoseph Mingrone #define RPCAP_MSG_FINDALLIF_REQ		0x02	/* Request to list all the remote interfaces */
3786f9cba8fSJoseph Mingrone #define RPCAP_MSG_OPEN_REQ		0x03	/* Request to open a remote device */
3796f9cba8fSJoseph Mingrone #define RPCAP_MSG_STARTCAP_REQ		0x04	/* Request to start a capture on a remote device */
3806f9cba8fSJoseph Mingrone #define RPCAP_MSG_UPDATEFILTER_REQ	0x05	/* Send a compiled filter into the remote device */
3816f9cba8fSJoseph Mingrone #define RPCAP_MSG_CLOSE			0x06	/* Close the connection with the remote peer */
3826f9cba8fSJoseph Mingrone #define RPCAP_MSG_PACKET		0x07	/* This is a 'data' message, which carries a network packet */
3836f9cba8fSJoseph Mingrone #define RPCAP_MSG_AUTH_REQ		0x08	/* Message that keeps the authentication parameters */
3846f9cba8fSJoseph Mingrone #define RPCAP_MSG_STATS_REQ		0x09	/* It requires to have network statistics */
3856f9cba8fSJoseph Mingrone #define RPCAP_MSG_ENDCAP_REQ		0x0A	/* Stops the current capture, keeping the device open */
3866f9cba8fSJoseph Mingrone #define RPCAP_MSG_SETSAMPLING_REQ	0x0B	/* Set sampling parameters */
387b00ab754SHans Petter Selasky 
388b00ab754SHans Petter Selasky #define RPCAP_MSG_FINDALLIF_REPLY	(RPCAP_MSG_FINDALLIF_REQ | RPCAP_MSG_IS_REPLY)		/* Keeps the list of all the remote interfaces */
389b00ab754SHans Petter Selasky #define RPCAP_MSG_OPEN_REPLY		(RPCAP_MSG_OPEN_REQ | RPCAP_MSG_IS_REPLY)		/* The remote device has been opened correctly */
390b00ab754SHans Petter Selasky #define RPCAP_MSG_STARTCAP_REPLY	(RPCAP_MSG_STARTCAP_REQ | RPCAP_MSG_IS_REPLY)		/* The capture is starting correctly */
391b00ab754SHans Petter Selasky #define RPCAP_MSG_UPDATEFILTER_REPLY	(RPCAP_MSG_UPDATEFILTER_REQ | RPCAP_MSG_IS_REPLY)	/* The filter has been applied correctly on the remote device */
392b00ab754SHans Petter Selasky #define RPCAP_MSG_AUTH_REPLY		(RPCAP_MSG_AUTH_REQ | RPCAP_MSG_IS_REPLY)		/* Sends a message that says 'ok, authorization successful' */
393b00ab754SHans Petter Selasky #define RPCAP_MSG_STATS_REPLY		(RPCAP_MSG_STATS_REQ | RPCAP_MSG_IS_REPLY)		/* Message that keeps the network statistics */
394b00ab754SHans Petter Selasky #define RPCAP_MSG_ENDCAP_REPLY		(RPCAP_MSG_ENDCAP_REQ | RPCAP_MSG_IS_REPLY)		/* Confirms that the capture stopped successfully */
395b00ab754SHans Petter Selasky #define RPCAP_MSG_SETSAMPLING_REPLY	(RPCAP_MSG_SETSAMPLING_REQ | RPCAP_MSG_IS_REPLY)		/* Confirms that the capture stopped successfully */
396b00ab754SHans Petter Selasky 
397b00ab754SHans Petter Selasky #define RPCAP_STARTCAPREQ_FLAG_PROMISC		0x00000001	/* Enables promiscuous mode (default: disabled) */
398b00ab754SHans Petter Selasky #define RPCAP_STARTCAPREQ_FLAG_DGRAM		0x00000002	/* Use a datagram (i.e. UDP) connection for the data stream (default: use TCP)*/
399b00ab754SHans Petter Selasky #define RPCAP_STARTCAPREQ_FLAG_SERVEROPEN	0x00000004	/* The server has to open the data connection toward the client */
400b00ab754SHans Petter Selasky #define RPCAP_STARTCAPREQ_FLAG_INBOUND		0x00000008	/* Capture only inbound packets (take care: the flag has no effect with promiscuous enabled) */
401b00ab754SHans Petter Selasky #define RPCAP_STARTCAPREQ_FLAG_OUTBOUND		0x00000010	/* Capture only outbound packets (take care: the flag has no effect with promiscuous enabled) */
402b00ab754SHans Petter Selasky 
403b00ab754SHans Petter Selasky #define RPCAP_UPDATEFILTER_BPF 1			/* This code tells us that the filter is encoded with the BPF/NPF syntax */
404b00ab754SHans Petter Selasky 
40557e22627SCy Schubert /*
40657e22627SCy Schubert  * Network error codes.
40757e22627SCy Schubert  *
40857e22627SCy Schubert  * These values are used in messages sent over the network, and MUST
40957e22627SCy Schubert  * not be changed.
41057e22627SCy Schubert  */
411b00ab754SHans Petter Selasky #define PCAP_ERR_NETW			1	/* Network error */
412b00ab754SHans Petter Selasky #define PCAP_ERR_INITTIMEOUT		2	/* The RPCAP initial timeout has expired */
413b00ab754SHans Petter Selasky #define PCAP_ERR_AUTH			3	/* Generic authentication error */
414b00ab754SHans Petter Selasky #define PCAP_ERR_FINDALLIF		4	/* Generic findalldevs error */
415b00ab754SHans Petter Selasky #define PCAP_ERR_NOREMOTEIF		5	/* The findalldevs was ok, but the remote end had no interfaces to list */
416b00ab754SHans Petter Selasky #define PCAP_ERR_OPEN			6	/* Generic pcap_open error */
417b00ab754SHans Petter Selasky #define PCAP_ERR_UPDATEFILTER		7	/* Generic updatefilter error */
418b00ab754SHans Petter Selasky #define PCAP_ERR_GETSTATS		8	/* Generic pcap_stats error */
419b00ab754SHans Petter Selasky #define PCAP_ERR_READEX			9	/* Generic pcap_next_ex error */
420b00ab754SHans Petter Selasky #define PCAP_ERR_HOSTNOAUTH		10	/* The host is not authorized to connect to this server */
421b00ab754SHans Petter Selasky #define PCAP_ERR_REMOTEACCEPT		11	/* Generic pcap_remoteaccept error */
422b00ab754SHans Petter Selasky #define PCAP_ERR_STARTCAPTURE		12	/* Generic pcap_startcapture error */
423b00ab754SHans Petter Selasky #define PCAP_ERR_ENDCAPTURE		13	/* Generic pcap_endcapture error */
424b00ab754SHans Petter Selasky #define PCAP_ERR_RUNTIMETIMEOUT		14	/* The RPCAP run-time timeout has expired */
425b00ab754SHans Petter Selasky #define PCAP_ERR_SETSAMPLING		15	/* Error during the settings of sampling parameters */
426b00ab754SHans Petter Selasky #define PCAP_ERR_WRONGMSG		16	/* The other end endpoint sent a message which has not been recognized */
427b00ab754SHans Petter Selasky #define PCAP_ERR_WRONGVER		17	/* The other end endpoint has a version number that is not compatible with our */
42857e22627SCy Schubert #define PCAP_ERR_AUTH_FAILED		18	/* The user couldn't be authenticated */
42957e22627SCy Schubert #define PCAP_ERR_TLS_REQUIRED		19	/* The server requires TLS to connect */
43057e22627SCy Schubert #define PCAP_ERR_AUTH_TYPE_NOTSUP	20	/* The authentication type isn't supported */
431b00ab754SHans Petter Selasky 
432b00ab754SHans Petter Selasky /*
433b00ab754SHans Petter Selasky  * \brief Buffer used by socket functions to send-receive packets.
434b00ab754SHans Petter Selasky  * In case you plan to have messages larger than this value, you have to increase it.
435b00ab754SHans Petter Selasky  */
436b00ab754SHans Petter Selasky #define RPCAP_NETBUF_SIZE 64000
437b00ab754SHans Petter Selasky 
438b00ab754SHans Petter Selasky /*********************************************************
439b00ab754SHans Petter Selasky  *                                                       *
440b00ab754SHans Petter Selasky  * Routines used by the rpcap client and rpcap daemon    *
441b00ab754SHans Petter Selasky  *                                                       *
442b00ab754SHans Petter Selasky  *********************************************************/
443b00ab754SHans Petter Selasky 
444b00ab754SHans Petter Selasky #include "sockutils.h"
4456f9cba8fSJoseph Mingrone #include "sslutils.h"
446b00ab754SHans Petter Selasky 
447b00ab754SHans Petter Selasky extern void rpcap_createhdr(struct rpcap_header *header, uint8 ver, uint8 type, uint16 value, uint32 length);
448b00ab754SHans Petter Selasky extern const char *rpcap_msg_type_string(uint8 type);
449*afdbf109SJoseph Mingrone extern int rpcap_senderror(PCAP_SOCKET sock, SSL *ssl, uint8 ver, uint16 errcode, const char *error, char *errbuf);
450b00ab754SHans Petter Selasky 
451b00ab754SHans Petter Selasky #endif
452