pcap.pp 12 KB

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