forked from helpsystems/pcapy
-
Notifications
You must be signed in to change notification settings - Fork 7
/
pcapy.html
615 lines (612 loc) · 62.6 KB
/
pcapy.html
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Part I. Pcapy Reference</title><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><meta name="keywords" content="pcap, packet, capture, python" /></head><body><div class="part"><div class="titlepage"><div><div><h1 class="title"><a id="idp1073119908928"></a>Part I. Pcapy Reference</h1></div><div><h3 class="corpauthor">CORE SECURITY TECHNOLOGIES</h3></div><div><p class="copyright">Copyright © 2016-2018 CORE SECURITY TECHNOLOGIES</p></div><div><div class="revhistory"><table style="border-style:solid; width:100%;" summary="Revision History"><tr><th align="left" valign="top" colspan="3"><strong>Revision History</strong></th></tr><tr><td align="left">Revision Revision: 16</td><td align="left">Date: 2018-06-04</td><td align="left">Author: jkohen</td></tr><tr><td align="left" colspan="3">2018 updated</td></tr></table></div></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="reference"><a href="#idp1073147197920">I. Pcapy Module Reference</a></span></dt><dd><dl><dt><span class="refentrytitle"><a href="#idp1073147198592">open_live</a></span><span class="refpurpose"> — Obtain a packet capture descriptor to look at packets on the network</span></dt><dt><span class="refentrytitle"><a href="#idp1073150793936">open_offline</a></span><span class="refpurpose"> —
Obtain a packet capture descriptor to look at packets on a <em class="glossterm">savefile</em>
</span></dt><dt><span class="refentrytitle"><a href="#idp1073147070528">lookupdev</a></span><span class="refpurpose"> —
Return a network device suitable for use with
<code class="function">open_live</code>
</span></dt><dt><span class="refentrytitle"><a href="#idp1073147077888">findalldevs</a></span><span class="refpurpose"> — Obtain the list of available network devices</span></dt><dt><span class="refentrytitle"><a href="#idp1073147099856">compile</a></span><span class="refpurpose"> — Compile a BPF filter</span></dt><dt><span class="refentrytitle"><a href="#idp1073147113952">create</a></span><span class="refpurpose"> — Creates a non-activated packet capture handle to look at packets on the network</span></dt></dl></dd><dt><span class="reference"><a href="#idp1073147121920">II. Reader Object Reference</a></span></dt><dd><dl><dt><span class="refentrytitle"><a href="#idp1073147122592">dispatch</a></span><span class="refpurpose"> — Collect and process packets</span></dt><dt><span class="refentrytitle"><a href="#idp1073151839280">next</a></span><span class="refpurpose"> — Collect the next packet</span></dt><dt><span class="refentrytitle"><a href="#idp1073151848272">stats</a></span><span class="refpurpose"> — get capture statistics</span></dt><dt><span class="refentrytitle"><a href="#idp1073151854112">setfilter</a></span><span class="refpurpose"> — Specify a filter</span></dt><dt><span class="refentrytitle"><a href="#idp1073151860592">getfd</a></span><span class="refpurpose"> — get a file descriptor on which a select() can be
done for a live capture</span></dt><dt><span class="refentrytitle"><a href="#idp1073151867408">set_snaplen</a></span><span class="refpurpose"> — Set the snapshot length for a not-yet-activated
capture handle</span></dt><dt><span class="refentrytitle"><a href="#idp1073151874800">set_promisc</a></span><span class="refpurpose"> — Set promiscuous mode for a not-yet-activated
capture handle</span></dt><dt><span class="refentrytitle"><a href="#idp1073151882288">set_timeout</a></span><span class="refpurpose"> — Set the read timeout for a not-yet-activated
capture handle</span></dt><dt><span class="refentrytitle"><a href="#idp1073151889792">set_buffer_size</a></span><span class="refpurpose"> — Set the buffer size for a not-yet-activated capture handle
capture handle</span></dt><dt><span class="refentrytitle"><a href="#idp1073151897312">activate</a></span><span class="refpurpose"> — Activate a capture handle</span></dt><dt><span class="refentrytitle"><a href="#idp1073151904256">getnet</a></span><span class="refpurpose"> — Get the associated network number and mask</span></dt><dt><span class="refentrytitle"><a href="#idp1073151913552">datalink</a></span><span class="refpurpose"> — Obtain the link layer type</span></dt><dt><span class="refentrytitle"><a href="#idp1073152009584">getnonblock / setnonblock</a></span><span class="refpurpose"> —
Manipulate the
<em class="firstterm">non-blocking</em> flag
</span></dt><dt><span class="refentrytitle"><a href="#idp1073152025552">dump_open</a></span><span class="refpurpose"> — Create a Dumper object</span></dt><dt><span class="refentrytitle"><a href="#idp1073152035072">close</a></span><span class="refpurpose"> —
Close a Reader
</span></dt></dl></dd><dt><span class="reference"><a href="#idp1073152041312">III. Dumper Object Reference</a></span></dt><dd><dl><dt><span class="refentrytitle"><a href="#idp1073152041952">dump</a></span><span class="refpurpose"> —
Dump a packet to a <em class="glossterm">savefile</em>
</span></dt><dt><span class="refentrytitle"><a href="#idp1073152051216">close</a></span><span class="refpurpose"> —
Close a Dumper
</span></dt></dl></dd><dt><span class="reference"><a href="#idp1073152057456">IV. Pkthdr Object Reference</a></span></dt><dd><dl><dt><span class="refentrytitle"><a href="#idp1073152058096">getts</a></span><span class="refpurpose"> — Obtain packet header information</span></dt></dl></dd><dt><span class="reference"><a href="#idp1073152071120">V. Bpf Object Reference</a></span></dt><dd><dl><dt><span class="refentrytitle"><a href="#idp1073152071760">filter</a></span><span class="refpurpose"> — Test a packet against a compiled filter</span></dt></dl></dd><dt><span class="bibliography"><a href="#idp1073152080944">Bibliography</a></span></dt></dl></div><div class="reference"><div class="titlepage"><div><div><h1 class="title"><a id="idp1073147197920"></a>Pcapy Module Reference</h1></div></div><hr /></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="refentrytitle"><a href="#idp1073147198592">open_live</a></span><span class="refpurpose"> — Obtain a packet capture descriptor to look at packets on the network</span></dt><dt><span class="refentrytitle"><a href="#idp1073150793936">open_offline</a></span><span class="refpurpose"> —
Obtain a packet capture descriptor to look at packets on a <em class="glossterm">savefile</em>
</span></dt><dt><span class="refentrytitle"><a href="#idp1073147070528">lookupdev</a></span><span class="refpurpose"> —
Return a network device suitable for use with
<code class="function">open_live</code>
</span></dt><dt><span class="refentrytitle"><a href="#idp1073147077888">findalldevs</a></span><span class="refpurpose"> — Obtain the list of available network devices</span></dt><dt><span class="refentrytitle"><a href="#idp1073147099856">compile</a></span><span class="refpurpose"> — Compile a BPF filter</span></dt><dt><span class="refentrytitle"><a href="#idp1073147113952">create</a></span><span class="refpurpose"> — Creates a non-activated packet capture handle to look at packets on the network</span></dt></dl></div><div class="refentry"><a id="idp1073147198592"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>open_live — Obtain a packet capture descriptor to look at packets on the network</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
Reader <strong class="fsfunc">open_live</strong>
(</code></td><td><var class="pdparam">device</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">snaplen</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">promisc</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">to_ms</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
string <var class="pdparam">device</var>
</code>;<br /><code>
int <var class="pdparam">snaplen</var>
</code>;<br /><code>
int <var class="pdparam">promisc</var>
</code>;<br /><code>
int <var class="pdparam">to_ms</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073147206960"></a><h2>DESCRIPTION</h2><p>
<code class="function">open_live</code> is used to obtain a packet
capture descriptor to look at packets on the network.
<em class="parameter"><code>device</code></em> is a string that specifies the
network device to open; on Linux systems with 2.2 or later
kernels, a device argument of <code class="literal">any</code> or
<code class="constant">NULL</code> can be used to capture packets
from all interfaces. <em class="parameter"><code>snaplen</code></em>
specifies the maximum number of bytes to capture.
<em class="parameter"><code>promisc</code></em> specifies if the interface is
to be put into promiscuous mode. (Note that even if this
parameter is false, the interface could well be in
promiscuous mode for some other reason.) For now, this
doesn't work on the <code class="literal">any</code> device; if an
argument of <code class="literal">any</code> or
<code class="constant">NULL</code> is supplied, the
<em class="parameter"><code>promisc</code></em> flag is ignored.
<em class="parameter"><code>to_ms</code></em> specifies the read timeout in
milliseconds. The read timeout is used to arrange that the
read not necessarily return immediately when a packet is
seen, but that it wait for some amount of time to allow more
packets to arrive and to read multiple packets from the OS
kernel in one operation. Not all platforms support a read
timeout; on platforms that don't, the read timeout is
ignored.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073150793936"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>open_offline —
Obtain a packet capture descriptor to look at packets on a <em class="glossterm">savefile</em>
</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
Reader <strong class="fsfunc">open_offline</strong>
(</code></td><td><var class="pdparam">filename</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
string <var class="pdparam">filename</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073150799152"></a><h2>DESCRIPTION</h2><p>
<code class="function">open_offline</code> is called to open a
<em class="glossterm">savefile</em> for reading. <em class="parameter"><code>filename</code></em>
specifies the name of the file to open. The file has the
same format as those used by
<span class="citerefentry"><span class="refentrytitle">tcpdump</span>(8)</span> and
<span class="citerefentry"><span class="refentrytitle">tcpslice</span>(8)</span>. The name
<code class="filename">-</code> is a synonym for
<code class="filename">stdin</code>.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073147070528"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>lookupdev —
Return a network device suitable for use with
<code class="function">open_live</code>
</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
string <strong class="fsfunc">lookupdev</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073147075168"></a><h2>DESCRIPTION</h2><p>
<code class="function">lookupdev</code> returns the name of a network
device suitable for use with <code class="function">open_live</code>.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073147077888"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>findalldevs — Obtain the list of available network devices</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
string[] <strong class="fsfunc">findalldevs</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073147081856"></a><h2>DESCRIPTION</h2><p>
<code class="function">findalldevs</code> constructs a list of
network devices that can be opened with
<code class="function">open_live</code>. (Note that there may be
network devices that cannot be opened with
<code class="function">open_live</code>, because, for example, that
process might not have sufficient privileges to open them
for capturing; if so, those devices will not appear on the
list.)
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073147099856"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>compile — Compile a BPF filter</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
Bpf <strong class="fsfunc">compile</strong>
(</code></td><td><var class="pdparam">linktype</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">snaplen</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">filter</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">optimize</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">netmask</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
int <var class="pdparam">linktype</var>
</code>;<br /><code>
int <var class="pdparam">snaplen</var>
</code>;<br /><code>
string <var class="pdparam">filter</var>
</code>;<br /><code>
int <var class="pdparam">optimize</var>
</code>;<br /><code>
int32 <var class="pdparam">netmask</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073147109104"></a><h2>DESCRIPTION</h2><p>
<code class="function">compile</code> is used to compile the
<em class="parameter"><code>filter</code></em> into a filter program.
<code class="function">snaplen</code> specifies the maximum number of
bytes to capture. <em class="parameter"><code>optimize</code></em> controls
whether optimization on the resulting code is performed.
<em class="parameter"><code>netmask</code></em> specifies the netmask of the
local network.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073147113952"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>create — Creates a non-activated packet capture handle to look at packets on the network</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
Reader <strong class="fsfunc">create</strong>
(</code></td><td><var class="pdparam">device</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
string <var class="pdparam">device</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073147118752"></a><h2>DESCRIPTION</h2><p>
<code class="function">create</code> is used to create a
packet capture handle to look at packets on the network.
The returned handle must be activated with
<code class="function">activate()</code> before packets can be captured
with it; options for the capture, such as promiscuous mode,
can be set on the handle before activating it.
</p></div></div></div><div class="reference"><div class="titlepage"><div><div><h1 class="title"><a id="idp1073147121920"></a>Reader Object Reference</h1></div></div><hr /></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="refentrytitle"><a href="#idp1073147122592">dispatch</a></span><span class="refpurpose"> — Collect and process packets</span></dt><dt><span class="refentrytitle"><a href="#idp1073151839280">next</a></span><span class="refpurpose"> — Collect the next packet</span></dt><dt><span class="refentrytitle"><a href="#idp1073151848272">stats</a></span><span class="refpurpose"> — get capture statistics</span></dt><dt><span class="refentrytitle"><a href="#idp1073151854112">setfilter</a></span><span class="refpurpose"> — Specify a filter</span></dt><dt><span class="refentrytitle"><a href="#idp1073151860592">getfd</a></span><span class="refpurpose"> — get a file descriptor on which a select() can be
done for a live capture</span></dt><dt><span class="refentrytitle"><a href="#idp1073151867408">set_snaplen</a></span><span class="refpurpose"> — Set the snapshot length for a not-yet-activated
capture handle</span></dt><dt><span class="refentrytitle"><a href="#idp1073151874800">set_promisc</a></span><span class="refpurpose"> — Set promiscuous mode for a not-yet-activated
capture handle</span></dt><dt><span class="refentrytitle"><a href="#idp1073151882288">set_timeout</a></span><span class="refpurpose"> — Set the read timeout for a not-yet-activated
capture handle</span></dt><dt><span class="refentrytitle"><a href="#idp1073151889792">set_buffer_size</a></span><span class="refpurpose"> — Set the buffer size for a not-yet-activated capture handle
capture handle</span></dt><dt><span class="refentrytitle"><a href="#idp1073151897312">activate</a></span><span class="refpurpose"> — Activate a capture handle</span></dt><dt><span class="refentrytitle"><a href="#idp1073151904256">getnet</a></span><span class="refpurpose"> — Get the associated network number and mask</span></dt><dt><span class="refentrytitle"><a href="#idp1073151913552">datalink</a></span><span class="refpurpose"> — Obtain the link layer type</span></dt><dt><span class="refentrytitle"><a href="#idp1073152009584">getnonblock / setnonblock</a></span><span class="refpurpose"> —
Manipulate the
<em class="firstterm">non-blocking</em> flag
</span></dt><dt><span class="refentrytitle"><a href="#idp1073152025552">dump_open</a></span><span class="refpurpose"> — Create a Dumper object</span></dt><dt><span class="refentrytitle"><a href="#idp1073152035072">close</a></span><span class="refpurpose"> —
Close a Reader
</span></dt></dl></div><div class="refentry"><a id="idp1073147122592"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>dispatch, loop — Collect and process packets</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int <strong class="fsfunc">dispatch</strong>
(</code></td><td><var class="pdparam">maxcant</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">(* callback)</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
int <var class="pdparam">maxcant</var>
</code>;<br /><code>
void <var class="pdparam">(* callback)</var>
<code>(</code>Pkthdr, string<code>)</code>
</code>;</div><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int <strong class="fsfunc">loop</strong>
(</code></td><td><var class="pdparam">maxcant</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">(* callback)</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
int <var class="pdparam">maxcant</var>
</code>;<br /><code>
void <var class="pdparam">(* callback)</var>
<code>(</code>Pkthdr, string<code>)</code>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073151821776"></a><h2>DESCRIPTION</h2><p>
<code class="function">dispatch</code> is used to collect and process
packets. <em class="parameter"><code>maxcant</code></em> specifies the
maximum number of packets to process before returning. This
is not a minimum number; when reading a live capture, only
one bufferful of packets is read at a time, so fewer than
<em class="parameter"><code>maxcant</code></em> packets may be processed. A
<em class="parameter"><code>cnt</code></em> of <code class="literal">-1</code>
processes all the packets received in one buffer when
reading a live capture, or all the packets in the file when
reading a <em class="glossterm">savefile</em>. <em class="parameter"><code>callback</code></em>
specifies a routine to be called with two arguments: a
<code class="classname">Pkthdr</code> instance describing the data
passed and the data itself.
</p><p>
The number of packets read is returned.
<span class="returnvalue">0</span> is returned if no packets were
read from a live capture (if, for example, they were
discarded because they didn't pass the packet filter, or if,
on platforms that support a read timeout that starts before
any packets arrive, the timeout expires before any packets
arrive, or if the file descriptor for the capture device is
in non-blocking mode and no packets were available to be
read) or if no more packets are available in a <em class="glossterm">savefile</em>.
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
When reading a live capture, <code class="function">dispatch</code>
will not necessarily return when the read times out; on
some platforms, the read timeout isn't supported, and, on
other platforms, the timer doesn't start until at least
one packet arrives. This means that the read timeout
should <span class="emphasis"><em>not</em></span> be used in, for example,
an interactive application, to allow the packet capture
loop to poll for user input periodically, as there's no
guarantee that <code class="function">dispatch</code> will return
after the timeout expires.
</p></div><p>
<code class="function">loop</code> is similar to
<code class="function">dispatch</code> except it keeps reading
packets until <em class="parameter"><code>maxcant</code></em> packets are
processed or an error occurs. It does
<span class="emphasis"><em>not</em></span> return when live read timeouts
occur. Rather, specifying a non-zero read timeout to
<code class="function">open_live</code> and then calling
<code class="function">dispatch</code> allows the reception and
processing of any packets that arrive when the timeout
occurs. A negative <em class="parameter"><code>maxcant</code></em> causes
<code class="function">loop</code> to loop forever (or at least until
an error occurs). <span class="returnvalue">0</span> is returned
if <em class="parameter"><code>maxcant</code></em> is exhausted.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073151839280"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>next — Collect the next packet</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
(Pkthdr, string) <strong class="fsfunc">next</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073151843104"></a><h2>DESCRIPTION</h2><p>
<code class="function">next</code> reads the next packet (by calling
<code class="function">dispatch</code> with a
<em class="parameter"><code>maxcant</code></em> of <code class="constant">1</code>)
and returns a tuple (header, data) where
<em class="parameter"><code>header</code></em> is a
<code class="classname">Pkthdr</code> instance describing the data
passed and <em class="parameter"><code>data</code></em> is the data itself.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073151848272"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>stats — get capture statistics</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
(int32, int32, int32) <strong class="fsfunc">stats</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073151852096"></a><h2>DESCRIPTION</h2><p>
<code class="function">stats</code> returns statistics on the current
capture as a tuple (recv, drop, ifdrop)
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073151854112"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>setfilter — Specify a filter</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
<strong class="fsfunc">setfilter</strong>
(</code></td><td><var class="pdparam">filter</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
string <var class="pdparam">filter</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073151858688"></a><h2>DESCRIPTION</h2><p>
<code class="function">setfilter</code> is used to specify a filter
for this object.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073151860592"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>getfd — get a file descriptor on which a select() can be
done for a live capture</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int <strong class="fsfunc">getfd</strong>
(</code></td><td><var class="pdparam">filter</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
string <var class="pdparam">filter</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073151865168"></a><h2>DESCRIPTION</h2><p>
<code class="function">getfd</code> returns, on UNIX, a file descriptor
number for a file descriptor on which one can do a select(),
poll(), epoll_wait(), kevent(), or other such call to wait
for it to be possible to read packets without blocking, if
such a descriptor exists, or -1, if no such descriptor exists.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073151867408"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>set_snaplen — Set the snapshot length for a not-yet-activated
capture handle</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int <strong class="fsfunc">set_snaplen</strong>
(</code></td><td><var class="pdparam">snaplen</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
int <var class="pdparam">snaplen</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073151871984"></a><h2>DESCRIPTION</h2><p>
<code class="function">set_snaplen</code> sets the snapshot length
to be used on a capture handle when the handle is activated
to snaplen.
<code class="function">set_snaplen</code> returns 0 on success
or PCAP_ERROR_ACTIVATED if called on a capture handle that
has been activated.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073151874800"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>set_promisc — Set promiscuous mode for a not-yet-activated
capture handle</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int <strong class="fsfunc">set_promisc</strong>
(</code></td><td><var class="pdparam">promisc</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
int <var class="pdparam">promisc</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073151879376"></a><h2>DESCRIPTION</h2><p>
<code class="function">set_promisc</code> sets whether promiscuous mode
should be set on a capture handle when the handle is activated.
If promisc is non-zero, promiscuous mode will be set, otherwise
it will not be set.
<code class="function">set_promisc</code> returns 0 on success
or PCAP_ERROR_ACTIVATED if called on a capture handle that
has been activated.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073151882288"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>set_timeout — Set the read timeout for a not-yet-activated
capture handle</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int <strong class="fsfunc">set_timeout</strong>
(</code></td><td><var class="pdparam">timeout</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
int <var class="pdparam">timeout</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073151886944"></a><h2>DESCRIPTION</h2><p>
<code class="function">set_timeout</code> sets the read timeout
that will be used on a capture handle when the handle
is activated to to_ms, which is in units of milliseconds.
<code class="function">set_timeout</code> returns 0 on success
or PCAP_ERROR_ACTIVATED if called on a capture handle that
has been activated.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073151889792"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>set_buffer_size — Set the buffer size for a not-yet-activated capture handle
capture handle</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int <strong class="fsfunc">set_buffer_size</strong>
(</code></td><td><var class="pdparam">buffer_size</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
int <var class="pdparam">buffer_size</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073151894464"></a><h2>DESCRIPTION</h2><p>
<code class="function">set_buffer_size</code> sets the buffer size
that will be used on a capture handle when the handle is
activated to buffer_size, which is in units of bytes.
<code class="function">set_buffer_size</code> returns 0 on success
or PCAP_ERROR_ACTIVATED if called on a capture handle that
has been activated.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073151897312"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>activate — Activate a capture handle</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int <strong class="fsfunc">activate</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073151901136"></a><h2>DESCRIPTION</h2><p>
<code class="function">activate</code> is used to activate a
packet capture handle to look at packets on the network,
with the options that were set on the handle being in effect.
<code class="function">activate</code> returns 0 on success without
warnings, a non-zero positive value on success with warnings,
and a negative value on error. A non-zero return value indicates
what warning or error condition occurred.
has been activated.
See https://www.tcpdump.org/manpages/pcap_activate.3pcap.html for
all possible return values.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073151904256"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>getnet, getmask — Get the associated network number and mask</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int32 <strong class="fsfunc">getnet</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int32 <strong class="fsfunc">getmask</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073151910496"></a><h2>DESCRIPTION</h2><p>
<code class="function">getnet</code> and <code class="function">getmask</code>
are used to determine the network number and mask associated
with the network device attached to this
<code class="classname">Reader</code>.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073151913552"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>datalink — Obtain the link layer type</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int <strong class="fsfunc">datalink</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073151917376"></a><h2>DESCRIPTION</h2><p>
<code class="function">datalink</code> returns the link layer type; link layer types it can return include:
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
<code class="constant">DLT_NULL</code>
</span></dt><dd><p class="simpara">
<acronym class="acronym">BSD</acronym> loopback encapsulation; the
link layer header is a 4-byte field, in host
byte order, containing a <code class="constant">PF_</code>
value from <code class="filename">socket.h</code> for the
network-layer protocol of the packet.
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
<span class="quote">“<span class="quote">host byte order</span>”</span> is the byte order
of the machine on which the packets are captured,
and the <code class="constant">PF_</code> values are for
the <acronym class="acronym">OS</acronym> of the machine on which
the packets are captured; if a live capture is
being done, <span class="quote">“<span class="quote">host byte order</span>”</span> is the
byte order of the machine capturing the packets,
and the <code class="constant">PF_</code> values are those
of the <acronym class="acronym">OS</acronym> of the machine
capturing the packets, but if a <em class="glossterm">savefile</em> is being
read, the byte order and <code class="constant">PF_</code>
values are <span class="emphasis"><em>not</em></span> necessarily
those of the machine reading the capture file.
</p></div></dd><dt><span class="term">
<code class="constant">DLT_EN10MB</code>
</span></dt><dd>Ethernet (10Mb, 100Mb, 1000Mb, and up)</dd><dt><span class="term">
<code class="constant">DLT_IEEE802</code>
</span></dt><dd>
<acronym class="acronym">IEEE</acronym> 802.5 Token Ring
</dd><dt><span class="term">
<code class="constant">DLT_ARCNET</code>
</span></dt><dd>
<acronym class="acronym">ARCNET</acronym>
</dd><dt><span class="term">
<code class="constant">DLT_SLIP</code>
</span></dt><dd><p>
<acronym class="acronym">SLIP</acronym>; the link layer header contains, in order:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
a 1-byte flag, which is
<code class="literal">0</code> for packets received by
the machine and <code class="literal">1</code> for
packets sent by the machine.
</li><li class="listitem"><p>
a 1-byte field, the upper 4 bits of which indicate the type of packet, as per <acronym class="acronym">RFC</acronym> 1144:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<code class="literal">0x40</code>; an unmodified
<acronym class="acronym">IP</acronym> datagram
(<code class="constant">TYPE_IP</code>)
</li><li class="listitem">
<code class="literal">0x70</code>; an
uncompressed-<acronym class="acronym">TCP/IP</acronym>
datagram
(<code class="constant">UNCOMPRESSED_TCP</code>),
with that byte being the first byte of
the raw <acronym class="acronym">IP</acronym> header on
the wire, containing the connection
number in the protocol field
</li><li class="listitem">
<code class="literal">0x80</code>; a
compressed-<acronym class="acronym">TCP/IP</acronym>
datagram
(<code class="constant">COMPRESSED_TCP</code>),
with that byte being the first byte of
the compressed <acronym class="acronym">TCP/IP</acronym>
datagram header
</li></ul></div><p>
</p></li><li class="listitem">
for <code class="constant">UNCOMPRESSED_TCP</code>, the
rest of the modified <acronym class="acronym">IP</acronym>
header, and for
<code class="constant">COMPRESSED_TCP</code>, the
compressed <acronym class="acronym">TCP/IP</acronym> datagram
header
</li></ul></div><p>
for a total of 16 bytes; the uncompressed <acronym class="acronym">IP</acronym> datagram follows the header.
</p></dd><dt><span class="term">
<code class="constant">DLT_PPP</code>
</span></dt><dd>
<acronym class="acronym">PPP</acronym>; if the first 2 bytes are
<code class="literal">0xff</code> and <code class="literal">0x03</code>,
it's <acronym class="acronym">PPP</acronym> in
<acronym class="acronym">HDLC</acronym>-like framing, with the
<acronym class="acronym">PPP</acronym> header following those two
bytes, otherwise it's <acronym class="acronym">PPP</acronym> without
framing, and the packet begins with the
<acronym class="acronym">PPP</acronym> header.
</dd><dt><span class="term">
<code class="constant">DLT_FDDI</code>
</span></dt><dd>
<acronym class="acronym">FDDI</acronym>
</dd><dt><span class="term">
<code class="constant">DLT_ATM_RFC1483</code>
</span></dt><dd>
<acronym class="acronym">RFC</acronym> 1483
<acronym class="acronym">LLC/SNAP</acronym>-encapsulated
<acronym class="acronym">ATM</acronym>; the packet begins with an
<acronym class="acronym">IEEE</acronym> 802.2 <acronym class="acronym">LLC</acronym>
header.
</dd><dt><span class="term">
<code class="constant">DLT_RAW</code>
</span></dt><dd>
Raw <acronym class="acronym">IP</acronym>; the packet begins with an
<acronym class="acronym">IP</acronym> header.
</dd><dt><span class="term">
<code class="constant">DLT_PPP_SERIAL</code>
</span></dt><dd>
<acronym class="acronym">PPP</acronym> in
<acronym class="acronym">HDLC</acronym>-like framing, as per
<acronym class="acronym">RFC</acronym> 1662, or Cisco
<acronym class="acronym">PPP</acronym> with <acronym class="acronym">HDLC</acronym>
framing, as per section 4.3.1 of
<acronym class="acronym">RFC</acronym> 1547; the first byte will be
<code class="literal">0xFF</code> for <acronym class="acronym">PPP</acronym>
in <acronym class="acronym">HDLC</acronym>-like framing, and
will be <code class="literal">0x0F</code> or
<code class="literal">0x8F</code> for Cisco
<acronym class="acronym">PPP</acronym> with <acronym class="acronym">HDLC</acronym>
framing.
</dd><dt><span class="term">
<code class="constant">DLT_PPP_ETHER</code>
</span></dt><dd>
<acronym class="acronym">PPPoE</acronym>; the packet begins with a
<acronym class="acronym">PPPoE</acronym> header, as per
<acronym class="acronym">RFC</acronym> 2516.
</dd><dt><span class="term">
<code class="constant">DLT_C_HDLC</code>
</span></dt><dd>
Cisco <acronym class="acronym">PPP</acronym> with
<acronym class="acronym">HDLC</acronym> framing, as per section
4.3.1 of <acronym class="acronym">RFC</acronym> 1547.
</dd><dt><span class="term">
<code class="constant">DLT_IEEE802_11</code>
</span></dt><dd>
<acronym class="acronym">IEEE</acronym> 802.11 wireless
<acronym class="acronym">LAN</acronym>.
</dd><dt><span class="term">
<code class="constant">DLT_LOOP</code>
</span></dt><dd><p class="simpara">
OpenBSD loopback encapsulation; the link layer
header is a 4-byte field, in network byte
order, containing a <code class="constant">PF_</code> value
from OpenBSD's <code class="filename">socket.h</code> for the
network-layer protocol of the packet.
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
Note that, if a <em class="glossterm">savefile</em> is being read, those
<code class="constant">PF_</code> values are
<span class="emphasis"><em>not</em></span> necessarily those of the
machine reading the capture file.
</p></div></dd><dt><span class="term">
<code class="constant">DLT_LINUX_SLL</code>
</span></dt><dd><p>
Linux cooked capture encapsulation; the link layer
header contains, in order:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
a 2-byte "packet type", in network
byte order, which is one of:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<code class="literal">0</code>; packet was sent to
us by somebody else.
</li><li class="listitem">
<code class="literal">1</code>; packet was
broadcast by somebody else.
</li><li class="listitem">
<code class="literal">2</code>; packet was
multicast, but not broadcast, by
somebody else.
</li><li class="listitem">
<code class="literal">3</code>; packet was sent by
somebody else to somebody else.
</li><li class="listitem">
<code class="literal">4</code>; packet was sent by
us.
</li></ul></div><p>
</p></li><li class="listitem">
a 2-byte field, in network byte order,
containing a Linux
<code class="constant">ARPHRD_</code> value for the
link layer device type.
</li><li class="listitem">
a 2-byte field, in network byte order,
containing the length of the link layer
address of the sender of the packet (which
could be 0).
</li><li class="listitem">
an 8-byte field containing that number
of bytes of the link layer header (if there
are more than 8 bytes, only the first 8 are
present).
</li><li class="listitem">
a 2-byte field containing an Ethernet
protocol type, in network byte order, or
containing <code class="literal">1</code> for Novell
802.3 frames without an 802.2
<acronym class="acronym">LLC</acronym> header or
<code class="literal">4</code> for frames beginning with
an 802.2 <acronym class="acronym">LLC</acronym> header.
</li></ul></div><p>
</p></dd><dt><span class="term">
<code class="constant">DLT_LTALK</code>
</span></dt><dd>
Apple LocalTalk; the packet begins with an AppleTalk
<acronym class="acronym">LLAP</acronym> header.
</dd></dl></div><p>
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073152009584"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>getnonblock / setnonblock —
Manipulate the
<em class="firstterm">non-blocking</em> flag
</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int <strong class="fsfunc">getnonblock</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
<strong class="fsfunc">setnonblock</strong>
(</code></td><td><var class="pdparam">state</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
int <var class="pdparam">state</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073152016576"></a><h2>DESCRIPTION</h2><p>
<code class="function">getnonblock</code> returns the current
non-blocking state of the capture descriptor; it
always returns <span class="returnvalue">0</span> on <em class="glossterm">savefile</em>s.
</p></div><div class="refsect1"><a id="idp1073152019248"></a><h2>DESCRIPTION</h2><p>
<code class="function">setnonblock</code> puts a capture descriptor,
opened with <code class="function">open_live</code>, into
non-blocking mode, or takes it out of
non-blocking mode, depending on whether the
<em class="parameter"><code>state</code></em> argument is non-zero or
zero. It has no effect on <em class="glossterm">savefile</em>s. In non-blocking
mode, an attempt to read from the capture descriptor with
<code class="function">dispatch</code> will, if no packets are
currently available to be read, return
<span class="returnvalue">0</span> immediately rather than
blocking waiting for packets to arrive.
<code class="function">loop</code> and <code class="function">next</code> will
not work in non-blocking mode.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073152025552"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>dump_open — Create a Dumper object</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
Dumper <strong class="fsfunc">dump_open</strong>
(</code></td><td><var class="pdparam">filename</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
string <var class="pdparam">filename</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073152030128"></a><h2>DESCRIPTION</h2><p>
<code class="function">dump_open</code> is called to open a <em class="glossterm">savefile</em>
for writing and associate it to a newly created
<code class="classname">Dumper</code> instance. The name
<code class="filename">-</code> is a synonym for <code class="filename">stdout</code>.
<em class="parameter"><code>filename</code></em> specifies the name of the
file to open.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073152035072"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>close —
Close a Reader
</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
Reader <strong class="fsfunc">close</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073152038896"></a><h2>DESCRIPTION</h2><p>
<code class="function">close</code> closes a <code class="classname">Reader</code> using pcap_close.
</p></div></div></div><div class="reference"><div class="titlepage"><div><div><h1 class="title"><a id="idp1073152041312"></a>Dumper Object Reference</h1></div></div><hr /></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="refentrytitle"><a href="#idp1073152041952">dump</a></span><span class="refpurpose"> —
Dump a packet to a <em class="glossterm">savefile</em>
</span></dt><dt><span class="refentrytitle"><a href="#idp1073152051216">close</a></span><span class="refpurpose"> —
Close a Dumper
</span></dt></dl></div><div class="refentry"><a id="idp1073152041952"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>dump —
Dump a packet to a <em class="glossterm">savefile</em>
</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
<strong class="fsfunc">dump</strong>
(</code></td><td><var class="pdparam">header</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">data</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
Pkthdr <var class="pdparam">header</var>
</code>;<br /><code>
string <var class="pdparam">data</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073152047920"></a><h2>DESCRIPTION</h2><p>
<code class="function">dump</code> outputs a packet to the <em class="glossterm">savefile</em>
opened with <code class="function">dump_open</code> from type
<code class="classname">Reader</code>.
</p></div></div><div class="refentry"><div class="refentry.separator"><hr /></div><a id="idp1073152051216"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>close —
Close a Dumper
</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
Dumper <strong class="fsfunc">close</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073152055040"></a><h2>DESCRIPTION</h2><p>
<code class="function">close</code> closes a <code class="classname">Dumper</code>.
</p></div></div></div><div class="reference"><div class="titlepage"><div><div><h1 class="title"><a id="idp1073152057456"></a>Pkthdr Object Reference</h1></div></div><hr /></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="refentrytitle"><a href="#idp1073152058096">getts</a></span><span class="refpurpose"> — Obtain packet header information</span></dt></dl></div><div class="refentry"><a id="idp1073152058096"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>getts, getcaplen, getlen — Obtain packet header information</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
(long, long) <strong class="fsfunc">getts</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
long <strong class="fsfunc">getcaplen</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
long <strong class="fsfunc">getlen</strong>
(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073152066752"></a><h2>DESCRIPTION</h2><p>
<code class="function">getts</code>, <code class="function">getcaplen</code>
and <code class="function">getlen</code> return the timestamp,
capture length and total length fields of the packet header,
respectively.
</p><p>
Timestamp is a tuple with two elements: the number of
seconds since the Epoch, and the amount of microseconds past
the current second. The capture length is the number of
bytes of the packet that are available from the capture.
Finally, total length gives the length of the packet, in
bytes (which might be more than the number of bytes
available from the capture, if the length of the packet is
larger than the maximum number of bytes to capture).
</p></div></div></div><div class="reference"><div class="titlepage"><div><div><h1 class="title"><a id="idp1073152071120"></a>Bpf Object Reference</h1></div></div><hr /></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="refentrytitle"><a href="#idp1073152071760">filter</a></span><span class="refpurpose"> — Test a packet against a compiled filter</span></dt></dl></div><div class="refentry"><a id="idp1073152071760"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>filter — Test a packet against a compiled filter</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
int <strong class="fsfunc">filter</strong>
(</code></td><td><var class="pdparam">packet</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>
string <var class="pdparam">packet</var>
</code>;</div><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="idp1073152076336"></a><h2>DESCRIPTION</h2><p>
<code class="function">filter</code> tests a packet against a
compiled filter as returned by
<code class="classname">pcapy</code>'s <code class="function">compile</code>.
If the packet is allowed to pass through
<span class="returnvalue">-1</span> is returned, otherwise
<code class="function">filter</code> returns
<span class="returnvalue">0</span>.
</p></div></div></div><div class="bibliography"><div class="titlepage"><div><div><h2 class="title"><a id="idp1073152080944"></a>Bibliography</h2></div></div></div><div class="bibliodiv"><h3 class="title"><a id="idp1073152081584"></a>Sources</h3><div class="biblioentry"><a id="idp1073152082224"></a><p><span class="bibliomisc">
Portions of this work based on
<span class="citerefentry"><span class="refentrytitle">pcap</span>(3)</span> by the Lawrence
Berkeley National Laboratory, University of California,
Berkeley, CA.
. </span></p></div></div></div></div></body></html>