]> git.sur5r.net Git - freertos/blob - FreeRTOS-Labs/Demo/FreeRTOS_IoT_Libraries/mqtt/common/WinPCap/pcap/pcap.h
Add the Labs projects provided in the V10.2.1_191129 zip file.
[freertos] / FreeRTOS-Labs / Demo / FreeRTOS_IoT_Libraries / mqtt / common / WinPCap / pcap / pcap.h
1 /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */\r
2 /*\r
3  * Copyright (c) 1993, 1994, 1995, 1996, 1997\r
4  *      The Regents of the University of California.  All rights reserved.\r
5  *\r
6  * Redistribution and use in source and binary forms, with or without\r
7  * modification, are permitted provided that the following conditions\r
8  * are met:\r
9  * 1. Redistributions of source code must retain the above copyright\r
10  *    notice, this list of conditions and the following disclaimer.\r
11  * 2. Redistributions in binary form must reproduce the above copyright\r
12  *    notice, this list of conditions and the following disclaimer in the\r
13  *    documentation and/or other materials provided with the distribution.\r
14  * 3. All advertising materials mentioning features or use of this software\r
15  *    must display the following acknowledgement:\r
16  *      This product includes software developed by the Computer Systems\r
17  *      Engineering Group at Lawrence Berkeley Laboratory.\r
18  * 4. Neither the name of the University nor of the Laboratory may be used\r
19  *    to endorse or promote products derived from this software without\r
20  *    specific prior written permission.\r
21  *\r
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
32  * SUCH DAMAGE.\r
33  *\r
34  * @(#) $Header: /tcpdump/master/libpcap/pcap/pcap.h,v 1.4.2.11 2008-10-06 15:38:39 gianluca Exp $ (LBL)\r
35  */\r
36 \r
37 #ifndef lib_pcap_pcap_h\r
38 #define lib_pcap_pcap_h\r
39 \r
40 #if defined(WIN32)\r
41   #include <pcap-stdinc.h>\r
42 #elif defined(MSDOS)\r
43   #include <sys/types.h>\r
44   #include <sys/socket.h>  /* u_int, u_char etc. */\r
45 #else /* UN*X */\r
46   #include <sys/types.h>\r
47   #include <sys/time.h>\r
48 #endif /* WIN32/MSDOS/UN*X */\r
49 \r
50 #ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H\r
51 #include <pcap/bpf.h>\r
52 #endif\r
53 \r
54 #include <stdio.h>\r
55 \r
56 #ifdef HAVE_REMOTE\r
57         // We have to define the SOCKET here, although it has been defined in sockutils.h\r
58         // This is to avoid the distribution of the 'sockutils.h' file around\r
59         // (for example in the WinPcap developer's pack)\r
60         #ifndef SOCKET\r
61                 #ifdef WIN32\r
62                         #define SOCKET unsigned int\r
63                 #else\r
64                         #define SOCKET int\r
65                 #endif\r
66         #endif\r
67 #endif\r
68 \r
69 #ifdef __cplusplus\r
70 extern "C" {\r
71 #endif\r
72 \r
73 #define PCAP_VERSION_MAJOR 2\r
74 #define PCAP_VERSION_MINOR 4\r
75 \r
76 #define PCAP_ERRBUF_SIZE 256\r
77 \r
78 /*\r
79  * Compatibility for systems that have a bpf.h that\r
80  * predates the bpf typedefs for 64-bit support.\r
81  */\r
82 #if BPF_RELEASE - 0 < 199406\r
83 typedef int bpf_int32;\r
84 typedef u_int bpf_u_int32;\r
85 #endif\r
86 \r
87 typedef struct pcap pcap_t;\r
88 typedef struct pcap_dumper pcap_dumper_t;\r
89 typedef struct pcap_if pcap_if_t;\r
90 typedef struct pcap_addr pcap_addr_t;\r
91 \r
92 /*\r
93  * The first record in the file contains saved values for some\r
94  * of the flags used in the printout phases of tcpdump.\r
95  * Many fields here are 32 bit ints so compilers won't insert unwanted\r
96  * padding; these files need to be interchangeable across architectures.\r
97  *\r
98  * Do not change the layout of this structure, in any way (this includes\r
99  * changes that only affect the length of fields in this structure).\r
100  *\r
101  * Also, do not change the interpretation of any of the members of this\r
102  * structure, in any way (this includes using values other than\r
103  * LINKTYPE_ values, as defined in "savefile.c", in the "linktype"\r
104  * field).\r
105  *\r
106  * Instead:\r
107  *\r
108  *      introduce a new structure for the new format, if the layout\r
109  *      of the structure changed;\r
110  *\r
111  *      send mail to "tcpdump-workers@lists.tcpdump.org", requesting\r
112  *      a new magic number for your new capture file format, and, when\r
113  *      you get the new magic number, put it in "savefile.c";\r
114  *\r
115  *      use that magic number for save files with the changed file\r
116  *      header;\r
117  *\r
118  *      make the code in "savefile.c" capable of reading files with\r
119  *      the old file header as well as files with the new file header\r
120  *      (using the magic number to determine the header format).\r
121  *\r
122  * Then supply the changes as a patch at\r
123  *\r
124  *      http://sourceforge.net/projects/libpcap/\r
125  *\r
126  * so that future versions of libpcap and programs that use it (such as\r
127  * tcpdump) will be able to read your new capture file format.\r
128  */\r
129 struct pcap_file_header {\r
130         bpf_u_int32 magic;\r
131         u_short version_major;\r
132         u_short version_minor;\r
133         bpf_int32 thiszone;     /* gmt to local correction */\r
134         bpf_u_int32 sigfigs;    /* accuracy of timestamps */\r
135         bpf_u_int32 snaplen;    /* max length saved portion of each pkt */\r
136         bpf_u_int32 linktype;   /* data link type (LINKTYPE_*) */\r
137 };\r
138 \r
139 /*\r
140  * Macros for the value returned by pcap_datalink_ext().\r
141  * \r
142  * If LT_FCS_LENGTH_PRESENT(x) is true, the LT_FCS_LENGTH(x) macro\r
143  * gives the FCS length of packets in the capture.\r
144  */\r
145 #define LT_FCS_LENGTH_PRESENT(x)        ((x) & 0x04000000)\r
146 #define LT_FCS_LENGTH(x)                (((x) & 0xF0000000) >> 28)\r
147 #define LT_FCS_DATALINK_EXT(x)          ((((x) & 0xF) << 28) | 0x04000000)\r
148 \r
149 typedef enum {\r
150        PCAP_D_INOUT = 0,\r
151        PCAP_D_IN,\r
152        PCAP_D_OUT\r
153 } pcap_direction_t;\r
154 \r
155 /*\r
156  * Generic per-packet information, as supplied by libpcap.\r
157  *\r
158  * The time stamp can and should be a "struct timeval", regardless of\r
159  * whether your system supports 32-bit tv_sec in "struct timeval",\r
160  * 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit\r
161  * and 64-bit applications.  The on-disk format of savefiles uses 32-bit\r
162  * tv_sec (and tv_usec); this structure is irrelevant to that.  32-bit\r
163  * and 64-bit versions of libpcap, even if they're on the same platform,\r
164  * should supply the appropriate version of "struct timeval", even if\r
165  * that's not what the underlying packet capture mechanism supplies.\r
166  */\r
167 struct pcap_pkthdr {\r
168         struct timeval ts;      /* time stamp */\r
169         bpf_u_int32 caplen;     /* length of portion present */\r
170         bpf_u_int32 len;        /* length this packet (off wire) */\r
171 };\r
172 \r
173 /*\r
174  * As returned by the pcap_stats()\r
175  */\r
176 struct pcap_stat {\r
177         u_int ps_recv;          /* number of packets received */\r
178         u_int ps_drop;          /* number of packets dropped */\r
179         u_int ps_ifdrop;        /* drops by interface XXX not yet supported */\r
180 #ifdef HAVE_REMOTE\r
181         u_int ps_capt;          /* number of packets that are received by the application; please get rid off the Win32 ifdef */\r
182         u_int ps_sent;          /* number of packets sent by the server on the network */\r
183         u_int ps_netdrop;       /* number of packets lost on the network */\r
184 #endif /* HAVE_REMOTE */\r
185 };\r
186 \r
187 #ifdef MSDOS\r
188 /*\r
189  * As returned by the pcap_stats_ex()\r
190  */\r
191 struct pcap_stat_ex {\r
192        u_long  rx_packets;        /* total packets received       */\r
193        u_long  tx_packets;        /* total packets transmitted    */\r
194        u_long  rx_bytes;          /* total bytes received         */\r
195        u_long  tx_bytes;          /* total bytes transmitted      */\r
196        u_long  rx_errors;         /* bad packets received         */\r
197        u_long  tx_errors;         /* packet transmit problems     */\r
198        u_long  rx_dropped;        /* no space in Rx buffers       */\r
199        u_long  tx_dropped;        /* no space available for Tx    */\r
200        u_long  multicast;         /* multicast packets received   */\r
201        u_long  collisions;\r
202 \r
203        /* detailed rx_errors: */\r
204        u_long  rx_length_errors;\r
205        u_long  rx_over_errors;    /* receiver ring buff overflow  */\r
206        u_long  rx_crc_errors;     /* recv'd pkt with crc error    */\r
207        u_long  rx_frame_errors;   /* recv'd frame alignment error */\r
208        u_long  rx_fifo_errors;    /* recv'r fifo overrun          */\r
209        u_long  rx_missed_errors;  /* recv'r missed packet         */\r
210 \r
211        /* detailed tx_errors */\r
212        u_long  tx_aborted_errors;\r
213        u_long  tx_carrier_errors;\r
214        u_long  tx_fifo_errors;\r
215        u_long  tx_heartbeat_errors;\r
216        u_long  tx_window_errors;\r
217      };\r
218 #endif\r
219 \r
220 /*\r
221  * Item in a list of interfaces.\r
222  */\r
223 struct pcap_if {\r
224         struct pcap_if *next;\r
225         char *name;             /* name to hand to "pcap_open_live()" */\r
226         char *description;      /* textual description of interface, or NULL */\r
227         struct pcap_addr *addresses;\r
228         bpf_u_int32 flags;      /* PCAP_IF_ interface flags */\r
229 };\r
230 \r
231 #define PCAP_IF_LOOPBACK        0x00000001      /* interface is loopback */\r
232 \r
233 /*\r
234  * Representation of an interface address.\r
235  */\r
236 struct pcap_addr {\r
237         struct pcap_addr *next;\r
238         struct sockaddr *addr;          /* address */\r
239         struct sockaddr *netmask;       /* netmask for that address */\r
240         struct sockaddr *broadaddr;     /* broadcast address for that address */\r
241         struct sockaddr *dstaddr;       /* P2P destination address for that address */\r
242 };\r
243 \r
244 typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,\r
245                              const u_char *);\r
246 \r
247 /*\r
248  * Error codes for the pcap API.\r
249  * These will all be negative, so you can check for the success or\r
250  * failure of a call that returns these codes by checking for a\r
251  * negative value.\r
252  */\r
253 #define PCAP_ERROR                      -1      /* generic error code */\r
254 #define PCAP_ERROR_BREAK                -2      /* loop terminated by pcap_breakloop */\r
255 #define PCAP_ERROR_NOT_ACTIVATED        -3      /* the capture needs to be activated */\r
256 #define PCAP_ERROR_ACTIVATED            -4      /* the operation can't be performed on already activated captures */\r
257 #define PCAP_ERROR_NO_SUCH_DEVICE       -5      /* no such device exists */\r
258 #define PCAP_ERROR_RFMON_NOTSUP         -6      /* this device doesn't support rfmon (monitor) mode */\r
259 #define PCAP_ERROR_NOT_RFMON            -7      /* operation supported only in monitor mode */\r
260 #define PCAP_ERROR_PERM_DENIED          -8      /* no permission to open the device */\r
261 #define PCAP_ERROR_IFACE_NOT_UP         -9      /* interface isn't up */\r
262 \r
263 /*\r
264  * Warning codes for the pcap API.\r
265  * These will all be positive and non-zero, so they won't look like\r
266  * errors.\r
267  */\r
268 #define PCAP_WARNING                    1       /* generic warning code */\r
269 #define PCAP_WARNING_PROMISC_NOTSUP     2       /* this device doesn't support promiscuous mode */\r
270 \r
271 char    *pcap_lookupdev(char *);\r
272 int     pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);\r
273 \r
274 pcap_t  *pcap_create(const char *, char *);\r
275 int     pcap_set_snaplen(pcap_t *, int);\r
276 int     pcap_set_promisc(pcap_t *, int);\r
277 int     pcap_can_set_rfmon(pcap_t *);\r
278 int     pcap_set_rfmon(pcap_t *, int);\r
279 int     pcap_set_timeout(pcap_t *, int);\r
280 int     pcap_set_buffer_size(pcap_t *, int);\r
281 int     pcap_activate(pcap_t *);\r
282 \r
283 pcap_t  *pcap_open_live(const char *, int, int, int, char *);\r
284 pcap_t  *pcap_open_dead(int, int);\r
285 pcap_t  *pcap_open_offline(const char *, char *);\r
286 #if defined(WIN32)\r
287 pcap_t  *pcap_hopen_offline(intptr_t, char *);\r
288 #if !defined(LIBPCAP_EXPORTS)\r
289 #define pcap_fopen_offline(f,b) \\r
290         pcap_hopen_offline(_get_osfhandle(_fileno(f)), b)\r
291 #else /*LIBPCAP_EXPORTS*/\r
292 static pcap_t *pcap_fopen_offline(FILE *, char *);\r
293 #endif\r
294 #else /*WIN32*/\r
295 pcap_t  *pcap_fopen_offline(FILE *, char *);\r
296 #endif /*WIN32*/\r
297 \r
298 void    pcap_close(pcap_t *);\r
299 int     pcap_loop(pcap_t *, int, pcap_handler, u_char *);\r
300 int     pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);\r
301 const u_char*\r
302         pcap_next(pcap_t *, struct pcap_pkthdr *);\r
303 int     pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);\r
304 void    pcap_breakloop(pcap_t *);\r
305 int     pcap_stats(pcap_t *, struct pcap_stat *);\r
306 int     pcap_setfilter(pcap_t *, struct bpf_program *);\r
307 int     pcap_setdirection(pcap_t *, pcap_direction_t);\r
308 int     pcap_getnonblock(pcap_t *, char *);\r
309 int     pcap_setnonblock(pcap_t *, int, char *);\r
310 int     pcap_inject(pcap_t *, const void *, size_t);\r
311 int     pcap_sendpacket(pcap_t *, const u_char *, int);\r
312 const char *pcap_statustostr(int);\r
313 const char *pcap_strerror(int);\r
314 char    *pcap_geterr(pcap_t *);\r
315 void    pcap_perror(pcap_t *, char *);\r
316 int     pcap_compile(pcap_t *, struct bpf_program *, const char *, int,\r
317             bpf_u_int32);\r
318 int     pcap_compile_nopcap(int, int, struct bpf_program *,\r
319             const char *, int, bpf_u_int32);\r
320 void    pcap_freecode(struct bpf_program *);\r
321 int     pcap_offline_filter(struct bpf_program *, const struct pcap_pkthdr *,\r
322             const u_char *);\r
323 int     pcap_datalink(pcap_t *);\r
324 int     pcap_datalink_ext(pcap_t *);\r
325 int     pcap_list_datalinks(pcap_t *, int **);\r
326 int     pcap_set_datalink(pcap_t *, int);\r
327 void    pcap_free_datalinks(int *);\r
328 int     pcap_datalink_name_to_val(const char *);\r
329 const char *pcap_datalink_val_to_name(int);\r
330 const char *pcap_datalink_val_to_description(int);\r
331 int     pcap_snapshot(pcap_t *);\r
332 int     pcap_is_swapped(pcap_t *);\r
333 int     pcap_major_version(pcap_t *);\r
334 int     pcap_minor_version(pcap_t *);\r
335 \r
336 /* XXX */\r
337 FILE    *pcap_file(pcap_t *);\r
338 int     pcap_fileno(pcap_t *);\r
339 \r
340 pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);\r
341 pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);\r
342 FILE    *pcap_dump_file(pcap_dumper_t *);\r
343 long    pcap_dump_ftell(pcap_dumper_t *);\r
344 int     pcap_dump_flush(pcap_dumper_t *);\r
345 void    pcap_dump_close(pcap_dumper_t *);\r
346 void    pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);\r
347 \r
348 int     pcap_findalldevs(pcap_if_t **, char *);\r
349 void    pcap_freealldevs(pcap_if_t *);\r
350 \r
351 const char *pcap_lib_version(void);\r
352 \r
353 /* XXX this guy lives in the bpf tree */\r
354 u_int   bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);\r
355 int     bpf_validate(const struct bpf_insn *f, int len);\r
356 char    *bpf_image(const struct bpf_insn *, int);\r
357 void    bpf_dump(const struct bpf_program *, int);\r
358 \r
359 #if defined(WIN32)\r
360 \r
361 /*\r
362  * Win32 definitions\r
363  */\r
364 \r
365 int pcap_setbuff(pcap_t *p, int dim);\r
366 int pcap_setmode(pcap_t *p, int mode);\r
367 int pcap_setmintocopy(pcap_t *p, int size);\r
368 \r
369 #ifdef WPCAP\r
370 /* Include file with the wpcap-specific extensions */\r
371 #include <Win32-Extensions.h>\r
372 #endif /* WPCAP */\r
373 \r
374 #define MODE_CAPT 0\r
375 #define MODE_STAT 1\r
376 #define MODE_MON 2\r
377 \r
378 #elif defined(MSDOS)\r
379 \r
380 /*\r
381  * MS-DOS definitions\r
382  */\r
383 \r
384 int  pcap_stats_ex (pcap_t *, struct pcap_stat_ex *);\r
385 void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait);\r
386 u_long pcap_mac_packets (void);\r
387 \r
388 #else /* UN*X */\r
389 \r
390 /*\r
391  * UN*X definitions\r
392  */\r
393 \r
394 int     pcap_get_selectable_fd(pcap_t *);\r
395 \r
396 #endif /* WIN32/MSDOS/UN*X */\r
397 \r
398 #ifdef HAVE_REMOTE\r
399 /* Includes most of the public stuff that is needed for the remote capture */\r
400 #include <remote-ext.h>\r
401 #endif   /* HAVE_REMOTE */\r
402 \r
403 #ifdef __cplusplus\r
404 }\r
405 #endif\r
406 \r
407 #endif\r