]> The Tcpdump Group git mirrors - libpcap/blob - rpcap-protocol.h
Clean up the ether_hostton() stuff.
[libpcap] / rpcap-protocol.h
1 /*
2 * Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
3 * Copyright (c) 2005 - 2008 CACE Technologies, Davis (California)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Politecnico di Torino, CACE Technologies
16 * nor the names of its contributors may be used to endorse or promote
17 * products derived from this software without specific prior written
18 * permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 #ifndef __RPCAP_PROTOCOL_H__
35 #define __RPCAP_PROTOCOL_H__
36
37 #define RPCAP_DEFAULT_NETPORT "2002" /* Default port on which the RPCAP daemon is waiting for connections. */
38 /* Default port on which the client workstation is waiting for connections in case of active mode. */
39 #define RPCAP_DEFAULT_NETPORT_ACTIVE "2003"
40 #define RPCAP_DEFAULT_NETADDR "" /* Default network address on which the RPCAP daemon binds to. */
41 #define RPCAP_VERSION 0 /* Present version of the RPCAP protocol (0 = Experimental). */
42
43 /*
44 * Separators used for the host list.
45 *
46 * It is used:
47 * - by the rpcapd daemon, when you types a list of allowed connecting hosts
48 * - by the rpcap client in active mode, when the client waits for incoming
49 * connections from other hosts
50 */
51 #define RPCAP_HOSTLIST_SEP " ,;\n\r"
52
53 /*********************************************************
54 * *
55 * Protocol messages formats *
56 * *
57 *********************************************************/
58 /*
59 * WARNING: This file defines some structures that are used to transfer
60 * data on the network.
61 * Note that your compiler MUST not insert padding into these structures
62 * for better alignment.
63 * These structures have been created in order to be correctly aligned to
64 * a 32-bit boundary, but be careful in any case.
65 */
66
67 /*
68 * WARNING: These typedefs MUST be of a specific size.
69 * You might have to change them on your platform.
70 *
71 * XXX - use the C99 types? Microsoft's newer versions of Visual Studio
72 * support them.
73 */
74 typedef unsigned char uint8; /* 8-bit unsigned integer */
75 typedef unsigned short uint16; /* 16-bit unsigned integer */
76 typedef unsigned int uint32; /* 32-bit unsigned integer */
77 typedef int int32; /* 32-bit signed integer */
78
79 /* Common header for all the RPCAP messages */
80 struct rpcap_header
81 {
82 uint8 ver; /* RPCAP version number */
83 uint8 type; /* RPCAP message type (error, findalldevs, ...) */
84 uint16 value; /* Message-dependent value (not always used) */
85 uint32 plen; /* Length of the payload of this RPCAP message */
86 };
87
88 /* Format of the message for the interface description (findalldevs command) */
89 struct rpcap_findalldevs_if
90 {
91 uint16 namelen; /* Length of the interface name */
92 uint16 desclen; /* Length of the interface description */
93 uint32 flags; /* Interface flags */
94 uint16 naddr; /* Number of addresses */
95 uint16 dummy; /* Must be zero */
96 };
97
98 /*
99 * Format of an address as sent over the wire.
100 *
101 * Do *NOT* use struct sockaddr_storage, as the layout for that is
102 * machine-dependent.
103 *
104 * RFC 2553 gives two sample layouts, both of which are 128 bytes long,
105 * both of which are aligned on an 8-byte boundary, and both of which
106 * have 2 bytes before the address data.
107 *
108 * However, one has a 2-byte address family value at the beginning
109 * and the other has a 1-byte address length value and a 1-byte
110 * address family value; this reflects the fact that the original
111 * BSD sockaddr structure had a 2-byte address family value, which
112 * was later changed to a 1-byte address length value and a 1-byte
113 * address family value, when support for variable-length OSI
114 * network-layer addresses was added.
115 *
116 * Furthermore, Solaris's struct sockaddr_storage is 256 bytes
117 * long.
118 *
119 * This structure is supposed to be aligned on an 8-byte boundary;
120 * the message header is 8 bytes long, so we don't have to do
121 * anything to ensure it's aligned on that boundary within a packet,
122 * so we just define it as 128 bytes long, with a 2-byte address
123 * family. (We only support IPv4 and IPv6 addresses, which are fixed-
124 * length.) That way, it's the same size as sockaddr_storage on
125 * Windows, and it'll look like what an older Windows client will
126 * expect.
127 *
128 * In addition, do *NOT* use the host's AF_ value for an address,
129 * as the value for AF_INET6 is machine-dependent. We use the
130 * Windows value, so it'll look like what an older Windows client
131 * will expect.
132 *
133 * (The Windows client is the only one that has been distributed
134 * as a standard part of *pcap; UN*X clients are probably built
135 * from source by the user or administrator, so they're in a
136 * better position to upgrade an old client. Therefore, we
137 * try to make what goes over the wire look like what comes
138 * from a Windows server.)
139 */
140 struct rpcap_sockaddr
141 {
142 uint16 family; /* Address family */
143 char data[128-2]; /* Data */
144 };
145
146 /*
147 * Format of an IPv4 address as sent over the wire.
148 */
149 #define RPCAP_AF_INET 2 /* Value on all OSes */
150 struct rpcap_sockaddr_in
151 {
152 uint16 family; /* Address family */
153 uint16 port; /* Port number */
154 uint32 addr; /* IPv4 address */
155 uint8 zero[8]; /* Padding */
156 };
157
158 /*
159 * Format of an IPv6 address as sent over the wire.
160 */
161 #define RPCAP_AF_INET6 23 /* Value on Windows */
162 struct rpcap_sockaddr_in6
163 {
164 uint16 family; /* Address family */
165 uint16 port; /* Port number */
166 uint32 flowinfo; /* IPv6 flow information */
167 uint8 addr[16]; /* IPv6 address */
168 uint32 scope_id; /* Scope zone index */
169 };
170
171 /* Format of the message for the address listing (findalldevs command) */
172 struct rpcap_findalldevs_ifaddr
173 {
174 struct rpcap_sockaddr addr; /* Network address */
175 struct rpcap_sockaddr netmask; /* Netmask for that address */
176 struct rpcap_sockaddr broadaddr; /* Broadcast address for that address */
177 struct rpcap_sockaddr dstaddr; /* P2P destination address for that address */
178 };
179
180 /*
181 * \brief Format of the message of the connection opening reply (open command).
182 *
183 * This structure transfers over the network some of the values useful on the client side.
184 */
185 struct rpcap_openreply
186 {
187 int32 linktype; /* Link type */
188 int32 tzoff; /* Timezone offset */
189 };
190
191 /* Format of the message that starts a remote capture (startcap command) */
192 struct rpcap_startcapreq
193 {
194 uint32 snaplen; /* Length of the snapshot (number of bytes to capture for each packet) */
195 uint32 read_timeout; /* Read timeout in milliseconds */
196 uint16 flags; /* Flags (see RPCAP_STARTCAPREQ_FLAG_xxx) */
197 uint16 portdata; /* Network port on which the client is waiting at (if 'serveropen') */
198 };
199
200 /* Format of the reply message that devoted to start a remote capture (startcap reply command) */
201 struct rpcap_startcapreply
202 {
203 int32 bufsize; /* Size of the user buffer allocated by WinPcap; it can be different from the one we chose */
204 uint16 portdata; /* Network port on which the server is waiting at (passive mode only) */
205 uint16 dummy; /* Must be zero */
206 };
207
208 /*
209 * \brief Format of the header which encapsulates captured packets when transmitted on the network.
210 *
211 * This message requires the general header as well, since we want to be able to exchange
212 * more information across the network in the future (for example statistics, and kind like that).
213 */
214 struct rpcap_pkthdr
215 {
216 uint32 timestamp_sec; /* 'struct timeval' compatible, it represents the 'tv_sec' field */
217 uint32 timestamp_usec; /* 'struct timeval' compatible, it represents the 'tv_usec' field */
218 uint32 caplen; /* Length of portion present in the capture */
219 uint32 len; /* Real length this packet (off wire) */
220 uint32 npkt; /* Ordinal number of the packet (i.e. the first one captured has '1', the second one '2', etc) */
221 };
222
223 /* General header used for the pcap_setfilter() command; keeps just the number of BPF instructions */
224 struct rpcap_filter
225 {
226 uint16 filtertype; /* type of the filter transferred (BPF instructions, ...) */
227 uint16 dummy; /* Must be zero */
228 uint32 nitems; /* Number of items contained into the filter (e.g. BPF instructions for BPF filters) */
229 };
230
231 /* Structure that keeps a single BPF instuction; it is repeated 'ninsn' times according to the 'rpcap_filterbpf' header */
232 struct rpcap_filterbpf_insn
233 {
234 uint16 code; /* opcode of the instruction */
235 uint8 jt; /* relative offset to jump to in case of 'true' */
236 uint8 jf; /* relative offset to jump to in case of 'false' */
237 int32 k; /* instruction-dependent value */
238 };
239
240 /* Structure that keeps the data required for the authentication on the remote host */
241 struct rpcap_auth
242 {
243 uint16 type; /* Authentication type */
244 uint16 dummy; /* Must be zero */
245 uint16 slen1; /* Length of the first authentication item (e.g. username) */
246 uint16 slen2; /* Length of the second authentication item (e.g. password) */
247 };
248
249 /* Structure that keeps the statistics about the number of packets captured, dropped, etc. */
250 struct rpcap_stats
251 {
252 uint32 ifrecv; /* Packets received by the kernel filter (i.e. pcap_stats.ps_recv) */
253 uint32 ifdrop; /* Packets dropped by the network interface (e.g. not enough buffers) (i.e. pcap_stats.ps_ifdrop) */
254 uint32 krnldrop; /* Packets dropped by the kernel filter (i.e. pcap_stats.ps_drop) */
255 uint32 svrcapt; /* Packets captured by the RPCAP daemon and sent on the network */
256 };
257
258 /* Structure that is needed to set sampling parameters */
259 struct rpcap_sampling
260 {
261 uint8 method; /* Sampling method */
262 uint8 dummy1; /* Must be zero */
263 uint16 dummy2; /* Must be zero */
264 uint32 value; /* Parameter related to the sampling method */
265 };
266
267 /* Messages field coding */
268 #define RPCAP_MSG_ERROR 1 /* Message that keeps an error notification */
269 #define RPCAP_MSG_FINDALLIF_REQ 2 /* Request to list all the remote interfaces */
270 #define RPCAP_MSG_OPEN_REQ 3 /* Request to open a remote device */
271 #define RPCAP_MSG_STARTCAP_REQ 4 /* Request to start a capture on a remote device */
272 #define RPCAP_MSG_UPDATEFILTER_REQ 5 /* Send a compiled filter into the remote device */
273 #define RPCAP_MSG_CLOSE 6 /* Close the connection with the remote peer */
274 #define RPCAP_MSG_PACKET 7 /* This is a 'data' message, which carries a network packet */
275 #define RPCAP_MSG_AUTH_REQ 8 /* Message that keeps the authentication parameters */
276 #define RPCAP_MSG_STATS_REQ 9 /* It requires to have network statistics */
277 #define RPCAP_MSG_ENDCAP_REQ 10 /* Stops the current capture, keeping the device open */
278 #define RPCAP_MSG_SETSAMPLING_REQ 11 /* Set sampling parameters */
279
280 #define RPCAP_MSG_FINDALLIF_REPLY (128+RPCAP_MSG_FINDALLIF_REQ) /* Keeps the list of all the remote interfaces */
281 #define RPCAP_MSG_OPEN_REPLY (128+RPCAP_MSG_OPEN_REQ) /* The remote device has been opened correctly */
282 #define RPCAP_MSG_STARTCAP_REPLY (128+RPCAP_MSG_STARTCAP_REQ) /* The capture is starting correctly */
283 #define RPCAP_MSG_UPDATEFILTER_REPLY (128+RPCAP_MSG_UPDATEFILTER_REQ) /* The filter has been applied correctly on the remote device */
284 #define RPCAP_MSG_AUTH_REPLY (128+RPCAP_MSG_AUTH_REQ) /* Sends a message that says 'ok, authorization successful' */
285 #define RPCAP_MSG_STATS_REPLY (128+RPCAP_MSG_STATS_REQ) /* Message that keeps the network statistics */
286 #define RPCAP_MSG_ENDCAP_REPLY (128+RPCAP_MSG_ENDCAP_REQ) /* Confirms that the capture stopped successfully */
287 #define RPCAP_MSG_SETSAMPLING_REPLY (128+RPCAP_MSG_SETSAMPLING_REQ) /* Confirms that the capture stopped successfully */
288
289 #define RPCAP_STARTCAPREQ_FLAG_PROMISC 0x00000001 /* Enables promiscuous mode (default: disabled) */
290 #define RPCAP_STARTCAPREQ_FLAG_DGRAM 0x00000002 /* Use a datagram (i.e. UDP) connection for the data stream (default: use TCP)*/
291 #define RPCAP_STARTCAPREQ_FLAG_SERVEROPEN 0x00000004 /* The server has to open the data connection toward the client */
292 #define RPCAP_STARTCAPREQ_FLAG_INBOUND 0x00000008 /* Capture only inbound packets (take care: the flag has no effect with promiscuous enabled) */
293 #define RPCAP_STARTCAPREQ_FLAG_OUTBOUND 0x00000010 /* Capture only outbound packets (take care: the flag has no effect with promiscuous enabled) */
294
295 #define RPCAP_UPDATEFILTER_BPF 1 /* This code tells us that the filter is encoded with the BPF/NPF syntax */
296
297 /* Network error codes */
298 #define PCAP_ERR_NETW 1 /* Network error */
299 #define PCAP_ERR_INITTIMEOUT 2 /* The RPCAP initial timeout has expired */
300 #define PCAP_ERR_AUTH 3 /* Generic authentication error */
301 #define PCAP_ERR_FINDALLIF 4 /* Generic findalldevs error */
302 #define PCAP_ERR_NOREMOTEIF 5 /* The findalldevs was ok, but the remote end had no interfaces to list */
303 #define PCAP_ERR_OPEN 6 /* Generic pcap_open error */
304 #define PCAP_ERR_UPDATEFILTER 7 /* Generic updatefilter error */
305 #define PCAP_ERR_GETSTATS 8 /* Generic pcap_stats error */
306 #define PCAP_ERR_READEX 9 /* Generic pcap_next_ex error */
307 #define PCAP_ERR_HOSTNOAUTH 10 /* The host is not authorized to connect to this server */
308 #define PCAP_ERR_REMOTEACCEPT 11 /* Generic pcap_remoteaccept error */
309 #define PCAP_ERR_STARTCAPTURE 12 /* Generic pcap_startcapture error */
310 #define PCAP_ERR_ENDCAPTURE 13 /* Generic pcap_endcapture error */
311 #define PCAP_ERR_RUNTIMETIMEOUT 14 /* The RPCAP run-time timeout has expired */
312 #define PCAP_ERR_SETSAMPLING 15 /* Error during the settings of sampling parameters */
313 #define PCAP_ERR_WRONGMSG 16 /* The other end endpoint sent a message which has not been recognized */
314 #define PCAP_ERR_WRONGVER 17 /* The other end endpoint has a version number that is not compatible with our */
315
316 #endif