summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/pcap/src/pcap.pp
blob: d207dbc2ee9b50d64c42acdc3be3cf1a86dd84fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
unit Pcap;

  { -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*-  }
  {
   * Copyright (c) 1993, 1994, 1995, 1996, 1997
   *	The Regents of the University of California.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in the
   *    documentation and/or other materials provided with the distribution.
   * 3. All advertising materials mentioning features or use of this software
   *    must display the following acknowledgement:
   *	This product includes software developed by the Computer Systems
   *	Engineering Group at Lawrence Berkeley Laboratory.
   * 4. Neither the name of the University nor of the Laboratory may be used
   *    to endorse or promote products derived from this software without
   *    specific prior written permission.
   *
   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   *
   * $FreeBSD: src/contrib/libpcap/pcap.h,v 1.11 2005/07/11 03:43:25 sam Exp $
   * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.52 2004/12/18 08:52:11 guy Exp $ (LBL)
    }

interface

uses
  {$ifdef UNIX}
  UnixType,BaseUnix,
  {$endif}
  {$ifdef Windows}
  WinSock, Windows,
  {$endif}
  Types, Sockets;

{$IFDEF FPC}
  {$PACKRECORDS C}
  {$ifndef NO_SMART_LINK}
    {$smartlink on}
  {$endif}
{$ENDIF}

  const
     {$ifdef unix}
     {$linklib c}
     PCAP_LIB_NAME = 'libpcap';
     {$endif}
     {$ifdef WINDOWS}
     PCAP_LIB_NAME = 'wpcap';
     {$endif}
     PCAP_VERSION_MAJOR = 2;
     PCAP_VERSION_MINOR = 4;
     PCAP_ERRBUF_SIZE = 256;
  { interface is loopback  }
     PCAP_IF_LOOPBACK = $00000001;
  {
   * The first record in the file contains saved values for some
   * of the flags used in the printout phases of tcpdump.
   * Many fields here are 32 bit ints so compilers won't insert unwanted
   * padding; these files need to be interchangeable across architectures.
   *
   * Do not change the layout of this structure, in any way (this includes
   * changes that only affect the length of fields in this structure).
   *
   * Also, do not change the interpretation of any of the members of this
   * structure, in any way (this includes using values other than
   * LINKTYPE_ values, as defined in "savefile.c", in the "linktype"
   * field).
   *
   * Instead:
   *
   *	introduce a new structure for the new format, if the layout
   *	of the structure changed;
   *
   *	send mail to "tcpdump-workers@tcpdump.org", requesting a new
   *	magic number for your new capture file format, and, when
   *	you get the new magic number, put it in "savefile.c";
   *
   *	use that magic number for save files with the changed file
   *	header;
   *
   *	make the code in "savefile.c" capable of reading files with
   *	the old file header as well as files with the new file header
   *	(using the magic number to determine the header format).
   *
   * Then supply the changes to "patches@tcpdump.org", so that future
   * versions of libpcap and programs that use it (such as tcpdump) will
   * be able to read your new capture file format.
    }
  { gmt to local correction  }
  { accuracy of timestamps  }
  { max length saved portion of each pkt  }
  { data link type (LINKTYPE_*)  }
  type
     PPLongint = ^PLongint;
     PPcap_File_Header = ^TPcap_File_Header;
     TPcap_File_Header = record
       magic : DWord;
       version_major : Word;
       version_minor : Word;
       thiszone : Longint;
       sigfigs : DWord;
       snaplen : DWord;
       linktype : DWord;
     end;

     PBPF_Insn = ^TBPF_Insn;
     TBPF_Insn = record
       code: Word;
       jt: Byte;
       jf: Byte;
       k: DWord;
     end;

     PBPF_Program = ^TBPF_Program;
     TBPF_Program = record
       bf_len: PtrInt;
       bf_insns: PBPF_Insn;
     end;

     PDirection = ^TDirection;
     TDirection = (D_INOUT, D_IN, D_OUT);
  {
   * Each packet in the dump file is prepended with this generic header.
   * This gets around the problem of different headers for different
   * packet interfaces.
    }
  { time stamp  }
  { length of portion present  }
  { length this packet (off wire)  }
     PPPcap_Pkthdr = ^PPcap_Pkthdr;
     PPcap_Pkthdr = ^TPcap_Pkthdr;
     TPcap_Pkthdr = record
       ts : TTimeVal;
       caplen : DWord;
       len : DWord;
     end;

  {
   * As returned by the pcap_stats()
    }
  { number of packets received  }
  { number of packets dropped  }
  { drops by interface XXX not yet supported  }

     PPcap_Stat = ^TPcap_Stat;
     TPcap_Stat = record
       ps_recv   : DWord;
       ps_drop   : DWord;
       ps_ifdrop : DWord;
       bs_capt   : DWord;
     end;

  {
   * Representation of an interface address.
    }
  { address  }
  { netmask for that address  }
  { broadcast address for that address  }
  { P2P destination address for that address  }

     PPcap_Addr = ^TPcap_Addr;
     TPcap_Addr = record
       next : PPcap_Addr;
       addr : PSockAddr;
       netmask : PSockAddr;
       broadaddr : PSockAddr;
       dstaddr : PSockAddr;
     end;

  {
   * Item in a list of interfaces.
    }
  { name to hand to "pcap_open_live()"  }
  { textual description of interface, or NULL  }
  { PCAP_IF_ interface flags  }
     PPPcap_If = ^PPcap_If;
     PPcap_If = ^TPcap_If;
     TPcap_If = record
       next : PPcap_If;
       name : PChar;
       description : PChar;
       addresses : PPcap_Addr;
       flags : DWord;
     end;
     
  { obfuscated C types }
     PPcap = ^TPcap;
     TPcap = record end;

     PPcapDumper = ^TPcapDumper;
     TPcapDumper = record end;

     TPcapHandler = procedure (para1: PChar; Header: PPcap_Pkthdr; Data: PChar); cdecl;

  function pcap_lookupdev(ErrBuf: PChar): PChar; cdecl; external PCAP_LIB_NAME;

  function pcap_lookupnet(Device: PChar; NetP: PDword;
                          MaskP: PDword; ErrBuf: PChar): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_open_live(Device : PChar; SnapLen: Longint; Promisc: Longint;
                          to_ms: Longint; ebuf: PChar): PPcap; cdecl; external PCAP_LIB_NAME;

  function pcap_open_dead(LinkType: Longint; SnapLen: Longint): PPcap; cdecl; external PCAP_LIB_NAME;

  function pcap_open_offline(FileName: PChar; ErrBuf: PChar): PPcap; cdecl; external PCAP_LIB_NAME;

//  function pcap_fopen_offline(para1:PFILE; para2:PChar): PPcap; cdecl; external PCAP_LIB_NAME;

  procedure pcap_close(p :PPcap); cdecl; external PCAP_LIB_NAME;

  function pcap_loop(p: PPcap; cnt: Longint; Callback: TPCapHandler; User: PChar): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_dispatch(p: PPcap; cnt: Longint; Callback: TPCapHandler; User: PChar): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_next(para1: PPcap; para2:PPcap_Pkthdr): PChar; cdecl; external PCAP_LIB_NAME;

  function pcap_next_ex(para1: PPcap; para2:PPPcap_Pkthdr; para3:PPChar): Longint; cdecl; external PCAP_LIB_NAME;

  procedure pcap_breakloop(para1:PPcap); cdecl; external PCAP_LIB_NAME;

  function pcap_stats(para1: PPcap; para2:PPcap_Stat): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_setfilter(para1: PPcap; para2:PBPF_Program): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_setdirection(para1: PPcap; para2:TDirection): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_getnonblock(para1: PPcap; para2:PChar): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_setnonblock(para1: PPcap; para2: Longint; para3:PChar): Longint; cdecl; external PCAP_LIB_NAME;

  procedure pcap_perror(para1: PPcap; para2:PChar); cdecl; external PCAP_LIB_NAME;

  function pcap_inject(para1: PPcap; para2:pointer; para3: TSize): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_sendpacket(para1: PPcap; para2: PChar; para3:Longint): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_strerror(para1:Longint): PChar; cdecl; external PCAP_LIB_NAME;

  function pcap_geterr(para1:PPcap): PChar; cdecl; external PCAP_LIB_NAME;

  function pcap_compile(para1: PPcap; para2:PBPF_Program; para3: PChar; para4: Longint; para5:DWord): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_compile_nopcap(para1: Longint; para2: Longint; para3:PBPF_Program; para4: PChar; para5: Longint;
             para6:DWord): Longint; cdecl; external PCAP_LIB_NAME;

  procedure pcap_freecode(para1:PBPF_Program); cdecl; external PCAP_LIB_NAME;

  function pcap_datalink(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_list_datalinks(para1: PPcap; para2:PPLongint): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_set_datalink(para1: PPcap; para2:Longint): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_datalink_name_to_val(para1:PChar): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_datalink_val_to_name(para1:Longint): PChar; cdecl; external PCAP_LIB_NAME;

  function pcap_datalink_val_to_description(para1:Longint): PChar; cdecl; external PCAP_LIB_NAME;

  function pcap_snapshot(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_is_swapped(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_major_version(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_minor_version(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;

  { XXX  }
//  function pcap_file(para1:PPcap):PFILE; cdecl; external PCAP_LIB_NAME;

  function pcap_fileno(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_dump_open(para1: PPcap; para2:PChar):PPCapDumper; cdecl; external PCAP_LIB_NAME;

//  function pcap_dump_fopen(para1: PPcap; fp:PFILE):PPCapDumper; cdecl; external PCAP_LIB_NAME;

//  function pcap_dump_file(para1:PPCapDumper):PFILE; cdecl; external PCAP_LIB_NAME;

  function pcap_dump_ftell(para1:PPCapDumper): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_dump_flush(para1:PPCapDumper): Longint; cdecl; external PCAP_LIB_NAME;

  procedure pcap_dump_close(para1:PPCapDumper); cdecl; external PCAP_LIB_NAME;

  procedure pcap_dump(para1: PChar; para2:PPcap_Pkthdr; para3:PChar); cdecl; external PCAP_LIB_NAME;

  function pcap_findalldevs(para1:PPPcap_If; para2:PChar): Longint; cdecl; external PCAP_LIB_NAME;

  procedure pcap_freealldevs(para1:PPcap_If); cdecl; external PCAP_LIB_NAME;

  function pcap_lib_version: PChar; cdecl; external PCAP_LIB_NAME;

  { XXX this guy lives in the bpf tree  }
  function bpf_filter(para1:Pbpf_insn; para2: PChar; para3:PtrInt; para4:PtrInt):PtrInt; cdecl; external PCAP_LIB_NAME;

  function bpf_validate(f:Pbpf_insn; len:Longint): Longint; cdecl; external PCAP_LIB_NAME;

  function bpf_image(para1:Pbpf_insn; para2:Longint): PChar; cdecl; external PCAP_LIB_NAME;

  procedure bpf_dump(para1:PBPF_Program; para2:Longint); cdecl; external PCAP_LIB_NAME;

{$ifdef WINDOWS}

  function pcap_setbuff(p: PPcap; dim:Longint): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_setmode(p: PPcap; mode:Longint): Longint; cdecl; external PCAP_LIB_NAME;

  function pcap_setmintocopy(p: PPcap; size:Longint): Longint; cdecl; external PCAP_LIB_NAME;

{$endif}

{$ifdef unix}

  function pcap_get_selectable_fd(para1:PPcap): Longint; cdecl; external PCAP_LIB_NAME;

{$endif}

implementation


end.