pcap.h.html 15 KB

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