initial commit
[rofl0r-KOL.git] / kolsniffer / kolwinpcap.pas
bloba0b4200140b1d62d846801578d48b36a3a6edd33
1 //
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
7 //
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
10 // comments
12 {********************************************************************************
13 --------------------------------------------------------------------------------
14 header conversion for Delphi
16 for winpcap
18 Packet Capture Driver by Politecnico di Torino
20 Written by Umar Sear
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
37 given below.
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.
45 Umar Sear
46 Email : usear@yahoo.com
48 Winpcap author:
49 webpsite: http://netgroup-serv.polito.it
50 ********************************************************************************}
52 unit kolwinpcap;
54 interface
56 uses Windows,kol,kolwinpcaptypes;
58 Const
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
66 type
68 PTpcap_handler =^Tpcap_handler;
69 Tpcap_handler = procedure(User:pointer;const Header:PTpcap_pkthdr;const Data:Pointer);
71 Type
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;
95 Var
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;
119 Implementation
122 wpcapsucceed: Boolean = false;
124 function Initializewpcap : Boolean;
126 hInst: THandle;
127 begin
128 if wpcapsucceed then
129 begin
130 Result := true;
131 exit;
132 end;
133 Result := false;
134 hInst := LoadLibrary('wpcap.dll');
136 if hInst = 0 then
137 exit;
139 pcap_loop := GetProcAddress(hInst, 'pcap_loop');
140 if @pcap_loop = nil then
141 exit;
143 pcap_open_live := GetProcAddress(hInst, 'pcap_open_live');
144 if @pcap_open_live = nil then
145 exit;
147 pcap_open_dead := GetProcAddress(hInst, 'pcap_open_dead');
148 if @pcap_open_dead = nil then
149 exit;
151 pcap_dispatch := GetProcAddress(hInst, 'pcap_dispatch');
152 if @pcap_dispatch = nil then
153 exit;
155 pcap_datalink := GetProcAddress(hInst, 'pcap_datalink');
156 if @pcap_datalink = nil then
157 exit;
159 pcap_read := GetProcAddress(hInst, 'pcap_read');
160 if @pcap_read = nil then
161 exit;
163 pcap_read_ex := GetProcAddress(hInst, 'pcap_read_ex');
164 if @pcap_read = nil then
165 exit;
167 pcap_stats_ex := GetProcAddress(hInst, 'pcap_stats_ex');
168 if @pcap_stats_ex = nil then
169 exit;
171 pcap_setbuff := GetProcAddress(hInst, 'pcap_setbuff');
172 if @pcap_setbuff = nil then
173 exit;
175 pcap_close := GetProcAddress(hInst, 'pcap_close');
176 if @pcap_close = nil then
177 exit;
179 pcap_freecode := GetProcAddress(hInst, 'pcap_freecode');
180 if @pcap_freecode = nil then
181 exit;
183 pcap_setfilter := GetProcAddress(hInst, 'pcap_setfilter');
184 if @pcap_setfilter = nil then
185 exit;
187 pcap_compile := GetProcAddress(hInst, 'pcap_compile');
188 if @pcap_compile = nil then
189 exit;
191 pcap_findalldevs := GetProcAddress(hInst, 'pcap_findalldevs');
192 if @pcap_findalldevs = nil then
193 exit;
195 pcap_freealldevs := GetProcAddress(hInst, 'pcap_freealldevs');
196 if @pcap_freealldevs = nil then
197 exit;
199 pcap_major_version := GetProcAddress(hInst, 'pcap_major_version');
200 if @pcap_major_version = nil then
201 exit;
203 pcap_minor_version := GetProcAddress(hInst, 'pcap_minor_version');
204 if @pcap_minor_version = nil then
205 exit;
207 pcap_snapshot := GetProcAddress(hInst, 'pcap_snapshot');
208 if @pcap_snapshot = nil then
209 exit;
211 pcap_geterr := GetProcAddress(hInst, 'pcap_geterr');
212 if @pcap_geterr = nil then
213 exit;
216 wpcapsucceed := true;
217 Result := true;
218 end;
220 End.