2 // purpose: Packet sniffer for use with the open source WinPcap driver
3 // author: Authorized KOL version, © 2005, Thaddy de Koning
4 // Original version © Umar Sear
5 // Remarks: The WinPCap driver is free ware and available from
6 // http://winpcap.polito.it/ under a BSD style license
8 // This KOL demo and the KOL headerfile translations are not freeware
9 // They are subject to the same license as Umar states in his header
12 {********************************************************************************
13 --------------------------------------------------------------------------------
14 header conversion for Delphi
18 Packet Capture Driver by Politecnico di Torino
21 --------------------------------------------------------------------------------
23 TERMS AND CONDITIONS OF USE.
25 Code in this unit is Copyright(C) 2003 Umar Sear
27 The author of this software assumes no liability for damages caused under
28 any circumstances whatsoever, and is under no obligation. Use of the software
29 indicates acceptance of all conditions contained in this document. If you do
30 not agree to these terms, you must delete this software immediately.
32 You may distribute the archive in which this software is distributed, but
33 under no circumstances must this archive be changed. Distributing a modified
34 archive is a violation of the software license.
36 If you do redistribute this software, please let me know at the email address
39 This software is not freeware, if you wish to use it other than for trial
40 purposes, please contact me for a full licence.
42 If you have any questions, requests, bug reports, etc., please contact me at
43 the address given below.
46 Email : usear@yahoo.com
49 webpsite: http://netgroup-serv.polito.it
50 ********************************************************************************}
56 uses Windows
,kol
,kolwinpcaptypes
;
60 DLL
= 'wpcap.dll'; // Name of DLL file
61 DEFAULT_DRIVERBUFFER
= 1000000; // Dimension of the buffer in driver
62 MAX_LINK_NAME_LENGTH
= 64; // Adapters symbolic names maximum length
63 PcapBufSize
= 256000; // Dimension of the buffer in TPcap
64 DEFAULT_SNAPLEN
= 68; // Default Snapshot length
68 PTpcap_handler
=^Tpcap_handler
;
69 Tpcap_handler
= procedure(User
:pointer;const Header
:PTpcap_pkthdr
;const Data
:Pointer);
73 TDllpcap_loop
= function (P
:Ppcap
;cnt
:Integer;callback
:PTpcap_handler
;user
:Pointer):Integer; cdecl;
74 TDllpcap_open_dead
= function (linktype
:integer; SnapLen
:Integer):ppcap
; cdecl;
75 TDllpcap_open_live
= function (Device
:Pchar
; SnapLen
:Integer; Promisc
:Integer;To_ms
:Integer;
76 errstr
:Pchar
) : ppcap
; cdecl;
77 TDllpcap_dispatch
= function (P
:PPcap
;cnt
:Integer;callback
:PTpcap_handler
;user
:Pointer):Integer; cdecl;
78 TDllpcap_datalink
= function (P
:Ppcap
) : Integer; cdecl;
79 TDllpcap_read
= function (p
:Ppcap
;cnt
:Integer;callBack
:PTpcap_handler
;user
:pointer) :Integer; cdecl;
80 TDllpcap_read_ex
= function (p
:Ppcap
;Header
:Ppcap_pkthdr
;data
:pointer) :Integer; cdecl;
81 TDllpcap_stats_ex
= function (P
:Ppcap
;ps
:Ppcap_stat
) : Integer; cdecl; //remove
82 TDllpcap_setbuff
= function (p
:Ppcap
;dim
:Integer) : Integer; cdecl;
83 TDllpcap_findalldevs
= function (alldevp
: Pppcap_if
;errstr
:Pchar
):Integer; cdecl;
84 TDllpcapsetfilter
= function (P
:PPcap
;fp
:Pbpf_program
):integer; cdecl;
85 TDllpcap_compile
= function (P
:PPcap
;fp
:Pbpf_program
;str
:String;optimize
:Integer;bpf_u_int32
:LongWord
):Integer; cdecl;
86 TDllpcap_major_version
= function (p
: Ppcap
):Integer; cdecl;
87 TDllpcap_minor_version
= function (p
: Ppcap
):Integer; cdecl;
88 TDllpcap_snapshot
= Function (p
: Ppcap
):Integer; cdecl;
89 TDllpcap_geterr
= Function (p
: Ppcap
):Pchar
; cdecl;
90 TDLLpcap_freealldevs
= procedure(alldevsp
: ppcap_if
);cdecl;
91 TDllpcap_close
= procedure(p
: ppcap
); cdecl;
92 TDllpcap_freecode
= procedure(fp
:Pbpf_program
); cdecl;
96 pcap_dispatch
: TDllpcap_dispatch
;
97 pcap_loop
: TDllpcap_loop
;
98 pcap_open_live
: TDllpcap_open_live
;
99 pcap_open_dead
: TDllpcap_open_dead
;
100 pcap_datalink
: TDllpcap_datalink
;
101 pcap_freecode
: TDllpcap_freecode
;
102 pcap_read
: TDllpcap_read
;
103 pcap_read_ex
: TDllpcap_read_ex
;
104 pcap_stats_ex
: TDllpcap_stats_ex
;
105 pcap_setbuff
: TDllpcap_setbuff
;
106 pcap_close
: TDllpcap_close
;
107 pcap_setfilter
: TDllpcapsetfilter
;
108 pcap_compile
: TDllpcap_compile
;
109 pcap_freealldevs
: TDLLpcap_freealldevs
;
110 pcap_findalldevs
: TDLLpcap_findalldevs
;
111 pcap_major_version
: TDllpcap_major_version
;
112 pcap_minor_version
: TDllpcap_minor_version
;
113 pcap_snapshot
: TDllpcap_snapshot
;
114 pcap_geterr
: TDllpcap_geterr
;
117 function Initializewpcap
: Boolean;
122 wpcapsucceed
: Boolean = false;
124 function Initializewpcap
: Boolean;
134 hInst
:= LoadLibrary('wpcap.dll');
139 pcap_loop
:= GetProcAddress(hInst
, 'pcap_loop');
140 if @pcap_loop
= nil then
143 pcap_open_live
:= GetProcAddress(hInst
, 'pcap_open_live');
144 if @pcap_open_live
= nil then
147 pcap_open_dead
:= GetProcAddress(hInst
, 'pcap_open_dead');
148 if @pcap_open_dead
= nil then
151 pcap_dispatch
:= GetProcAddress(hInst
, 'pcap_dispatch');
152 if @pcap_dispatch
= nil then
155 pcap_datalink
:= GetProcAddress(hInst
, 'pcap_datalink');
156 if @pcap_datalink
= nil then
159 pcap_read
:= GetProcAddress(hInst
, 'pcap_read');
160 if @pcap_read
= nil then
163 pcap_read_ex
:= GetProcAddress(hInst
, 'pcap_read_ex');
164 if @pcap_read
= nil then
167 pcap_stats_ex
:= GetProcAddress(hInst
, 'pcap_stats_ex');
168 if @pcap_stats_ex
= nil then
171 pcap_setbuff
:= GetProcAddress(hInst
, 'pcap_setbuff');
172 if @pcap_setbuff
= nil then
175 pcap_close
:= GetProcAddress(hInst
, 'pcap_close');
176 if @pcap_close
= nil then
179 pcap_freecode
:= GetProcAddress(hInst
, 'pcap_freecode');
180 if @pcap_freecode
= nil then
183 pcap_setfilter
:= GetProcAddress(hInst
, 'pcap_setfilter');
184 if @pcap_setfilter
= nil then
187 pcap_compile
:= GetProcAddress(hInst
, 'pcap_compile');
188 if @pcap_compile
= nil then
191 pcap_findalldevs
:= GetProcAddress(hInst
, 'pcap_findalldevs');
192 if @pcap_findalldevs
= nil then
195 pcap_freealldevs
:= GetProcAddress(hInst
, 'pcap_freealldevs');
196 if @pcap_freealldevs
= nil then
199 pcap_major_version
:= GetProcAddress(hInst
, 'pcap_major_version');
200 if @pcap_major_version
= nil then
203 pcap_minor_version
:= GetProcAddress(hInst
, 'pcap_minor_version');
204 if @pcap_minor_version
= nil then
207 pcap_snapshot
:= GetProcAddress(hInst
, 'pcap_snapshot');
208 if @pcap_snapshot
= nil then
211 pcap_geterr
:= GetProcAddress(hInst
, 'pcap_geterr');
212 if @pcap_geterr
= nil then
216 wpcapsucceed
:= true;