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.
18  *
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.
30  *
31  */
32 
33 
34 #ifndef __REMOTE_EXT_H__
35     #define __REMOTE_EXT_H__
36 
37 
38     #ifndef HAVE_REMOTE
39         #error Please do not include this file directly. Just define HAVE_REMOTE and then include pcap.h
40     #endif
41 
42 /* Definition for Microsoft Visual Studio */
43     #if _MSC_VER > 1000
44         #pragma once
45     #endif
46 
47     #ifdef __cplusplus
48     extern "C" {
49     #endif
50 
51 /*!
52  *  \file remote-ext.h
53  *
54  *  The goal of this file it to include most of the new definitions that should be
55  *  placed into the pcap.h file.
56  *
57  *  It includes all new definitions (structures and functions like pcap_open().
58  *  Some of the functions are not really a remote feature, but, right now,
59  *  they are placed here.
60  */
61 
62 
63 
64 /* All this stuff is public */
65 
66 /*! \addtogroup remote_struct
67  \{
68  */
69 
70 
71 
72 /*!
73  *  \brief Defines the maximum buffer size in which address, port, interface names are kept.
74  *
75  *  In case the adapter name or such is larger than this value, it is truncated.
76  *  This is not used by the user; however it must be aware that an hostname / interface
77  *  name longer than this value will be truncated.
78  */
79     #define PCAP_BUF_SIZE    1024
80 
81 
82 /*! \addtogroup remote_source_ID
83  \{
84  */
85 
86 
87 /*!
88  *  \brief Internal representation of the type of source in use (file,
89  *  remote/local interface).
90  *
91  *  This indicates a file, i.e. the user want to open a capture from a local file.
92  */
93     #define PCAP_SRC_FILE        2
94 
95 /*!
96  *  \brief Internal representation of the type of source in use (file,
97  *  remote/local interface).
98  *
99  *  This indicates a local interface, i.e. the user want to open a capture from
100  *  a local interface. This does not involve the RPCAP protocol.
101  */
102     #define PCAP_SRC_IFLOCAL     3
103 
104 /*!
105  *  \brief Internal representation of the type of source in use (file,
106  *  remote/local interface).
107  *
108  *  This indicates a remote interface, i.e. the user want to open a capture from
109  *  an interface on a remote host. This does involve the RPCAP protocol.
110  */
111     #define PCAP_SRC_IFREMOTE    4
112 
113 /*!
114  \}
115  */
116 
117 
118 
119 /*! \addtogroup remote_source_string
120  *
121  *  The formats allowed by the pcap_open() are the following:
122  *  - file://path_and_filename [opens a local file]
123  *  - rpcap://devicename [opens the selected device devices available on the local host, without using the RPCAP protocol]
124  *  - rpcap://host/devicename [opens the selected device available on a remote host]
125  *  - rpcap://host:port/devicename [opens the selected device available on a remote host, using a non-standard port for RPCAP]
126  *  - adaptername [to open a local adapter; kept for compability, but it is strongly discouraged]
127  *  - (NULL) [to open the first local adapter; kept for compability, but it is strongly discouraged]
128  *
129  *  The formats allowed by the pcap_findalldevs_ex() are the following:
130  *  - file://folder/ [lists all the files in the given folder]
131  *  - rpcap:// [lists all local adapters]
132  *  - rpcap://host:port/ [lists the devices available on a remote host]
133  *
134  *  Referring to the 'host' and 'port' paramters, they can be either numeric or literal. Since
135  *  IPv6 is fully supported, these are the allowed formats:
136  *
137  *  - host (literal): e.g. host.foo.bar
138  *  - host (numeric IPv4): e.g. 10.11.12.13
139  *  - host (numeric IPv4, IPv6 style): e.g. [10.11.12.13]
140  *  - host (numeric IPv6): e.g. [1:2:3::4]
141  *  - port: can be either numeric (e.g. '80') or literal (e.g. 'http')
142  *
143  *  Here you find some allowed examples:
144  *  - rpcap://host.foo.bar/devicename [everything literal, no port number]
145  *  - rpcap://host.foo.bar:1234/devicename [everything literal, with port number]
146  *  - rpcap://10.11.12.13/devicename [IPv4 numeric, no port number]
147  *  - rpcap://10.11.12.13:1234/devicename [IPv4 numeric, with port number]
148  *  - rpcap://[10.11.12.13]:1234/devicename [IPv4 numeric with IPv6 format, with port number]
149  *  - rpcap://[1:2:3::4]/devicename [IPv6 numeric, no port number]
150  *  - rpcap://[1:2:3::4]:1234/devicename [IPv6 numeric, with port number]
151  *  - rpcap://[1:2:3::4]:http/devicename [IPv6 numeric, with literal port number]
152  *
153  \{
154  */
155 
156 
157 /*!
158  *  \brief String that will be used to determine the type of source in use (file,
159  *  remote/local interface).
160  *
161  *  This string will be prepended to the interface name in order to create a string
162  *  that contains all the information required to open the source.
163  *
164  *  This string indicates that the user wants to open a capture from a local file.
165  */
166     #define PCAP_SRC_FILE_STRING    "file://"
167 
168 /*!
169  *  \brief String that will be used to determine the type of source in use (file,
170  *  remote/local interface).
171  *
172  *  This string will be prepended to the interface name in order to create a string
173  *  that contains all the information required to open the source.
174  *
175  *  This string indicates that the user wants to open a capture from a network interface.
176  *  This string does not necessarily involve the use of the RPCAP protocol. If the
177  *  interface required resides on the local host, the RPCAP protocol is not involved
178  *  and the local functions are used.
179  */
180     #define PCAP_SRC_IF_STRING      "rpcap://"
181 
182 /*!
183  \}
184  */
185 
186 
187 
188 /*!
189  *  \addtogroup remote_open_flags
190  \{
191  */
192 
193 /*!
194  *  \brief Defines if the adapter has to go in promiscuous mode.
195  *
196  *  It is '1' if you have to open the adapter in promiscuous mode, '0' otherwise.
197  *  Note that even if this parameter is false, the interface could well be in promiscuous
198  *  mode for some other reason (for example because another capture process with
199  *  promiscuous mode enabled is currently using that interface).
200  *  On on Linux systems with 2.2 or later kernels (that have the "any" device), this
201  *  flag does not work on the "any" device; if an argument of "any" is supplied,
202  *  the 'promisc' flag is ignored.
203  */
204     #define PCAP_OPENFLAG_PROMISCUOUS    1
205 
206 /*!
207  *  \brief Defines if the data transfer (in case of a remote
208  *  capture) has to be done with UDP protocol.
209  *
210  *  If it is '1' if you want a UDP data connection, '0' if you want
211  *  a TCP data connection; control connection is always TCP-based.
212  *  A UDP connection is much lighter, but it does not guarantee that all
213  *  the captured packets arrive to the client workstation. Moreover,
214  *  it could be harmful in case of network congestion.
215  *  This flag is meaningless if the source is not a remote interface.
216  *  In that case, it is simply ignored.
217  */
218     #define PCAP_OPENFLAG_DATATX_UDP     2
219 
220 
221 /*!
222  *  \brief Defines if the remote probe will capture its own generated traffic.
223  *
224  *  In case the remote probe uses the same interface to capture traffic and to send
225  *  data back to the caller, the captured traffic includes the RPCAP traffic as well.
226  *  If this flag is turned on, the RPCAP traffic is excluded from the capture, so that
227  *  the trace returned back to the collector is does not include this traffic.
228  */
229     #define PCAP_OPENFLAG_NOCAPTURE_RPCAP       4
230 
231 /*!
232  *  \brief Defines if the local adapter will capture its own generated traffic.
233  *
234  *  This flag tells the underlying capture driver to drop the packets that were sent by itself.
235  *  This is useful when building applications like bridges, that should ignore the traffic
236  *  they just sent.
237  */
238     #define PCAP_OPENFLAG_NOCAPTURE_LOCAL       8
239 
240 /*!
241  *  \brief This flag configures the adapter for maximum responsiveness.
242  *
243  *  In presence of a large value for nbytes, WinPcap waits for the arrival of several packets before
244  *  copying the data to the user. This guarantees a low number of system calls, i.e. lower processor usage,
245  *  i.e. better performance, which is good for applications like sniffers. If the user sets the
246  *  PCAP_OPENFLAG_MAX_RESPONSIVENESS flag, the capture driver will copy the packets as soon as the application
247  *  is ready to receive them. This is suggested for real time applications (like, for example, a bridge)
248  *  that need the best responsiveness.*/
249     #define PCAP_OPENFLAG_MAX_RESPONSIVENESS    16
250 
251 /*!
252  \}
253  */
254 
255 
256 /*!
257  *  \addtogroup remote_samp_methods
258  \{
259  */
260 
261 /*!
262  *  \brief No sampling has to be done on the current capture.
263  *
264  *  In this case, no sampling algorithms are applied to the current capture.
265  */
266     #define PCAP_SAMP_NOSAMP              0
267 
268 /*!
269  *  \brief It defines that only 1 out of N packets must be returned to the user.
270  *
271  *  In this case, the 'value' field of the 'pcap_samp' structure indicates the
272  *  number of packets (minus 1) that must be discarded before one packet got accepted.
273  *  In other words, if 'value = 10', the first packet is returned to the caller, while
274  *  the following 9 are discarded.
275  */
276     #define PCAP_SAMP_1_EVERY_N           1
277 
278 /*!
279  *  \brief It defines that we have to return 1 packet every N milliseconds.
280  *
281  *  In this case, the 'value' field of the 'pcap_samp' structure indicates the 'waiting
282  *  time' in milliseconds before one packet got accepted.
283  *  In other words, if 'value = 10', the first packet is returned to the caller; the next
284  *  returned one will be the first packet that arrives when 10ms have elapsed.
285  */
286     #define PCAP_SAMP_FIRST_AFTER_N_MS    2
287 
288 /*!
289  \}
290  */
291 
292 
293 /*!
294  *  \addtogroup remote_auth_methods
295  \{
296  */
297 
298 /*!
299  *  \brief It defines the NULL authentication.
300  *
301  *  This value has to be used within the 'type' member of the pcap_rmtauth structure.
302  *  The 'NULL' authentication has to be equal to 'zero', so that old applications
303  *  can just put every field of struct pcap_rmtauth to zero, and it does work.
304  */
305     #define RPCAP_RMTAUTH_NULL    0
306 
307 /*!
308  *  \brief It defines the username/password authentication.
309  *
310  *  With this type of authentication, the RPCAP protocol will use the username/
311  *  password provided to authenticate the user on the remote machine. If the
312  *  authentication is successful (and the user has the right to open network devices)
313  *  the RPCAP connection will continue; otherwise it will be dropped.
314  *
315  *  This value has to be used within the 'type' member of the pcap_rmtauth structure.
316  */
317     #define RPCAP_RMTAUTH_PWD     1
318 
319 /*!
320  \}
321  */
322 
323 
324 
325 /*!
326  *
327  *  \brief This structure keeps the information needed to authenticate
328  *  the user on a remote machine.
329  *
330  *  The remote machine can either grant or refuse the access according
331  *  to the information provided.
332  *  In case the NULL authentication is required, both 'username' and
333  *  'password' can be NULL pointers.
334  *
335  *  This structure is meaningless if the source is not a remote interface;
336  *  in that case, the functions which requires such a structure can accept
337  *  a NULL pointer as well.
338  */
339     struct pcap_rmtauth
340     {
341         /*!
342          *  \brief Type of the authentication required.
343          *
344          *  In order to provide maximum flexibility, we can support different types
345          *  of authentication based on the value of this 'type' variable. The currently
346          *  supported authentication methods are defined into the
347          *  \link remote_auth_methods Remote Authentication Methods Section\endlink.
348          *
349          */
350         int type;
351 
352         /*!
353          *  \brief Zero-terminated string containing the username that has to be
354          *  used on the remote machine for authentication.
355          *
356          *  This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
357          *  and it can be NULL.
358          */
359         char * username;
360 
361         /*!
362          *  \brief Zero-terminated string containing the password that has to be
363          *  used on the remote machine for authentication.
364          *
365          *  This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
366          *  and it can be NULL.
367          */
368         char * password;
369     };
370 
371 
372 /*!
373  *  \brief This structure defines the information related to sampling.
374  *
375  *  In case the sampling is requested, the capturing device should read
376  *  only a subset of the packets coming from the source. The returned packets depend
377  *  on the sampling parameters.
378  *
379  *  \warning The sampling process is applied <strong>after</strong> the filtering process.
380  *  In other words, packets are filtered first, then the sampling process selects a
381  *  subset of the 'filtered' packets and it returns them to the caller.
382  */
383     struct pcap_samp
384     {
385         /*!
386          *  Method used for sampling. Currently, the supported methods are listed in the
387          *  \link remote_samp_methods Sampling Methods Section\endlink.
388          */
389         int method;
390 
391         /*!
392          *  This value depends on the sampling method defined. For its meaning, please check
393          *  at the \link remote_samp_methods Sampling Methods Section\endlink.
394          */
395         int value;
396     };
397 
398 
399 
400 /*! Maximum length of an host name (needed for the RPCAP active mode) */
401     #define RPCAP_HOSTLIST_SIZE    1024
402 
403 
404 /*!
405  \}
406  *//* end of public documentation */
407 
408 
409 /* Exported functions */
410 
411 
412 
413 /** \name New WinPcap functions
414  *
415  *  This section lists the new functions that are able to help considerably in writing
416  *  WinPcap programs because of their easiness of use.
417  */
418 /*\{ */
419     pcap_t * pcap_open( const char * source,
420                         int snaplen,
421                         int flags,
422                         int read_timeout,
423                         struct pcap_rmtauth * auth,
424                         char * errbuf );
425     int pcap_createsrcstr( char * source,
426                            int type,
427                            const char * host,
428                            const char * port,
429                            const char * name,
430                            char * errbuf );
431     int pcap_parsesrcstr( const char * source,
432                           int * type,
433                           char * host,
434                           char * port,
435                           char * name,
436                           char * errbuf );
437     int pcap_findalldevs_ex( char * source,
438                              struct pcap_rmtauth * auth,
439                              pcap_if_t ** alldevs,
440                              char * errbuf );
441     struct pcap_samp * pcap_setsampling( pcap_t * p );
442 
443 /*\} */
444 /* End of new winpcap functions */
445 
446 
447 
448 /** \name Remote Capture functions
449  */
450 /*\{ */
451     SOCKET pcap_remoteact_accept( const char * address,
452                                   const char * port,
453                                   const char * hostlist,
454                                   char * connectinghost,
455                                   struct pcap_rmtauth * auth,
456                                   char * errbuf );
457     int pcap_remoteact_list( char * hostlist,
458                              char sep,
459                              int size,
460                              char * errbuf );
461     int pcap_remoteact_close( const char * host,
462                               char * errbuf );
463     void pcap_remoteact_cleanup();
464 /*\} */
465 /* End of remote capture functions */
466 
467     #ifdef __cplusplus
468 }
469     #endif
470 
471 
472 #endif /* ifndef __REMOTE_EXT_H__ */
473