add winpcap 4.0.2 from url http://www.winpcap.org/
[natblaster.git] / winpcap / wpcap / libpcap / pcap-remote.h
blob60dc76369678dfa1a0a35cf44f1c30d24457630c
1 /*
2 * Copyright (c) 2002 - 2003
3 * NetGroup, Politecnico di Torino (Italy)
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 nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef __PCAP_REMOTE_H__
34 #define __PCAP_REMOTE_H__
37 #include "pcap.h"
38 #include "sockutils.h" // Needed for some structures (like SOCKET, sockaddr_in) which are used here
41 /*!
42 \file pcap-remote.h
44 This file keeps all the new definitions and typedefs that are exported to the user and
45 that are needed for the RPCAP protocol.
47 \warning All the RPCAP functions that are allowed to return a buffer containing
48 the error description can return max PCAP_ERRBUF_SIZE characters.
49 However there is no guarantees that the string will be zero-terminated.
50 Best practice is to define the errbuf variable as a char of size 'PCAP_ERRBUF_SIZE+1'
51 and to insert manually the termination char at the end of the buffer. This will
52 guarantee that no buffer overflows occur even if we use the printf() to show
53 the error on the screen.
55 \warning This file declares some typedefs that MUST be of a specific size.
56 These definitions (i.e. typedefs) could need to be changed on other platforms than
57 Intel IA32.
59 \warning This file defines some structures that are used to transfer data on the network.
60 Be careful that you compiler MUST not insert padding into these structures
61 for better alignment.
62 These structures have been created in order to be correctly aligned to a 32 bits
63 boundary, but be careful in any case.
73 /*********************************************************
74 * *
75 * General definitions / typedefs for the RPCAP protocol *
76 * *
77 *********************************************************/
79 // All the following structures and typedef belongs to the Private Documentation
80 /*! \addtogroup remote_pri_struct
84 #define RPCAP_DEFAULT_NETPORT "2002" /*!< Default port on which the RPCAP daemon is waiting for connections. */
85 /*! Default port on which the client workstation is waiting for connections in case of active mode. */
86 #define RPCAP_DEFAULT_NETPORT_ACTIVE "2003"
87 #define RPCAP_DEFAULT_NETADDR "" /*!< Default network address on which the RPCAP daemon binds to. */
88 #define RPCAP_VERSION 0 /*!< Present version of the RPCAP protocol (0 = Experimental). */
89 #define RPCAP_TIMEOUT_INIT 90 /*!< Initial timeout for RPCAP connections (default: 90 sec) */
90 #define RPCAP_TIMEOUT_RUNTIME 180 /*!< Run-time timeout for RPCAP connections (default: 3 min) */
91 #define RPCAP_ACTIVE_WAIT 30 /*!< Waiting time betweek two attempts to open a connection, in active mode (default: 30 sec) */
92 #define RPCAP_SUSPEND_WRONGAUTH 1 /*!< If the authentication is wrong, stops 1 sec before accepting a new auth message */
94 /*!
95 \brief Buffer used by socket functions to send-receive packets.
96 In case you plan to have messages larger than this value, you have to increase it.
98 #define RPCAP_NETBUF_SIZE 64000
102 \brief Separators used for the host list.
104 It is used:
105 - by the rpcapd daemon, when you types a list of allowed connecting hosts
106 - by the rpcap in active mode, when the client waits for incoming connections from other hosts
108 #define RPCAP_HOSTLIST_SEP " ,;\n\r"
113 // WARNING: These could need to be changed on other platforms
114 typedef unsigned char uint8; //!< Provides an 8-bits unsigned integer
115 typedef unsigned short uint16; //!< Provides a 16-bits unsigned integer
116 typedef unsigned int uint32; //!< Provides a 32-bits unsigned integer
117 typedef int int32; //!< Provides a 32-bits integer
123 \brief Keeps a list of all the opened connections in the active mode.
125 This structure defines a linked list of items that are needed to keep the info required to
126 manage the active mode.
127 In other words, when a new connection in active mode starts, this structure is updated so that
128 it reflects the list of active mode connections currently opened.
129 This structure is required by findalldevs() and open_remote() to see if they have to open a new
130 control connection toward the host, or they already have a control connection in place.
132 struct activehosts
134 struct sockaddr_storage host;
135 SOCKET sockctrl;
136 struct activehosts *next;
140 /*********************************************************
142 * Protocol messages formats *
144 *********************************************************/
145 // WARNING Take care you compiler does not insert padding for better alignments into these structs
148 //! Common header for all the RPCAP messages
149 struct rpcap_header
151 uint8 ver; //!< RPCAP version number
152 uint8 type; //!< RPCAP message type (error, findalldevs, ...)
153 uint16 value; //!< Message-dependent value (not always used)
154 uint32 plen; //!< Length of the payload of this RPCAP message
158 //! Format of the message for the interface description (findalldevs command)
159 struct rpcap_findalldevs_if
161 uint16 namelen; //!< Length of the interface name
162 uint16 desclen; //!< Length of the interface description
163 uint32 flags; //!< Interface flags
164 uint16 naddr; //!< Number of addresses
165 uint16 dummy; //!< Must be zero
169 //! Format of the message for the address listing (findalldevs command)
170 struct rpcap_findalldevs_ifaddr
172 struct sockaddr_storage addr; //!< Network address
173 struct sockaddr_storage netmask; //!< Netmask for that address
174 struct sockaddr_storage broadaddr; //!< Broadcast address for that address
175 struct sockaddr_storage dstaddr; //!< P2P destination address for that address
181 \brief Format of the message of the connection opening reply (open command).
183 This structure transfers over the network some of the values useful on the client side.
185 struct rpcap_openreply
187 int32 linktype; //!< Link type
188 int32 tzoff; //!< Timezone offset
193 //! Format of the message that starts a remote capture (startcap command)
194 struct rpcap_startcapreq
196 uint32 snaplen; //!< Length of the snapshot (number of bytes to capture for each packet)
197 uint32 read_timeout; //!< Read timeout in milliseconds
198 uint16 flags; //!< Flags (see RPCAP_STARTCAPREQ_FLAG_xxx)
199 uint16 portdata; //!< Network port on which the client is waiting at (if 'serveropen')
203 //! Format of the reply message that devoted to start a remote capture (startcap reply command)
204 struct rpcap_startcapreply
206 int32 bufsize; //!< Size of the user buffer allocated by WinPcap; it can be different from the one we chose
207 uint16 portdata; //!< Network port on which the server is waiting at (passive mode only)
208 uint16 dummy; //!< Must be zero
212 /*!
213 \brief Format of the header which encapsulates captured packets when transmitted on the network.
215 This message requries the general header as well, since we want to be albe to exchange
216 more information across the network in the future (for example statistics, and kind like that).
218 struct rpcap_pkthdr
220 uint32 timestamp_sec; //!< 'struct timeval' compatible, it represents the 'tv_sec' field
221 uint32 timestamp_usec; //!< 'struct timeval' compatible, it represents the 'tv_usec' field
222 uint32 caplen; //!< Length of portion present in the capture
223 uint32 len; //!< Real length this packet (off wire)
224 uint32 npkt; //!< Ordinal number of the packet (i.e. the first one captured has '1', the second one '2', etc)
228 //! General header used for the pcap_setfilter() command; keeps just the number of BPF instructions
229 struct rpcap_filter
231 uint16 filtertype; //!< type of the filter transferred (BPF instructions, ...)
232 uint16 dummy; //!< Must be zero
233 uint32 nitems; //!< Number of items contained into the filter (e.g. BPF instructions for BPF filters)
237 //! Structure that keeps a single BPF instuction; it is repeated 'ninsn' times according to the 'rpcap_filterbpf' header
238 struct rpcap_filterbpf_insn
240 uint16 code; //!< opcode of the instuction
241 uint8 jt; //!< relative offset to jump to in case of 'true'
242 uint8 jf; //!< relative offset to jump to in case of 'false'
243 int32 k; //!< instruction-dependent value
247 //! Structure that keeps the data required for the authentication on the remote host
248 struct rpcap_auth
250 uint16 type; //!< Authentication type
251 uint16 dummy; //!< Must be zero
252 uint16 slen1; //!< Length of the first authentication item (e.g. username)
253 uint16 slen2; //!< Length of the second authentication item (e.g. password)
257 //! Structure that keeps the statistics about the number of packets captured, dropped, etc.
258 struct rpcap_stats
260 uint32 ifrecv; //!< Packets received by the kernel filter (i.e. pcap_stats.ps_recv)
261 uint32 ifdrop; //!< Packets dropped by the network interface (e.g. not enough buffers) (i.e. pcap_stats.ps_ifdrop)
262 uint32 krnldrop; //!< Packets dropped by the kernel filter (i.e. pcap_stats.ps_drop)
263 uint32 svrcapt; //!< Packets captured by the RPCAP daemon and sent on the network
267 //! Structure that is needed to set sampling parameters
268 struct rpcap_sampling
270 uint8 method; //!< Sampling method
271 uint8 dummy1; //!< Must be zero
272 uint16 dummy2; //!< Must be zero
273 uint32 value; //!< Parameter related to the sampling method
278 // Messages field coding
279 #define RPCAP_MSG_ERROR 1 /*!< Message that keeps an error notification */
280 #define RPCAP_MSG_FINDALLIF_REQ 2 /*!< Request to list all the remote interfaces */
281 #define RPCAP_MSG_OPEN_REQ 3 /*!< Request to open a remote device */
282 #define RPCAP_MSG_STARTCAP_REQ 4 /*!< Request to start a capture on a remote device */
283 #define RPCAP_MSG_UPDATEFILTER_REQ 5 /*!< Send a compiled filter into the remote device */
284 #define RPCAP_MSG_CLOSE 6 /*!< Close the connection with the remote peer */
285 #define RPCAP_MSG_PACKET 7 /*!< This is a 'data' message, which carries a network packet */
286 #define RPCAP_MSG_AUTH_REQ 8 /*!< Message that keeps the authentication parameters */
287 #define RPCAP_MSG_STATS_REQ 9 /*!< It requires to have network statistics */
288 #define RPCAP_MSG_ENDCAP_REQ 10 /*!< Stops the current capture, keeping the device open */
289 #define RPCAP_MSG_SETSAMPLING_REQ 11 /*!< Sset sampling parameters */
291 #define RPCAP_MSG_FINDALLIF_REPLY (128+RPCAP_MSG_FINDALLIF_REQ) /*!< Keeps the list of all the remote interfaces */
292 #define RPCAP_MSG_OPEN_REPLY (128+RPCAP_MSG_OPEN_REQ) /*!< The remote device has been opened correctly */
293 #define RPCAP_MSG_STARTCAP_REPLY (128+RPCAP_MSG_STARTCAP_REQ) /*!< The capture is staarting correctly */
294 #define RPCAP_MSG_UPDATEFILTER_REPLY (128+RPCAP_MSG_UPDATEFILTER_REQ) /*!< The filter has been applied correctly on the remote device */
295 #define RPCAP_MSG_AUTH_REPLY (128+RPCAP_MSG_AUTH_REQ) /*!< Sends a message that says 'ok, authorization successful' */
296 #define RPCAP_MSG_STATS_REPLY (128+RPCAP_MSG_STATS_REQ) /*!< Message that keeps the network statistics */
297 #define RPCAP_MSG_ENDCAP_REPLY (128+RPCAP_MSG_ENDCAP_REQ) /*!< Confirms that the capture stopped succesfully */
298 #define RPCAP_MSG_SETSAMPLING_REPLY (128+RPCAP_MSG_SETSAMPLING_REQ) /*!< Confirms that the capture stopped succesfully */
300 #define RPCAP_STARTCAPREQ_FLAG_PROMISC 1 /*!< Enables promiscuous mode (default: disabled) */
301 #define RPCAP_STARTCAPREQ_FLAG_DGRAM 2 /*!< Use a datagram (i.e. UDP) connection for the data stream (default: use TCP)*/
302 #define RPCAP_STARTCAPREQ_FLAG_SERVEROPEN 4 /*!< The server has to open the data connection toward the client */
303 #define RPCAP_STARTCAPREQ_FLAG_INBOUND 8 /*!< Capture only inbound packets (take care: the flag has no effects with promiscuous enabled) */
304 #define RPCAP_STARTCAPREQ_FLAG_OUTBOUND 16 /*!< Capture only outbound packets (take care: the flag has no effects with promiscuous enabled) */
306 #define RPCAP_UPDATEFILTER_BPF 1 /*!< This code tells us that the filter is encoded with the BPF/NPF syntax */
309 // Network error codes
310 #define PCAP_ERR_NETW 1 /*!< Network error */
311 #define PCAP_ERR_INITTIMEOUT 2 /*!< The RPCAP initial timeout has expired */
312 #define PCAP_ERR_AUTH 3 /*!< Generic authentication error */
313 #define PCAP_ERR_FINDALLIF 4 /*!< Generic findalldevs error */
314 #define PCAP_ERR_NOREMOTEIF 5 /*!< The findalldevs was ok, but the remote end had no interfaces to list */
315 #define PCAP_ERR_OPEN 6 /*!< Generic pcap_open error */
316 #define PCAP_ERR_UPDATEFILTER 7 /*!< Generic updatefilter error */
317 #define PCAP_ERR_GETSTATS 8 /*!< Generic pcap_stats error */
318 #define PCAP_ERR_READEX 9 /*!< Generic pcap_next_ex error */
319 #define PCAP_ERR_HOSTNOAUTH 10 /*!< The host is not authorized to connect to this server */
320 #define PCAP_ERR_REMOTEACCEPT 11 /*!< Generic pcap_remoteaccept error */
321 #define PCAP_ERR_STARTCAPTURE 12 /*!< Generic pcap_startcapture error */
322 #define PCAP_ERR_ENDCAPTURE 13 /*!< Generic pcap_endcapture error */
323 #define PCAP_ERR_RUNTIMETIMEOUT 14 /*!< The RPCAP run-time timeout has expired */
324 #define PCAP_ERR_SETSAMPLING 15 /*!< Error diring the settings of sampling parameters */
325 #define PCAP_ERR_WRONGMSG 16 /*!< The other end endpoint sent a message which has not been recognized */
326 #define PCAP_ERR_WRONGVER 17 /*!< The other end endpoint ahs a version number that is not compatible with our */
329 */ // end of private documentation
336 /*********************************************************
338 * Exported funtion prototypes *
340 *********************************************************/
341 pcap_t *pcap_opensource_remote(const char *source, struct pcap_rmtauth *auth, char *errbuf);
342 int pcap_startcapture_remote(pcap_t *fp);
344 int pcap_read_nocb_remote(pcap_t *p, struct pcap_pkthdr **pkt_header, u_char **pkt_data);
345 int pcap_read_remote(pcap_t *p, int cnt, pcap_handler callback, u_char *user);
346 int pcap_updatefilter_remote(pcap_t *fp, struct bpf_program *prog);
347 int pcap_setfilter_remote(pcap_t *fp, struct bpf_program *prog);
348 int pcap_stats_remote(pcap_t *p, struct pcap_stat *ps);
349 int pcap_setsampling_remote(pcap_t *p);
350 struct pcap_stat *pcap_stats_ex_remote(pcap_t *p);
351 void pcap_close_remote(pcap_t *p);
353 void rpcap_createhdr(struct rpcap_header *header, uint8 type, uint16 value, uint32 length);
354 int rpcap_deseraddr(struct sockaddr_storage *sockaddrin, struct sockaddr_storage **sockaddrout, char *errbuf);
355 int rpcap_checkmsg(char *errbuf, SOCKET sock, struct rpcap_header *header, uint8 first, ...);
356 int rpcap_senderror(SOCKET sock, char *error, unsigned short errcode, char *errbuf);
357 int rpcap_sendauth(SOCKET sock, struct pcap_rmtauth *auth, char *errbuf);
359 int rpcap_remoteact_getsock(const char *host, char *errbuf);
361 #endif