pcap.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  1. /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
  2. /*
  3. * Copyright (c) 1993, 1994, 1995, 1996, 1997
  4. * The Regents of the University of California. 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. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. All advertising materials mentioning features or use of this software
  15. * must display the following acknowledgement:
  16. * This product includes software developed by the Computer Systems
  17. * Engineering Group at Lawrence Berkeley Laboratory.
  18. * 4. Neither the name of the University nor of the Laboratory may be used
  19. * to endorse or promote products derived from this software without
  20. * specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. */
  34. /*
  35. * Remote packet capture mechanisms and extensions from WinPcap:
  36. *
  37. * Copyright (c) 2002 - 2003
  38. * NetGroup, Politecnico di Torino (Italy)
  39. * All rights reserved.
  40. *
  41. * Redistribution and use in source and binary forms, with or without
  42. * modification, are permitted provided that the following conditions
  43. * are met:
  44. *
  45. * 1. Redistributions of source code must retain the above copyright
  46. * notice, this list of conditions and the following disclaimer.
  47. * 2. Redistributions in binary form must reproduce the above copyright
  48. * notice, this list of conditions and the following disclaimer in the
  49. * documentation and/or other materials provided with the distribution.
  50. * 3. Neither the name of the Politecnico di Torino nor the names of its
  51. * contributors may be used to endorse or promote products derived from
  52. * this software without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  55. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  56. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  57. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  58. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  59. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  60. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  61. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  62. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  63. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  64. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  65. *
  66. */
  67. #ifndef lib_pcap_pcap_h
  68. #define lib_pcap_pcap_h
  69. /*
  70. * Some software that uses libpcap/WinPcap/Npcap defines _MSC_VER before
  71. * includeing pcap.h if it's not defined - and it defines it to 1500.
  72. * (I'm looking at *you*, lwIP!)
  73. *
  74. * Attempt to detect this, and undefine _MSC_VER so that we can *reliably*
  75. * use it to know what compiler is being used and, if it's Visual Studio,
  76. * what version is being used.
  77. */
  78. #if defined(_MSC_VER)
  79. /*
  80. * We assume here that software such as that doesn't define _MSC_FULL_VER
  81. * as well and that it defines _MSC_VER with a value > 1200.
  82. *
  83. * DO NOT BREAK THESE ASSUMPTIONS. IF YOU FEEL YOU MUST DEFINE _MSC_VER
  84. * WITH A COMPILER THAT'S NOT MICROSOFT'S C COMPILER, PLEASE CONTACT
  85. * US SO THAT WE CAN MAKE IT SO THAT YOU DON'T HAVE TO DO THAT. THANK
  86. * YOU.
  87. *
  88. * OK, is _MSC_FULL_VER defined?
  89. */
  90. #if !defined(_MSC_FULL_VER)
  91. /*
  92. * According to
  93. *
  94. * https://sourceforge.net/p/predef/wiki/Compilers/
  95. *
  96. * with "Visual C++ 6.0 Processor Pack"/Visual C++ 6.0 SP6 and
  97. * later, _MSC_FULL_VER is defined, so either this is an older
  98. * version of Visual C++ or it's not Visual C++ at all.
  99. *
  100. * For Visual C++ 6.0, _MSC_VER is defined as 1200.
  101. */
  102. #if _MSC_VER > 1200
  103. /*
  104. * If this is Visual C++, _MSC_FULL_VER should be defined, so we
  105. * assume this isn't Visual C++, and undo the lie that it is.
  106. */
  107. #undef _MSC_VER
  108. #endif
  109. #endif
  110. #endif
  111. #include <pcap/funcattrs.h>
  112. #include <pcap/pcap-inttypes.h>
  113. #if defined(_WIN32)
  114. #include <winsock2.h> /* u_int, u_char etc. */
  115. #include <io.h> /* _get_osfhandle() */
  116. #elif defined(MSDOS)
  117. #include <sys/types.h> /* u_int, u_char etc. */
  118. #include <sys/socket.h>
  119. #else /* UN*X */
  120. #include <sys/types.h> /* u_int, u_char etc. */
  121. #include <sys/time.h>
  122. #endif /* _WIN32/MSDOS/UN*X */
  123. #include <pcap/socket.h> /* for SOCKET, as the active-mode rpcap APIs use it */
  124. #ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H
  125. #include <pcap/bpf.h>
  126. #endif
  127. #include <stdio.h>
  128. #ifdef __cplusplus
  129. extern "C" {
  130. #endif
  131. /*
  132. * Version number of the current version of the pcap file format.
  133. *
  134. * NOTE: this is *NOT* the version number of the libpcap library.
  135. * To fetch the version information for the version of libpcap
  136. * you're using, use pcap_lib_version().
  137. */
  138. #define PCAP_VERSION_MAJOR 2
  139. #define PCAP_VERSION_MINOR 4
  140. #define PCAP_ERRBUF_SIZE 256
  141. /*
  142. * Compatibility for systems that have a bpf.h that
  143. * predates the bpf typedefs for 64-bit support.
  144. */
  145. #if BPF_RELEASE - 0 < 199406
  146. typedef int bpf_int32;
  147. typedef u_int bpf_u_int32;
  148. #endif
  149. typedef struct pcap pcap_t;
  150. typedef struct pcap_dumper pcap_dumper_t;
  151. typedef struct pcap_if pcap_if_t;
  152. typedef struct pcap_addr pcap_addr_t;
  153. /*
  154. * The first record in the file contains saved values for some
  155. * of the flags used in the printout phases of tcpdump.
  156. * Many fields here are 32 bit ints so compilers won't insert unwanted
  157. * padding; these files need to be interchangeable across architectures.
  158. * Documentation: https://www.tcpdump.org/manpages/pcap-savefile.5.txt.
  159. *
  160. * Do not change the layout of this structure, in any way (this includes
  161. * changes that only affect the length of fields in this structure).
  162. *
  163. * Also, do not change the interpretation of any of the members of this
  164. * structure, in any way (this includes using values other than
  165. * LINKTYPE_ values, as defined in "savefile.c", in the "linktype"
  166. * field).
  167. *
  168. * Instead:
  169. *
  170. * introduce a new structure for the new format, if the layout
  171. * of the structure changed;
  172. *
  173. * send mail to "tcpdump-workers@lists.tcpdump.org", requesting
  174. * a new magic number for your new capture file format, and, when
  175. * you get the new magic number, put it in "savefile.c";
  176. *
  177. * use that magic number for save files with the changed file
  178. * header;
  179. *
  180. * make the code in "savefile.c" capable of reading files with
  181. * the old file header as well as files with the new file header
  182. * (using the magic number to determine the header format).
  183. *
  184. * Then supply the changes by forking the branch at
  185. *
  186. * https://github.com/the-tcpdump-group/libpcap/tree/master
  187. *
  188. * and issuing a pull request, so that future versions of libpcap and
  189. * programs that use it (such as tcpdump) will be able to read your new
  190. * capture file format.
  191. */
  192. struct pcap_file_header {
  193. bpf_u_int32 magic;
  194. u_short version_major;
  195. u_short version_minor;
  196. bpf_int32 thiszone; /* gmt to local correction; this is always 0 */
  197. bpf_u_int32 sigfigs; /* accuracy of timestamps; this is always 0 */
  198. bpf_u_int32 snaplen; /* max length saved portion of each pkt */
  199. bpf_u_int32 linktype; /* data link type (LINKTYPE_*) */
  200. };
  201. /*
  202. * Macros for the value returned by pcap_datalink_ext().
  203. *
  204. * If LT_FCS_LENGTH_PRESENT(x) is true, the LT_FCS_LENGTH(x) macro
  205. * gives the FCS length of packets in the capture.
  206. */
  207. #define LT_FCS_LENGTH_PRESENT(x) ((x) & 0x04000000)
  208. #define LT_FCS_LENGTH(x) (((x) & 0xF0000000) >> 28)
  209. #define LT_FCS_DATALINK_EXT(x) ((((x) & 0xF) << 28) | 0x04000000)
  210. typedef enum {
  211. PCAP_D_INOUT = 0,
  212. PCAP_D_IN,
  213. PCAP_D_OUT
  214. } pcap_direction_t;
  215. /*
  216. * Generic per-packet information, as supplied by libpcap.
  217. *
  218. * The time stamp can and should be a "struct timeval", regardless of
  219. * whether your system supports 32-bit tv_sec in "struct timeval",
  220. * 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit
  221. * and 64-bit applications. The on-disk format of savefiles uses 32-bit
  222. * tv_sec (and tv_usec); this structure is irrelevant to that. 32-bit
  223. * and 64-bit versions of libpcap, even if they're on the same platform,
  224. * should supply the appropriate version of "struct timeval", even if
  225. * that's not what the underlying packet capture mechanism supplies.
  226. */
  227. struct pcap_pkthdr {
  228. struct timeval ts; /* time stamp */
  229. bpf_u_int32 caplen; /* length of portion present */
  230. bpf_u_int32 len; /* length of this packet (off wire) */
  231. };
  232. /*
  233. * As returned by the pcap_stats()
  234. */
  235. struct pcap_stat {
  236. u_int ps_recv; /* number of packets received */
  237. u_int ps_drop; /* number of packets dropped */
  238. u_int ps_ifdrop; /* drops by interface -- only supported on some platforms */
  239. #ifdef _WIN32
  240. u_int ps_capt; /* number of packets that reach the application */
  241. u_int ps_sent; /* number of packets sent by the server on the network */
  242. u_int ps_netdrop; /* number of packets lost on the network */
  243. #endif /* _WIN32 */
  244. };
  245. #ifdef MSDOS
  246. /*
  247. * As returned by the pcap_stats_ex()
  248. */
  249. struct pcap_stat_ex {
  250. u_long rx_packets; /* total packets received */
  251. u_long tx_packets; /* total packets transmitted */
  252. u_long rx_bytes; /* total bytes received */
  253. u_long tx_bytes; /* total bytes transmitted */
  254. u_long rx_errors; /* bad packets received */
  255. u_long tx_errors; /* packet transmit problems */
  256. u_long rx_dropped; /* no space in Rx buffers */
  257. u_long tx_dropped; /* no space available for Tx */
  258. u_long multicast; /* multicast packets received */
  259. u_long collisions;
  260. /* detailed rx_errors: */
  261. u_long rx_length_errors;
  262. u_long rx_over_errors; /* receiver ring buff overflow */
  263. u_long rx_crc_errors; /* recv'd pkt with crc error */
  264. u_long rx_frame_errors; /* recv'd frame alignment error */
  265. u_long rx_fifo_errors; /* recv'r fifo overrun */
  266. u_long rx_missed_errors; /* recv'r missed packet */
  267. /* detailed tx_errors */
  268. u_long tx_aborted_errors;
  269. u_long tx_carrier_errors;
  270. u_long tx_fifo_errors;
  271. u_long tx_heartbeat_errors;
  272. u_long tx_window_errors;
  273. };
  274. #endif
  275. /*
  276. * Item in a list of interfaces.
  277. */
  278. struct pcap_if {
  279. struct pcap_if *next;
  280. char *name; /* name to hand to "pcap_open_live()" */
  281. char *description; /* textual description of interface, or NULL */
  282. struct pcap_addr *addresses;
  283. bpf_u_int32 flags; /* PCAP_IF_ interface flags */
  284. };
  285. #define PCAP_IF_LOOPBACK 0x00000001 /* interface is loopback */
  286. #define PCAP_IF_UP 0x00000002 /* interface is up */
  287. #define PCAP_IF_RUNNING 0x00000004 /* interface is running */
  288. #define PCAP_IF_WIRELESS 0x00000008 /* interface is wireless (*NOT* necessarily Wi-Fi!) */
  289. #define PCAP_IF_CONNECTION_STATUS 0x00000030 /* connection status: */
  290. #define PCAP_IF_CONNECTION_STATUS_UNKNOWN 0x00000000 /* unknown */
  291. #define PCAP_IF_CONNECTION_STATUS_CONNECTED 0x00000010 /* connected */
  292. #define PCAP_IF_CONNECTION_STATUS_DISCONNECTED 0x00000020 /* disconnected */
  293. #define PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE 0x00000030 /* not applicable */
  294. /*
  295. * Representation of an interface address.
  296. */
  297. struct pcap_addr {
  298. struct pcap_addr *next;
  299. struct sockaddr *addr; /* address */
  300. struct sockaddr *netmask; /* netmask for that address */
  301. struct sockaddr *broadaddr; /* broadcast address for that address */
  302. struct sockaddr *dstaddr; /* P2P destination address for that address */
  303. };
  304. typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
  305. const u_char *);
  306. /*
  307. * Error codes for the pcap API.
  308. * These will all be negative, so you can check for the success or
  309. * failure of a call that returns these codes by checking for a
  310. * negative value.
  311. */
  312. #define PCAP_ERROR -1 /* generic error code */
  313. #define PCAP_ERROR_BREAK -2 /* loop terminated by pcap_breakloop */
  314. #define PCAP_ERROR_NOT_ACTIVATED -3 /* the capture needs to be activated */
  315. #define PCAP_ERROR_ACTIVATED -4 /* the operation can't be performed on already activated captures */
  316. #define PCAP_ERROR_NO_SUCH_DEVICE -5 /* no such device exists */
  317. #define PCAP_ERROR_RFMON_NOTSUP -6 /* this device doesn't support rfmon (monitor) mode */
  318. #define PCAP_ERROR_NOT_RFMON -7 /* operation supported only in monitor mode */
  319. #define PCAP_ERROR_PERM_DENIED -8 /* no permission to open the device */
  320. #define PCAP_ERROR_IFACE_NOT_UP -9 /* interface isn't up */
  321. #define PCAP_ERROR_CANTSET_TSTAMP_TYPE -10 /* this device doesn't support setting the time stamp type */
  322. #define PCAP_ERROR_PROMISC_PERM_DENIED -11 /* you don't have permission to capture in promiscuous mode */
  323. #define PCAP_ERROR_TSTAMP_PRECISION_NOTSUP -12 /* the requested time stamp precision is not supported */
  324. /*
  325. * Warning codes for the pcap API.
  326. * These will all be positive and non-zero, so they won't look like
  327. * errors.
  328. */
  329. #define PCAP_WARNING 1 /* generic warning code */
  330. #define PCAP_WARNING_PROMISC_NOTSUP 2 /* this device doesn't support promiscuous mode */
  331. #define PCAP_WARNING_TSTAMP_TYPE_NOTSUP 3 /* the requested time stamp type is not supported */
  332. /*
  333. * Value to pass to pcap_compile() as the netmask if you don't know what
  334. * the netmask is.
  335. */
  336. #define PCAP_NETMASK_UNKNOWN 0xffffffff
  337. /*
  338. * Initialize pcap. If this isn't called, pcap is initialized to
  339. * a mode source-compatible and binary-compatible with older versions
  340. * that lack this routine.
  341. */
  342. /*
  343. * Initialization options.
  344. * All bits not listed here are reserved for expansion.
  345. *
  346. * On UNIX-like systems, the local character encoding is assumed to be
  347. * UTF-8, so no character encoding transformations are done.
  348. *
  349. * On Windows, the local character encoding is the local ANSI code page.
  350. */
  351. #define PCAP_CHAR_ENC_LOCAL 0x00000000U /* strings are in the local character encoding */
  352. #define PCAP_CHAR_ENC_UTF_8 0x00000001U /* strings are in UTF-8 */
  353. PCAP_AVAILABLE_1_10
  354. PCAP_API int pcap_init(unsigned int, char *);
  355. /*
  356. * We're deprecating pcap_lookupdev() for various reasons (not
  357. * thread-safe, can behave weirdly with WinPcap). Callers
  358. * should use pcap_findalldevs() and use the first device.
  359. */
  360. PCAP_AVAILABLE_0_4
  361. PCAP_API char *pcap_lookupdev(char *)
  362. PCAP_DEPRECATED(pcap_lookupdev, "use 'pcap_findalldevs' and use the first device");
  363. PCAP_AVAILABLE_0_4
  364. PCAP_API int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);
  365. PCAP_AVAILABLE_1_0
  366. PCAP_API pcap_t *pcap_create(const char *, char *);
  367. PCAP_AVAILABLE_1_0
  368. PCAP_API int pcap_set_snaplen(pcap_t *, int);
  369. PCAP_AVAILABLE_1_0
  370. PCAP_API int pcap_set_promisc(pcap_t *, int);
  371. PCAP_AVAILABLE_1_0
  372. PCAP_API int pcap_can_set_rfmon(pcap_t *);
  373. PCAP_AVAILABLE_1_0
  374. PCAP_API int pcap_set_rfmon(pcap_t *, int);
  375. PCAP_AVAILABLE_1_0
  376. PCAP_API int pcap_set_timeout(pcap_t *, int);
  377. PCAP_AVAILABLE_1_2
  378. PCAP_API int pcap_set_tstamp_type(pcap_t *, int);
  379. PCAP_AVAILABLE_1_5
  380. PCAP_API int pcap_set_immediate_mode(pcap_t *, int);
  381. PCAP_AVAILABLE_1_0
  382. PCAP_API int pcap_set_buffer_size(pcap_t *, int);
  383. PCAP_AVAILABLE_1_5
  384. PCAP_API int pcap_set_tstamp_precision(pcap_t *, int);
  385. PCAP_AVAILABLE_1_5
  386. PCAP_API int pcap_get_tstamp_precision(pcap_t *);
  387. PCAP_AVAILABLE_1_0
  388. PCAP_API int pcap_activate(pcap_t *);
  389. PCAP_AVAILABLE_1_2
  390. PCAP_API int pcap_list_tstamp_types(pcap_t *, int **);
  391. PCAP_AVAILABLE_1_2
  392. PCAP_API void pcap_free_tstamp_types(int *);
  393. PCAP_AVAILABLE_1_2
  394. PCAP_API int pcap_tstamp_type_name_to_val(const char *);
  395. PCAP_AVAILABLE_1_2
  396. PCAP_API const char *pcap_tstamp_type_val_to_name(int);
  397. PCAP_AVAILABLE_1_2
  398. PCAP_API const char *pcap_tstamp_type_val_to_description(int);
  399. #ifdef __linux__
  400. PCAP_AVAILABLE_1_9
  401. PCAP_API int pcap_set_protocol_linux(pcap_t *, int);
  402. #endif
  403. /*
  404. * Time stamp types.
  405. * Not all systems and interfaces will necessarily support all of these.
  406. *
  407. * A system that supports PCAP_TSTAMP_HOST is offering time stamps
  408. * provided by the host machine, rather than by the capture device,
  409. * but not committing to any characteristics of the time stamp.
  410. *
  411. * PCAP_TSTAMP_HOST_LOWPREC is a time stamp, provided by the host machine,
  412. * that's low-precision but relatively cheap to fetch; it's normally done
  413. * using the system clock, so it's normally synchronized with times you'd
  414. * fetch from system calls.
  415. *
  416. * PCAP_TSTAMP_HOST_HIPREC is a time stamp, provided by the host machine,
  417. * that's high-precision; it might be more expensive to fetch. It is
  418. * synchronized with the system clock.
  419. *
  420. * PCAP_TSTAMP_HOST_HIPREC_UNSYNCED is a time stamp, provided by the host
  421. * machine, that's high-precision; it might be more expensive to fetch.
  422. * It is not synchronized with the system clock, and might have
  423. * problems with time stamps for packets received on different CPUs,
  424. * depending on the platform. It might be more likely to be strictly
  425. * monotonic than PCAP_TSTAMP_HOST_HIPREC.
  426. *
  427. * PCAP_TSTAMP_ADAPTER is a high-precision time stamp supplied by the
  428. * capture device; it's synchronized with the system clock.
  429. *
  430. * PCAP_TSTAMP_ADAPTER_UNSYNCED is a high-precision time stamp supplied by
  431. * the capture device; it's not synchronized with the system clock.
  432. *
  433. * Note that time stamps synchronized with the system clock can go
  434. * backwards, as the system clock can go backwards. If a clock is
  435. * not in sync with the system clock, that could be because the
  436. * system clock isn't keeping accurate time, because the other
  437. * clock isn't keeping accurate time, or both.
  438. *
  439. * Note that host-provided time stamps generally correspond to the
  440. * time when the time-stamping code sees the packet; this could
  441. * be some unknown amount of time after the first or last bit of
  442. * the packet is received by the network adapter, due to batching
  443. * of interrupts for packet arrival, queueing delays, etc..
  444. */
  445. #define PCAP_TSTAMP_HOST 0 /* host-provided, unknown characteristics */
  446. #define PCAP_TSTAMP_HOST_LOWPREC 1 /* host-provided, low precision, synced with the system clock */
  447. #define PCAP_TSTAMP_HOST_HIPREC 2 /* host-provided, high precision, synced with the system clock */
  448. #define PCAP_TSTAMP_ADAPTER 3 /* device-provided, synced with the system clock */
  449. #define PCAP_TSTAMP_ADAPTER_UNSYNCED 4 /* device-provided, not synced with the system clock */
  450. #define PCAP_TSTAMP_HOST_HIPREC_UNSYNCED 5 /* host-provided, high precision, not synced with the system clock */
  451. /*
  452. * Time stamp resolution types.
  453. * Not all systems and interfaces will necessarily support all of these
  454. * resolutions when doing live captures; all of them can be requested
  455. * when reading a savefile.
  456. */
  457. #define PCAP_TSTAMP_PRECISION_MICRO 0 /* use timestamps with microsecond precision, default */
  458. #define PCAP_TSTAMP_PRECISION_NANO 1 /* use timestamps with nanosecond precision */
  459. PCAP_AVAILABLE_0_4
  460. PCAP_API pcap_t *pcap_open_live(const char *, int, int, int, char *);
  461. PCAP_AVAILABLE_0_6
  462. PCAP_API pcap_t *pcap_open_dead(int, int);
  463. PCAP_AVAILABLE_1_5
  464. PCAP_API pcap_t *pcap_open_dead_with_tstamp_precision(int, int, u_int);
  465. PCAP_AVAILABLE_1_5
  466. PCAP_API pcap_t *pcap_open_offline_with_tstamp_precision(const char *, u_int, char *);
  467. PCAP_AVAILABLE_0_4
  468. PCAP_API pcap_t *pcap_open_offline(const char *, char *);
  469. #ifdef _WIN32
  470. PCAP_AVAILABLE_1_5
  471. PCAP_API pcap_t *pcap_hopen_offline_with_tstamp_precision(intptr_t, u_int, char *);
  472. PCAP_API pcap_t *pcap_hopen_offline(intptr_t, char *);
  473. /*
  474. * If we're building libpcap, these are internal routines in savefile.c,
  475. * so we must not define them as macros.
  476. *
  477. * If we're not building libpcap, given that the version of the C runtime
  478. * with which libpcap was built might be different from the version
  479. * of the C runtime with which an application using libpcap was built,
  480. * and that a FILE structure may differ between the two versions of the
  481. * C runtime, calls to _fileno() must use the version of _fileno() in
  482. * the C runtime used to open the FILE *, not the version in the C
  483. * runtime with which libpcap was built. (Maybe once the Universal CRT
  484. * rules the world, this will cease to be a problem.)
  485. */
  486. #ifndef BUILDING_PCAP
  487. #define pcap_fopen_offline_with_tstamp_precision(f,p,b) \
  488. pcap_hopen_offline_with_tstamp_precision(_get_osfhandle(_fileno(f)), p, b)
  489. #define pcap_fopen_offline(f,b) \
  490. pcap_hopen_offline(_get_osfhandle(_fileno(f)), b)
  491. #endif
  492. #else /*_WIN32*/
  493. PCAP_AVAILABLE_1_5
  494. PCAP_API pcap_t *pcap_fopen_offline_with_tstamp_precision(FILE *, u_int, char *);
  495. PCAP_AVAILABLE_0_9
  496. PCAP_API pcap_t *pcap_fopen_offline(FILE *, char *);
  497. #endif /*_WIN32*/
  498. PCAP_AVAILABLE_0_4
  499. PCAP_API void pcap_close(pcap_t *);
  500. PCAP_AVAILABLE_0_4
  501. PCAP_API int pcap_loop(pcap_t *, int, pcap_handler, u_char *);
  502. PCAP_AVAILABLE_0_4
  503. PCAP_API int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
  504. PCAP_AVAILABLE_0_4
  505. PCAP_API const u_char *pcap_next(pcap_t *, struct pcap_pkthdr *);
  506. PCAP_AVAILABLE_0_8
  507. PCAP_API int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
  508. PCAP_AVAILABLE_0_8
  509. PCAP_API void pcap_breakloop(pcap_t *);
  510. PCAP_AVAILABLE_0_4
  511. PCAP_API int pcap_stats(pcap_t *, struct pcap_stat *);
  512. PCAP_AVAILABLE_0_4
  513. PCAP_API int pcap_setfilter(pcap_t *, struct bpf_program *);
  514. PCAP_AVAILABLE_0_9
  515. PCAP_API int pcap_setdirection(pcap_t *, pcap_direction_t);
  516. PCAP_AVAILABLE_0_7
  517. PCAP_API int pcap_getnonblock(pcap_t *, char *);
  518. PCAP_AVAILABLE_0_7
  519. PCAP_API int pcap_setnonblock(pcap_t *, int, char *);
  520. PCAP_AVAILABLE_0_9
  521. PCAP_API int pcap_inject(pcap_t *, const void *, size_t);
  522. PCAP_AVAILABLE_0_8
  523. PCAP_API int pcap_sendpacket(pcap_t *, const u_char *, int);
  524. PCAP_AVAILABLE_1_0
  525. PCAP_API const char *pcap_statustostr(int);
  526. PCAP_AVAILABLE_0_4
  527. PCAP_API const char *pcap_strerror(int);
  528. PCAP_AVAILABLE_0_4
  529. PCAP_API char *pcap_geterr(pcap_t *);
  530. PCAP_AVAILABLE_0_4
  531. PCAP_API void pcap_perror(pcap_t *, const char *);
  532. PCAP_AVAILABLE_0_4
  533. PCAP_API int pcap_compile(pcap_t *, struct bpf_program *, const char *, int,
  534. bpf_u_int32);
  535. PCAP_AVAILABLE_0_5
  536. PCAP_API int pcap_compile_nopcap(int, int, struct bpf_program *,
  537. const char *, int, bpf_u_int32);
  538. /* XXX - this took two arguments in 0.4 and 0.5 */
  539. PCAP_AVAILABLE_0_6
  540. PCAP_API void pcap_freecode(struct bpf_program *);
  541. PCAP_AVAILABLE_1_0
  542. PCAP_API int pcap_offline_filter(const struct bpf_program *,
  543. const struct pcap_pkthdr *, const u_char *);
  544. PCAP_AVAILABLE_0_4
  545. PCAP_API int pcap_datalink(pcap_t *);
  546. PCAP_AVAILABLE_1_0
  547. PCAP_API int pcap_datalink_ext(pcap_t *);
  548. PCAP_AVAILABLE_0_8
  549. PCAP_API int pcap_list_datalinks(pcap_t *, int **);
  550. PCAP_AVAILABLE_0_8
  551. PCAP_API int pcap_set_datalink(pcap_t *, int);
  552. PCAP_AVAILABLE_0_8
  553. PCAP_API void pcap_free_datalinks(int *);
  554. PCAP_AVAILABLE_0_8
  555. PCAP_API int pcap_datalink_name_to_val(const char *);
  556. PCAP_AVAILABLE_0_8
  557. PCAP_API const char *pcap_datalink_val_to_name(int);
  558. PCAP_AVAILABLE_0_8
  559. PCAP_API const char *pcap_datalink_val_to_description(int);
  560. PCAP_AVAILABLE_1_10
  561. PCAP_API const char *pcap_datalink_val_to_description_or_dlt(int);
  562. PCAP_AVAILABLE_0_4
  563. PCAP_API int pcap_snapshot(pcap_t *);
  564. PCAP_AVAILABLE_0_4
  565. PCAP_API int pcap_is_swapped(pcap_t *);
  566. PCAP_AVAILABLE_0_4
  567. PCAP_API int pcap_major_version(pcap_t *);
  568. PCAP_AVAILABLE_0_4
  569. PCAP_API int pcap_minor_version(pcap_t *);
  570. PCAP_AVAILABLE_1_9
  571. PCAP_API int pcap_bufsize(pcap_t *);
  572. /* XXX */
  573. PCAP_AVAILABLE_0_4
  574. PCAP_API FILE *pcap_file(pcap_t *);
  575. #ifdef _WIN32
  576. /*
  577. * This probably shouldn't have been kept in WinPcap; most if not all
  578. * UN*X code that used it won't work on Windows. We deprecate it; if
  579. * anybody really needs access to whatever HANDLE may be associated
  580. * with a pcap_t (there's no guarantee that there is one), we can add
  581. * a Windows-only pcap_handle() API that returns the HANDLE.
  582. */
  583. PCAP_AVAILABLE_0_4
  584. PCAP_API int pcap_fileno(pcap_t *)
  585. PCAP_DEPRECATED(pcap_fileno, "request a 'pcap_handle' that returns a HANDLE if you need it");
  586. #else /* _WIN32 */
  587. PCAP_AVAILABLE_0_4
  588. PCAP_API int pcap_fileno(pcap_t *);
  589. #endif /* _WIN32 */
  590. #ifdef _WIN32
  591. PCAP_API int pcap_wsockinit(void);
  592. #endif
  593. PCAP_AVAILABLE_0_4
  594. PCAP_API pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
  595. #ifdef _WIN32
  596. PCAP_AVAILABLE_0_9
  597. PCAP_API pcap_dumper_t *pcap_dump_hopen(pcap_t *, intptr_t);
  598. /*
  599. * If we're building libpcap, this is an internal routine in sf-pcap.c, so
  600. * we must not define it as a macro.
  601. *
  602. * If we're not building libpcap, given that the version of the C runtime
  603. * with which libpcap was built might be different from the version
  604. * of the C runtime with which an application using libpcap was built,
  605. * and that a FILE structure may differ between the two versions of the
  606. * C runtime, calls to _fileno() must use the version of _fileno() in
  607. * the C runtime used to open the FILE *, not the version in the C
  608. * runtime with which libpcap was built. (Maybe once the Universal CRT
  609. * rules the world, this will cease to be a problem.)
  610. */
  611. #ifndef BUILDING_PCAP
  612. #define pcap_dump_fopen(p,f) \
  613. pcap_dump_hopen(p, _get_osfhandle(_fileno(f)))
  614. #endif
  615. #else /*_WIN32*/
  616. PCAP_AVAILABLE_0_9
  617. PCAP_API pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
  618. #endif /*_WIN32*/
  619. PCAP_AVAILABLE_1_7
  620. PCAP_API pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *);
  621. PCAP_AVAILABLE_0_8
  622. PCAP_API FILE *pcap_dump_file(pcap_dumper_t *);
  623. PCAP_AVAILABLE_0_9
  624. PCAP_API long pcap_dump_ftell(pcap_dumper_t *);
  625. PCAP_AVAILABLE_1_9
  626. PCAP_API int64_t pcap_dump_ftell64(pcap_dumper_t *);
  627. PCAP_AVAILABLE_0_8
  628. PCAP_API int pcap_dump_flush(pcap_dumper_t *);
  629. PCAP_AVAILABLE_0_4
  630. PCAP_API void pcap_dump_close(pcap_dumper_t *);
  631. PCAP_AVAILABLE_0_4
  632. PCAP_API void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
  633. PCAP_AVAILABLE_0_7
  634. PCAP_API int pcap_findalldevs(pcap_if_t **, char *);
  635. PCAP_AVAILABLE_0_7
  636. PCAP_API void pcap_freealldevs(pcap_if_t *);
  637. /*
  638. * We return a pointer to the version string, rather than exporting the
  639. * version string directly.
  640. *
  641. * On at least some UNIXes, if you import data from a shared library into
  642. * a program, the data is bound into the program binary, so if the string
  643. * in the version of the library with which the program was linked isn't
  644. * the same as the string in the version of the library with which the
  645. * program is being run, various undesirable things may happen (warnings,
  646. * the string being the one from the version of the library with which the
  647. * program was linked, or even weirder things, such as the string being the
  648. * one from the library but being truncated).
  649. *
  650. * On Windows, the string is constructed at run time.
  651. */
  652. PCAP_AVAILABLE_0_8
  653. PCAP_API const char *pcap_lib_version(void);
  654. #if defined(_WIN32)
  655. /*
  656. * Win32 definitions
  657. */
  658. /*!
  659. \brief A queue of raw packets that will be sent to the network with pcap_sendqueue_transmit().
  660. */
  661. struct pcap_send_queue
  662. {
  663. u_int maxlen; /* Maximum size of the queue, in bytes. This
  664. variable contains the size of the buffer field. */
  665. u_int len; /* Current size of the queue, in bytes. */
  666. char *buffer; /* Buffer containing the packets to be sent. */
  667. };
  668. typedef struct pcap_send_queue pcap_send_queue;
  669. /*!
  670. \brief This typedef is a support for the pcap_get_airpcap_handle() function
  671. */
  672. #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
  673. #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
  674. typedef struct _AirpcapHandle *PAirpcapHandle;
  675. #endif
  676. PCAP_API int pcap_setbuff(pcap_t *p, int dim);
  677. PCAP_API int pcap_setmode(pcap_t *p, int mode);
  678. PCAP_API int pcap_setmintocopy(pcap_t *p, int size);
  679. PCAP_API HANDLE pcap_getevent(pcap_t *p);
  680. PCAP_AVAILABLE_1_8
  681. PCAP_API int pcap_oid_get_request(pcap_t *, bpf_u_int32, void *, size_t *);
  682. PCAP_AVAILABLE_1_8
  683. PCAP_API int pcap_oid_set_request(pcap_t *, bpf_u_int32, const void *, size_t *);
  684. PCAP_API pcap_send_queue* pcap_sendqueue_alloc(u_int memsize);
  685. PCAP_API void pcap_sendqueue_destroy(pcap_send_queue* queue);
  686. PCAP_API int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data);
  687. PCAP_API u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync);
  688. PCAP_API struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size);
  689. PCAP_API int pcap_setuserbuffer(pcap_t *p, int size);
  690. PCAP_API int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks);
  691. PCAP_API int pcap_live_dump_ended(pcap_t *p, int sync);
  692. PCAP_API int pcap_start_oem(char* err_str, int flags);
  693. PCAP_API PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p);
  694. #define MODE_CAPT 0
  695. #define MODE_STAT 1
  696. #define MODE_MON 2
  697. #elif defined(MSDOS)
  698. /*
  699. * MS-DOS definitions
  700. */
  701. PCAP_API int pcap_stats_ex (pcap_t *, struct pcap_stat_ex *);
  702. PCAP_API void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait);
  703. PCAP_API u_long pcap_mac_packets (void);
  704. #else /* UN*X */
  705. /*
  706. * UN*X definitions
  707. */
  708. PCAP_AVAILABLE_0_8
  709. PCAP_API int pcap_get_selectable_fd(pcap_t *);
  710. PCAP_AVAILABLE_1_9
  711. PCAP_API const struct timeval *pcap_get_required_select_timeout(pcap_t *);
  712. #endif /* _WIN32/MSDOS/UN*X */
  713. /*
  714. * Remote capture definitions.
  715. *
  716. * These routines are only present if libpcap has been configured to
  717. * include remote capture support.
  718. */
  719. /*
  720. * The maximum buffer size in which address, port, interface names are kept.
  721. *
  722. * In case the adapter name or such is larger than this value, it is truncated.
  723. * This is not used by the user; however it must be aware that an hostname / interface
  724. * name longer than this value will be truncated.
  725. */
  726. #define PCAP_BUF_SIZE 1024
  727. /*
  728. * The type of input source, passed to pcap_open().
  729. */
  730. #define PCAP_SRC_FILE 2 /* local savefile */
  731. #define PCAP_SRC_IFLOCAL 3 /* local network interface */
  732. #define PCAP_SRC_IFREMOTE 4 /* interface on a remote host, using RPCAP */
  733. /*
  734. * The formats allowed by pcap_open() are the following:
  735. * - file://path_and_filename [opens a local file]
  736. * - rpcap://devicename [opens the selected device available on the local host, without using the RPCAP protocol]
  737. * - rpcap://host/devicename [opens the selected device available on a remote host]
  738. * - rpcap://host:port/devicename [opens the selected device available on a remote host, using a non-standard port for RPCAP]
  739. * - adaptername [to open a local adapter; kept for compatibility, but it is strongly discouraged]
  740. * - (NULL) [to open the first local adapter; kept for compatibility, but it is strongly discouraged]
  741. *
  742. * The formats allowed by the pcap_findalldevs_ex() are the following:
  743. * - file://folder/ [lists all the files in the given folder]
  744. * - rpcap:// [lists all local adapters]
  745. * - rpcap://host:port/ [lists the devices available on a remote host]
  746. *
  747. * In all the above, "rpcaps://" can be substituted for "rpcap://" to enable
  748. * SSL (if it has been compiled in).
  749. *
  750. * Referring to the 'host' and 'port' parameters, they can be either numeric or literal. Since
  751. * IPv6 is fully supported, these are the allowed formats:
  752. *
  753. * - host (literal): e.g. host.foo.bar
  754. * - host (numeric IPv4): e.g. 10.11.12.13
  755. * - host (numeric IPv4, IPv6 style): e.g. [10.11.12.13]
  756. * - host (numeric IPv6): e.g. [1:2:3::4]
  757. * - port: can be either numeric (e.g. '80') or literal (e.g. 'http')
  758. *
  759. * Here you find some allowed examples:
  760. * - rpcap://host.foo.bar/devicename [everything literal, no port number]
  761. * - rpcap://host.foo.bar:1234/devicename [everything literal, with port number]
  762. * - rpcap://10.11.12.13/devicename [IPv4 numeric, no port number]
  763. * - rpcap://10.11.12.13:1234/devicename [IPv4 numeric, with port number]
  764. * - rpcap://[10.11.12.13]:1234/devicename [IPv4 numeric with IPv6 format, with port number]
  765. * - rpcap://[1:2:3::4]/devicename [IPv6 numeric, no port number]
  766. * - rpcap://[1:2:3::4]:1234/devicename [IPv6 numeric, with port number]
  767. * - rpcap://[1:2:3::4]:http/devicename [IPv6 numeric, with literal port number]
  768. */
  769. /*
  770. * URL schemes for capture source.
  771. */
  772. /*
  773. * This string indicates that the user wants to open a capture from a
  774. * local file.
  775. */
  776. #define PCAP_SRC_FILE_STRING "file://"
  777. /*
  778. * This string indicates that the user wants to open a capture from a
  779. * network interface. This string does not necessarily involve the use
  780. * of the RPCAP protocol. If the interface required resides on the local
  781. * host, the RPCAP protocol is not involved and the local functions are used.
  782. */
  783. #define PCAP_SRC_IF_STRING "rpcap://"
  784. /*
  785. * Flags to pass to pcap_open().
  786. */
  787. /*
  788. * Specifies whether promiscuous mode is to be used.
  789. */
  790. #define PCAP_OPENFLAG_PROMISCUOUS 0x00000001
  791. /*
  792. * Specifies, for an RPCAP capture, whether the data transfer (in
  793. * case of a remote capture) has to be done with UDP protocol.
  794. *
  795. * If it is '1' if you want a UDP data connection, '0' if you want
  796. * a TCP data connection; control connection is always TCP-based.
  797. * A UDP connection is much lighter, but it does not guarantee that all
  798. * the captured packets arrive to the client workstation. Moreover,
  799. * it could be harmful in case of network congestion.
  800. * This flag is meaningless if the source is not a remote interface.
  801. * In that case, it is simply ignored.
  802. */
  803. #define PCAP_OPENFLAG_DATATX_UDP 0x00000002
  804. /*
  805. * Specifies whether the remote probe will capture its own generated
  806. * traffic.
  807. *
  808. * In case the remote probe uses the same interface to capture traffic
  809. * and to send data back to the caller, the captured traffic includes
  810. * the RPCAP traffic as well. If this flag is turned on, the RPCAP
  811. * traffic is excluded from the capture, so that the trace returned
  812. * back to the collector is does not include this traffic.
  813. *
  814. * Has no effect on local interfaces or savefiles.
  815. */
  816. #define PCAP_OPENFLAG_NOCAPTURE_RPCAP 0x00000004
  817. /*
  818. * Specifies whether the local adapter will capture its own generated traffic.
  819. *
  820. * This flag tells the underlying capture driver to drop the packets
  821. * that were sent by itself. This is useful when building applications
  822. * such as bridges that should ignore the traffic they just sent.
  823. *
  824. * Supported only on Windows.
  825. */
  826. #define PCAP_OPENFLAG_NOCAPTURE_LOCAL 0x00000008
  827. /*
  828. * This flag configures the adapter for maximum responsiveness.
  829. *
  830. * In presence of a large value for nbytes, WinPcap waits for the arrival
  831. * of several packets before copying the data to the user. This guarantees
  832. * a low number of system calls, i.e. lower processor usage, i.e. better
  833. * performance, which is good for applications like sniffers. If the user
  834. * sets the PCAP_OPENFLAG_MAX_RESPONSIVENESS flag, the capture driver will
  835. * copy the packets as soon as the application is ready to receive them.
  836. * This is suggested for real time applications (such as, for example,
  837. * a bridge) that need the best responsiveness.
  838. *
  839. * The equivalent with pcap_create()/pcap_activate() is "immediate mode".
  840. */
  841. #define PCAP_OPENFLAG_MAX_RESPONSIVENESS 0x00000010
  842. /*
  843. * Remote authentication methods.
  844. * These are used in the 'type' member of the pcap_rmtauth structure.
  845. */
  846. /*
  847. * NULL authentication.
  848. *
  849. * The 'NULL' authentication has to be equal to 'zero', so that old
  850. * applications can just put every field of struct pcap_rmtauth to zero,
  851. * and it does work.
  852. */
  853. #define RPCAP_RMTAUTH_NULL 0
  854. /*
  855. * Username/password authentication.
  856. *
  857. * With this type of authentication, the RPCAP protocol will use the username/
  858. * password provided to authenticate the user on the remote machine. If the
  859. * authentication is successful (and the user has the right to open network
  860. * devices) the RPCAP connection will continue; otherwise it will be dropped.
  861. *
  862. * *******NOTE********: unless TLS is being used, the username and password
  863. * are sent over the network to the capture server *IN CLEAR TEXT*. Don't
  864. * use this, without TLS (i.e., with rpcap:// rather than rpcaps://) on
  865. * a network that you don't completely control! (And be *really* careful
  866. * in your definition of "completely"!)
  867. */
  868. #define RPCAP_RMTAUTH_PWD 1
  869. /*
  870. * This structure keeps the information needed to authenticate the user
  871. * on a remote machine.
  872. *
  873. * The remote machine can either grant or refuse the access according
  874. * to the information provided.
  875. * In case the NULL authentication is required, both 'username' and
  876. * 'password' can be NULL pointers.
  877. *
  878. * This structure is meaningless if the source is not a remote interface;
  879. * in that case, the functions which requires such a structure can accept
  880. * a NULL pointer as well.
  881. */
  882. struct pcap_rmtauth
  883. {
  884. /*
  885. * \brief Type of the authentication required.
  886. *
  887. * In order to provide maximum flexibility, we can support different types
  888. * of authentication based on the value of this 'type' variable. The currently
  889. * supported authentication methods are defined into the
  890. * \link remote_auth_methods Remote Authentication Methods Section\endlink.
  891. */
  892. int type;
  893. /*
  894. * \brief Zero-terminated string containing the username that has to be
  895. * used on the remote machine for authentication.
  896. *
  897. * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
  898. * and it can be NULL.
  899. */
  900. char *username;
  901. /*
  902. * \brief Zero-terminated string containing the password that has to be
  903. * used on the remote machine for authentication.
  904. *
  905. * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
  906. * and it can be NULL.
  907. */
  908. char *password;
  909. };
  910. /*
  911. * This routine can open a savefile, a local device, or a device on
  912. * a remote machine running an RPCAP server.
  913. *
  914. * For opening a savefile, the pcap_open_offline routines can be used,
  915. * and will work just as well; code using them will work on more
  916. * platforms than code using pcap_open() to open savefiles.
  917. *
  918. * For opening a local device, pcap_open_live() can be used; it supports
  919. * most of the capabilities that pcap_open() supports, and code using it
  920. * will work on more platforms than code using pcap_open(). pcap_create()
  921. * and pcap_activate() can also be used; they support all capabilities
  922. * that pcap_open() supports, except for the Windows-only
  923. * PCAP_OPENFLAG_NOCAPTURE_LOCAL, and support additional capabilities.
  924. *
  925. * For opening a remote capture, pcap_open() is currently the only
  926. * API available.
  927. */
  928. PCAP_AVAILABLE_1_9
  929. PCAP_API pcap_t *pcap_open(const char *source, int snaplen, int flags,
  930. int read_timeout, struct pcap_rmtauth *auth, char *errbuf);
  931. PCAP_AVAILABLE_1_9
  932. PCAP_API int pcap_createsrcstr(char *source, int type, const char *host,
  933. const char *port, const char *name, char *errbuf);
  934. PCAP_AVAILABLE_1_9
  935. PCAP_API int pcap_parsesrcstr(const char *source, int *type, char *host,
  936. char *port, char *name, char *errbuf);
  937. /*
  938. * This routine can scan a directory for savefiles, list local capture
  939. * devices, or list capture devices on a remote machine running an RPCAP
  940. * server.
  941. *
  942. * For scanning for savefiles, it can be used on both UN*X systems and
  943. * Windows systems; for each directory entry it sees, it tries to open
  944. * the file as a savefile using pcap_open_offline(), and only includes
  945. * it in the list of files if the open succeeds, so it filters out
  946. * files for which the user doesn't have read permission, as well as
  947. * files that aren't valid savefiles readable by libpcap.
  948. *
  949. * For listing local capture devices, it's just a wrapper around
  950. * pcap_findalldevs(); code using pcap_findalldevs() will work on more
  951. * platforms than code using pcap_findalldevs_ex().
  952. *
  953. * For listing remote capture devices, pcap_findalldevs_ex() is currently
  954. * the only API available.
  955. */
  956. PCAP_AVAILABLE_1_9
  957. PCAP_API int pcap_findalldevs_ex(const char *source,
  958. struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf);
  959. /*
  960. * Sampling methods.
  961. *
  962. * These allow pcap_loop(), pcap_dispatch(), pcap_next(), and pcap_next_ex()
  963. * to see only a sample of packets, rather than all packets.
  964. *
  965. * Currently, they work only on Windows local captures.
  966. */
  967. /*
  968. * Specifies that no sampling is to be done on the current capture.
  969. *
  970. * In this case, no sampling algorithms are applied to the current capture.
  971. */
  972. #define PCAP_SAMP_NOSAMP 0
  973. /*
  974. * Specifies that only 1 out of N packets must be returned to the user.
  975. *
  976. * In this case, the 'value' field of the 'pcap_samp' structure indicates the
  977. * number of packets (minus 1) that must be discarded before one packet got
  978. * accepted.
  979. * In other words, if 'value = 10', the first packet is returned to the
  980. * caller, while the following 9 are discarded.
  981. */
  982. #define PCAP_SAMP_1_EVERY_N 1
  983. /*
  984. * Specifies that we have to return 1 packet every N milliseconds.
  985. *
  986. * In this case, the 'value' field of the 'pcap_samp' structure indicates
  987. * the 'waiting time' in milliseconds before one packet got accepted.
  988. * In other words, if 'value = 10', the first packet is returned to the
  989. * caller; the next returned one will be the first packet that arrives
  990. * when 10ms have elapsed.
  991. */
  992. #define PCAP_SAMP_FIRST_AFTER_N_MS 2
  993. /*
  994. * This structure defines the information related to sampling.
  995. *
  996. * In case the sampling is requested, the capturing device should read
  997. * only a subset of the packets coming from the source. The returned packets
  998. * depend on the sampling parameters.
  999. *
  1000. * WARNING: The sampling process is applied *after* the filtering process.
  1001. * In other words, packets are filtered first, then the sampling process
  1002. * selects a subset of the 'filtered' packets and it returns them to the
  1003. * caller.
  1004. */
  1005. struct pcap_samp
  1006. {
  1007. /*
  1008. * Method used for sampling; see above.
  1009. */
  1010. int method;
  1011. /*
  1012. * This value depends on the sampling method defined.
  1013. * For its meaning, see above.
  1014. */
  1015. int value;
  1016. };
  1017. /*
  1018. * New functions.
  1019. */
  1020. PCAP_AVAILABLE_1_9
  1021. PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p);
  1022. /*
  1023. * RPCAP active mode.
  1024. */
  1025. /* Maximum length of an host name (needed for the RPCAP active mode) */
  1026. #define RPCAP_HOSTLIST_SIZE 1024
  1027. PCAP_AVAILABLE_1_9
  1028. PCAP_API SOCKET pcap_remoteact_accept(const char *address, const char *port,
  1029. const char *hostlist, char *connectinghost,
  1030. struct pcap_rmtauth *auth, char *errbuf);
  1031. PCAP_AVAILABLE_1_10
  1032. PCAP_API SOCKET pcap_remoteact_accept_ex(const char *address, const char *port,
  1033. const char *hostlist, char *connectinghost,
  1034. struct pcap_rmtauth *auth, int uses_ssl, char *errbuf);
  1035. PCAP_AVAILABLE_1_9
  1036. PCAP_API int pcap_remoteact_list(char *hostlist, char sep, int size,
  1037. char *errbuf);
  1038. PCAP_AVAILABLE_1_9
  1039. PCAP_API int pcap_remoteact_close(const char *host, char *errbuf);
  1040. PCAP_AVAILABLE_1_9
  1041. PCAP_API void pcap_remoteact_cleanup(void);
  1042. #ifdef __cplusplus
  1043. }
  1044. #endif
  1045. #endif /* lib_pcap_pcap_h */