pcap.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. unit Pcap;
  2. { -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- }
  3. {
  4. * Copyright (c) 1993, 1994, 1995, 1996, 1997
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  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. All advertising materials mentioning features or use of this software
  16. * must display the following acknowledgement:
  17. * This product includes software developed by the Computer Systems
  18. * Engineering Group at Lawrence Berkeley Laboratory.
  19. * 4. Neither the name of the University nor of the Laboratory may be used
  20. * to endorse or promote products derived from this software without
  21. * specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. * SUCH DAMAGE.
  34. *
  35. * $FreeBSD: src/contrib/libpcap/pcap.h,v 1.11 2005/07/11 03:43:25 sam Exp $
  36. * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.52 2004/12/18 08:52:11 guy Exp $ (LBL)
  37. }
  38. interface
  39. uses
  40. {$ifdef UNIX}
  41. BaseUnix,
  42. {$endif}
  43. {$ifdef Windows}
  44. WinSock, Windows,
  45. {$endif}
  46. Types, Sockets;
  47. {$IFDEF FPC}
  48. {$PACKRECORDS C}
  49. {$ifndef NO_SMART_LINK}
  50. {$smartlink on}
  51. {$endif}
  52. {$ENDIF}
  53. const
  54. {$ifdef unix}
  55. {$linklib c}
  56. PCAP_LIB_NAME = 'libpcap';
  57. {$endif}
  58. {$ifdef WINDOWS}
  59. PCAP_LIB_NAME = 'wpcap';
  60. {$endif}
  61. PCAP_VERSION_MAJOR = 2;
  62. PCAP_VERSION_MINOR = 4;
  63. PCAP_ERRBUF_SIZE = 256;
  64. { interface is loopback }
  65. PCAP_IF_LOOPBACK = $00000001;
  66. {
  67. * The first record in the file contains saved values for some
  68. * of the flags used in the printout phases of tcpdump.
  69. * Many fields here are 32 bit ints so compilers won't insert unwanted
  70. * padding; these files need to be interchangeable across architectures.
  71. *
  72. * Do not change the layout of this structure, in any way (this includes
  73. * changes that only affect the length of fields in this structure).
  74. *
  75. * Also, do not change the interpretation of any of the members of this
  76. * structure, in any way (this includes using values other than
  77. * LINKTYPE_ values, as defined in "savefile.c", in the "linktype"
  78. * field).
  79. *
  80. * Instead:
  81. *
  82. * introduce a new structure for the new format, if the layout
  83. * of the structure changed;
  84. *
  85. * send mail to "[email protected]", requesting a new
  86. * magic number for your new capture file format, and, when
  87. * you get the new magic number, put it in "savefile.c";
  88. *
  89. * use that magic number for save files with the changed file
  90. * header;
  91. *
  92. * make the code in "savefile.c" capable of reading files with
  93. * the old file header as well as files with the new file header
  94. * (using the magic number to determine the header format).
  95. *
  96. * Then supply the changes to "[email protected]", so that future
  97. * versions of libpcap and programs that use it (such as tcpdump) will
  98. * be able to read your new capture file format.
  99. }
  100. { gmt to local correction }
  101. { accuracy of timestamps }
  102. { max length saved portion of each pkt }
  103. { data link type (LINKTYPE_*) }
  104. type
  105. PPLongint = ^PLongint;
  106. PPcap_File_Header = ^TPcap_File_Header;
  107. TPcap_File_Header = record
  108. magic : DWord;
  109. version_major : Word;
  110. version_minor : Word;
  111. thiszone : Longint;
  112. sigfigs : DWord;
  113. snaplen : DWord;
  114. linktype : DWord;
  115. end;
  116. PBPF_Insn = ^TBPF_Insn;
  117. TBPF_Insn = record
  118. code: Word;
  119. jt: Byte;
  120. jf: Byte;
  121. k: DWord;
  122. end;
  123. PBPF_Program = ^TBPF_Program;
  124. TBPF_Program = record
  125. bf_len: PtrInt;
  126. bf_insns: PBPF_Insn;
  127. end;
  128. PDirection = ^TDirection;
  129. TDirection = (D_INOUT, D_IN, D_OUT);
  130. {
  131. * Each packet in the dump file is prepended with this generic header.
  132. * This gets around the problem of different headers for different
  133. * packet interfaces.
  134. }
  135. { time stamp }
  136. { length of portion present }
  137. { length this packet (off wire) }
  138. PPPcap_Pkthdr = ^PPcap_Pkthdr;
  139. PPcap_Pkthdr = ^TPcap_Pkthdr;
  140. TPcap_Pkthdr = record
  141. ts : TTimeVal;
  142. caplen : DWord;
  143. len : DWord;
  144. end;
  145. {
  146. * As returned by the pcap_stats()
  147. }
  148. { number of packets received }
  149. { number of packets dropped }
  150. { drops by interface XXX not yet supported }
  151. PPcap_Stat = ^TPcap_Stat;
  152. TPcap_Stat = record
  153. ps_recv : DWord;
  154. ps_drop : DWord;
  155. ps_ifdrop : DWord;
  156. bs_capt : DWord;
  157. end;
  158. {
  159. * Representation of an interface address.
  160. }
  161. { address }
  162. { netmask for that address }
  163. { broadcast address for that address }
  164. { P2P destination address for that address }
  165. PPcap_Addr = ^TPcap_Addr;
  166. TPcap_Addr = record
  167. next : PPcap_Addr;
  168. addr : PSockAddr;
  169. netmask : PSockAddr;
  170. broadaddr : PSockAddr;
  171. dstaddr : PSockAddr;
  172. end;
  173. {
  174. * Item in a list of interfaces.
  175. }
  176. { name to hand to "pcap_open_live()" }
  177. { textual description of interface, or NULL }
  178. { PCAP_IF_ interface flags }
  179. PPPcap_If = ^PPcap_If;
  180. PPcap_If = ^TPcap_If;
  181. TPcap_If = record
  182. next : PPcap_If;
  183. name : PChar;
  184. description : PChar;
  185. addresses : PPcap_Addr;
  186. flags : DWord;
  187. end;
  188. { obfuscated C types }
  189. PPcap = ^TPcap;
  190. TPcap = record end;
  191. PPcapDumper = ^TPcapDumper;
  192. TPcapDumper = record end;
  193. TPcapHandler = procedure (para1: PChar; Header: PPcap_Pkthdr; Data: PChar); cdecl;
  194. function pcap_lookupdev(ErrBuf: PChar): PChar; cdecl; external PCAP_LIB_NAME;
  195. function pcap_lookupnet(Device: PChar; NetP: PDword;
  196. MaskP: PDword; ErrBuf: PChar): Longint; cdecl; external PCAP_LIB_NAME;
  197. function pcap_open_live(Device : PChar; SnapLen: Longint; Promisc: Longint;
  198. to_ms: Longint; ebuf: PChar): PPcap; cdecl; external PCAP_LIB_NAME;
  199. function pcap_open_dead(LinkType: Longint; SnapLen: Longint): PPcap; cdecl; external PCAP_LIB_NAME;
  200. function pcap_open_offline(FileName: PChar; ErrBuf: PChar): PPcap; cdecl; external PCAP_LIB_NAME;
  201. // function pcap_fopen_offline(para1:PFILE; para2:PChar): PPcap; cdecl; external PCAP_LIB_NAME;
  202. procedure pcap_close(p :PPcap); cdecl; external PCAP_LIB_NAME;
  203. function pcap_loop(p: PPcap; cnt: Longint; Callback: TPCapHandler; User: PChar): Longint; cdecl; external PCAP_LIB_NAME;
  204. function pcap_dispatch(p: PPcap; cnt: Longint; Callback: TPCapHandler; User: PChar): Longint; cdecl; external PCAP_LIB_NAME;
  205. function pcap_next(para1: PPcap; para2:PPcap_Pkthdr): PChar; cdecl; external PCAP_LIB_NAME;
  206. function pcap_next_ex(para1: PPcap; para2:PPPcap_Pkthdr; para3:PPChar): Longint; cdecl; external PCAP_LIB_NAME;
  207. procedure pcap_breakloop(para1:PPcap); cdecl; external PCAP_LIB_NAME;
  208. function pcap_stats(para1: PPcap; para2:PPcap_Stat): Longint; cdecl; external PCAP_LIB_NAME;
  209. function pcap_setfilter(para1: PPcap; para2:PBPF_Program): Longint; cdecl; external PCAP_LIB_NAME;
  210. function pcap_setdirection(para1: PPcap; para2:TDirection): Longint; cdecl; external PCAP_LIB_NAME;
  211. function pcap_getnonblock(para1: PPcap; para2:PChar): Longint; cdecl; external PCAP_LIB_NAME;
  212. function pcap_setnonblock(para1: PPcap; para2: Longint; para3:PChar): Longint; cdecl; external PCAP_LIB_NAME;
  213. procedure pcap_perror(para1: PPcap; para2:PChar); cdecl; external PCAP_LIB_NAME;
  214. function pcap_inject(para1: PPcap; para2:pointer; para3: TSize): Longint; cdecl; external PCAP_LIB_NAME;
  215. function pcap_sendpacket(para1: PPcap; para2: PChar; para3:Longint): Longint; cdecl; external PCAP_LIB_NAME;
  216. function pcap_strerror(para1:Longint): PChar; cdecl; external PCAP_LIB_NAME;
  217. function pcap_geterr(para1:PPcap): PChar; cdecl; external PCAP_LIB_NAME;
  218. function pcap_compile(para1: PPcap; para2:PBPF_Program; para3: PChar; para4: Longint; para5:DWord): Longint; cdecl; external PCAP_LIB_NAME;
  219. function pcap_compile_nopcap(para1: Longint; para2: Longint; para3:PBPF_Program; para4: PChar; para5: Longint;
  220. para6:DWord): Longint; cdecl; external PCAP_LIB_NAME;
  221. procedure pcap_freecode(para1:PBPF_Program); cdecl; external PCAP_LIB_NAME;
  222. function pcap_datalink(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;
  223. function pcap_list_datalinks(para1: PPcap; para2:PPLongint): Longint; cdecl; external PCAP_LIB_NAME;
  224. function pcap_set_datalink(para1: PPcap; para2:Longint): Longint; cdecl; external PCAP_LIB_NAME;
  225. function pcap_datalink_name_to_val(para1:PChar): Longint; cdecl; external PCAP_LIB_NAME;
  226. function pcap_datalink_val_to_name(para1:Longint): PChar; cdecl; external PCAP_LIB_NAME;
  227. function pcap_datalink_val_to_description(para1:Longint): PChar; cdecl; external PCAP_LIB_NAME;
  228. function pcap_snapshot(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;
  229. function pcap_is_swapped(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;
  230. function pcap_major_version(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;
  231. function pcap_minor_version(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;
  232. { XXX }
  233. // function pcap_file(para1:PPcap):PFILE; cdecl; external PCAP_LIB_NAME;
  234. function pcap_fileno(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;
  235. function pcap_dump_open(para1: PPcap; para2:PChar):PPCapDumper; cdecl; external PCAP_LIB_NAME;
  236. // function pcap_dump_fopen(para1: PPcap; fp:PFILE):PPCapDumper; cdecl; external PCAP_LIB_NAME;
  237. // function pcap_dump_file(para1:PPCapDumper):PFILE; cdecl; external PCAP_LIB_NAME;
  238. function pcap_dump_ftell(para1:PPCapDumper): Longint; cdecl; external PCAP_LIB_NAME;
  239. function pcap_dump_flush(para1:PPCapDumper): Longint; cdecl; external PCAP_LIB_NAME;
  240. procedure pcap_dump_close(para1:PPCapDumper); cdecl; external PCAP_LIB_NAME;
  241. procedure pcap_dump(para1: PChar; para2:PPcap_Pkthdr; para3:PChar); cdecl; external PCAP_LIB_NAME;
  242. function pcap_findalldevs(para1:PPPcap_If; para2:PChar): Longint; cdecl; external PCAP_LIB_NAME;
  243. procedure pcap_freealldevs(para1:PPcap_If); cdecl; external PCAP_LIB_NAME;
  244. function pcap_lib_version: PChar; cdecl; external PCAP_LIB_NAME;
  245. { XXX this guy lives in the bpf tree }
  246. function bpf_filter(para1:Pbpf_insn; para2: PChar; para3:PtrInt; para4:PtrInt):PtrInt; cdecl; external PCAP_LIB_NAME;
  247. function bpf_validate(f:Pbpf_insn; len:Longint): Longint; cdecl; external PCAP_LIB_NAME;
  248. function bpf_image(para1:Pbpf_insn; para2:Longint): PChar; cdecl; external PCAP_LIB_NAME;
  249. procedure bpf_dump(para1:PBPF_Program; para2:Longint); cdecl; external PCAP_LIB_NAME;
  250. {$ifdef WINDOWS}
  251. function pcap_setbuff(p: PPcap; dim:Longint): Longint; cdecl; external PCAP_LIB_NAME;
  252. function pcap_setmode(p: PPcap; mode:Longint): Longint; cdecl; external PCAP_LIB_NAME;
  253. function pcap_setmintocopy(p: PPcap; size:Longint): Longint; cdecl; external PCAP_LIB_NAME;
  254. {$endif}
  255. {$ifdef unix}
  256. function pcap_get_selectable_fd(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;
  257. {$endif}
  258. implementation
  259. end.