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 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
|
<?xml version='1.0'?>
<!DOCTYPE part PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"docbook/dtd/xml/4.1.2/docbookx.dtd" [
<!ENTITY corest "CORE SECURITY TECHNOLOGIES">
]>
<part>
<partinfo>
<copyright>
<year>2016-2018</year>
<holder>&corest;</holder>
</copyright>
<corpauthor>&corest;</corpauthor>
<keywordset>
<keyword>pcap</keyword>
<keyword>packet</keyword>
<keyword>capture</keyword>
<keyword>python</keyword>
</keywordset>
<revhistory>
<revision>
<revnumber>Revision: 16</revnumber>
<date>Date: 2018-06-04</date>
<authorinitials>Author: jkohen</authorinitials>
<revremark>2018 updated</revremark>
</revision>
</revhistory>
</partinfo>
<title>Pcapy Reference</title>
<reference>
<title>Pcapy Module Reference</title>
<refentry>
<refnamediv>
<refname>open_live</refname>
<refpurpose>Obtain a packet capture descriptor to look at packets on the network</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
Reader <function>open_live</function>
</funcdef>
<paramdef>
string <parameter>device</parameter>
</paramdef>
<paramdef>
int <parameter>snaplen</parameter>
</paramdef>
<paramdef>
int <parameter>promisc</parameter>
</paramdef>
<paramdef>
int <parameter>to_ms</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>open_live</function> is used to obtain a packet
capture descriptor to look at packets on the network.
<parameter>device</parameter> is a string that specifies the
network device to open; on Linux systems with 2.2 or later
kernels, a device argument of <literal>any</literal> or
<constant>NULL</constant> can be used to capture packets
from all interfaces. <parameter>snaplen</parameter>
specifies the maximum number of bytes to capture.
<parameter>promisc</parameter> 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 <literal>any</literal> device; if an
argument of <literal>any</literal> or
<constant>NULL</constant> is supplied, the
<parameter>promisc</parameter> flag is ignored.
<parameter>to_ms</parameter> 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.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>open_offline</refname>
<refpurpose>
Obtain a packet capture descriptor to look at packets on a <glossterm>savefile</glossterm>
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
Reader <function>open_offline</function>
</funcdef>
<paramdef>
string <parameter>filename</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>open_offline</function> is called to open a
<glossterm>savefile</glossterm> for reading. <parameter>filename</parameter>
specifies the name of the file to open. The file has the
same format as those used by
<citerefentry>
<refentrytitle>tcpdump</refentrytitle>
<manvolnum>8</manvolnum>
</citerefentry> and
<citerefentry>
<refentrytitle>tcpslice</refentrytitle>
<manvolnum>8</manvolnum>
</citerefentry>. The name
<filename>-</filename> is a synonym for
<filename class="devicefile">stdin</filename>.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>lookupdev</refname>
<refpurpose>
Return a network device suitable for use with
<function>open_live</function>
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
string <function>lookupdev</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>lookupdev</function> returns the name of a network
device suitable for use with <function>open_live</function>.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>findalldevs</refname>
<refpurpose>Obtain the list of available network devices</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
string[] <function>findalldevs</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>findalldevs</function> constructs a list of
network devices that can be opened with
<function>open_live</function>. (Note that there may be
network devices that cannot be opened with
<function>open_live</function>, 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.)
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>compile</refname>
<refpurpose>Compile a BPF filter</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
Bpf <function>compile</function>
</funcdef>
<paramdef>
int <parameter>linktype</parameter>
</paramdef>
<paramdef>
int <parameter>snaplen</parameter>
</paramdef>
<paramdef>
string <parameter>filter</parameter>
</paramdef>
<paramdef>
int <parameter>optimize</parameter>
</paramdef>
<paramdef>
int32 <parameter>netmask</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>compile</function> is used to compile the
<parameter>filter</parameter> into a filter program.
<function>snaplen</function> specifies the maximum number of
bytes to capture. <parameter>optimize</parameter> controls
whether optimization on the resulting code is performed.
<parameter>netmask</parameter> specifies the netmask of the
local network.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>create</refname>
<refpurpose>Creates a non-activated packet capture handle to look at packets on the network</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
Reader <function>create</function>
</funcdef>
<paramdef>
string <parameter>device</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>create</function> is used to create a
packet capture handle to look at packets on the network.
The returned handle must be activated with
<function>activate()</function> before packets can be captured
with it; options for the capture, such as promiscuous mode,
can be set on the handle before activating it.
</para>
</refsect1>
</refentry>
</reference>
<reference>
<title>Reader Object Reference</title>
<refentry>
<refnamediv>
<refname>dispatch</refname>
<refname>loop</refname>
<refpurpose>Collect and process packets</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
int <function>dispatch</function>
</funcdef>
<paramdef>
int <parameter>maxcant</parameter>
</paramdef>
<paramdef>
void <parameter>(* callback)</parameter>
<funcparams>Pkthdr, string</funcparams>
</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
int <function>loop</function>
</funcdef>
<paramdef>
int <parameter>maxcant</parameter>
</paramdef>
<paramdef>
void <parameter>(* callback)</parameter>
<funcparams>Pkthdr, string</funcparams>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>dispatch</function> is used to collect and process
packets. <parameter>maxcant</parameter> 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
<parameter>maxcant</parameter> packets may be processed. A
<parameter>cnt</parameter> of <literal>-1</literal>
processes all the packets received in one buffer when
reading a live capture, or all the packets in the file when
reading a <glossterm>savefile</glossterm>. <parameter>callback</parameter>
specifies a routine to be called with two arguments: a
<classname>Pkthdr</classname> instance describing the data
passed and the data itself.
</para>
<para>
The number of packets read is returned.
<returnvalue>0</returnvalue> 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 <glossterm>savefile</glossterm>.
</para>
<note>
<para>
When reading a live capture, <function>dispatch</function>
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 <emphasis>not</emphasis> 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 <function>dispatch</function> will return
after the timeout expires.
</para>
</note>
<para>
<function>loop</function> is similar to
<function>dispatch</function> except it keeps reading
packets until <parameter>maxcant</parameter> packets are
processed or an error occurs. It does
<emphasis>not</emphasis> return when live read timeouts
occur. Rather, specifying a non-zero read timeout to
<function>open_live</function> and then calling
<function>dispatch</function> allows the reception and
processing of any packets that arrive when the timeout
occurs. A negative <parameter>maxcant</parameter> causes
<function>loop</function> to loop forever (or at least until
an error occurs). <returnvalue>0</returnvalue> is returned
if <parameter>maxcant</parameter> is exhausted.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>next</refname>
<refpurpose>Collect the next packet</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
(Pkthdr, string) <function>next</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>next</function> reads the next packet (by calling
<function>dispatch</function> with a
<parameter>maxcant</parameter> of <constant>1</constant>)
and returns a tuple (header, data) where
<parameter>header</parameter> is a
<classname>Pkthdr</classname> instance describing the data
passed and <parameter>data</parameter> is the data itself.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>stats</refname>
<refpurpose>get capture statistics</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
(int32, int32, int32) <function>stats</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>stats</function> returns statistics on the current
capture as a tuple (recv, drop, ifdrop)
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>setfilter</refname>
<refpurpose>Specify a filter</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
<function>setfilter</function>
</funcdef>
<paramdef>
string <parameter>filter</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>setfilter</function> is used to specify a filter
for this object.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>getfd</refname>
<refpurpose>get a file descriptor on which a select() can be
done for a live capture</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
int <function>getfd</function>
</funcdef>
<paramdef>
string <parameter>filter</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>getfd</function> 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.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>set_snaplen</refname>
<refpurpose>Set the snapshot length for a not-yet-activated
capture handle</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
int <function>set_snaplen</function>
</funcdef>
<paramdef>
int <parameter>snaplen</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>set_snaplen</function> sets the snapshot length
to be used on a capture handle when the handle is activated
to snaplen.
<function>set_snaplen</function> returns 0 on success
or PCAP_ERROR_ACTIVATED if called on a capture handle that
has been activated.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>set_promisc</refname>
<refpurpose>Set promiscuous mode for a not-yet-activated
capture handle</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
int <function>set_promisc</function>
</funcdef>
<paramdef>
int <parameter>promisc</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>set_promisc</function> 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.
<function>set_promisc</function> returns 0 on success
or PCAP_ERROR_ACTIVATED if called on a capture handle that
has been activated.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>set_timeout</refname>
<refpurpose>Set the read timeout for a not-yet-activated
capture handle</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
int <function>set_timeout</function>
</funcdef>
<paramdef>
int <parameter>timeout</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>set_timeout</function> 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.
<function>set_timeout</function> returns 0 on success
or PCAP_ERROR_ACTIVATED if called on a capture handle that
has been activated.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>set_buffer_size</refname>
<refpurpose>Set the buffer size for a not-yet-activated capture handle
capture handle</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
int <function>set_buffer_size</function>
</funcdef>
<paramdef>
int <parameter>buffer_size</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>set_buffer_size</function> 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.
<function>set_buffer_size</function> returns 0 on success
or PCAP_ERROR_ACTIVATED if called on a capture handle that
has been activated.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>activate</refname>
<refpurpose>Activate a capture handle</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
int <function>activate</function>
</funcdef>
<void />
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>activate</function> 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.
<function>activate</function> 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.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>getnet</refname>
<refname>getmask</refname>
<refpurpose>Get the associated network number and mask</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
int32 <function>getnet</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>
int32 <function>getmask</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>getnet</function> and <function>getmask</function>
are used to determine the network number and mask associated
with the network device attached to this
<classname>Reader</classname>.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>datalink</refname>
<refpurpose>Obtain the link layer type</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
int <function>datalink</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>datalink</function> returns the link layer type; link layer types it can return include:
<variablelist>
<varlistentry>
<term>
<constant>DLT_NULL</constant>
</term>
<listitem>
<simpara>
<acronym>BSD</acronym> loopback encapsulation; the
link layer header is a 4-byte field, in host
byte order, containing a <constant>PF_</constant>
value from <filename
class="headerfile">socket.h</filename> for the
network-layer protocol of the packet.
</simpara>
<note>
<simpara>
<quote>host byte order</quote> is the byte order
of the machine on which the packets are captured,
and the <constant>PF_</constant> values are for
the <acronym>OS</acronym> of the machine on which
the packets are captured; if a live capture is
being done, <quote>host byte order</quote> is the
byte order of the machine capturing the packets,
and the <constant>PF_</constant> values are those
of the <acronym>OS</acronym> of the machine
capturing the packets, but if a <glossterm>savefile</glossterm> is being
read, the byte order and <constant>PF_</constant>
values are <emphasis>not</emphasis> necessarily
those of the machine reading the capture file.
</simpara>
</note>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_EN10MB</constant>
</term>
<listitem>
<simpara>Ethernet (10Mb, 100Mb, 1000Mb, and up)</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_IEEE802</constant>
</term>
<listitem>
<simpara>
<acronym>IEEE</acronym> 802.5 Token Ring
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_ARCNET</constant>
</term>
<listitem>
<simpara>
<acronym>ARCNET</acronym>
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_SLIP</constant>
</term>
<listitem>
<para>
<acronym>SLIP</acronym>; the link layer header contains, in order:
<itemizedlist>
<listitem>
<simpara>
a 1-byte flag, which is
<literal>0</literal> for packets received by
the machine and <literal>1</literal> for
packets sent by the machine.
</simpara>
</listitem>
<listitem>
<para>
a 1-byte field, the upper 4 bits of which indicate the type of packet, as per <acronym>RFC</acronym> 1144:
<itemizedlist>
<listitem>
<simpara>
<literal>0x40</literal>; an unmodified
<acronym>IP</acronym> datagram
(<constant>TYPE_IP</constant>)
</simpara>
</listitem>
<listitem>
<simpara>
<literal>0x70</literal>; an
uncompressed-<acronym>TCP/IP</acronym>
datagram
(<constant>UNCOMPRESSED_TCP</constant>),
with that byte being the first byte of
the raw <acronym>IP</acronym> header on
the wire, containing the connection
number in the protocol field
</simpara>
</listitem>
<listitem>
<simpara>
<literal>0x80</literal>; a
compressed-<acronym>TCP/IP</acronym>
datagram
(<constant>COMPRESSED_TCP</constant>),
with that byte being the first byte of
the compressed <acronym>TCP/IP</acronym>
datagram header
</simpara>
</listitem>
</itemizedlist>
</para>
</listitem>
<listitem>
<simpara>
for <constant>UNCOMPRESSED_TCP</constant>, the
rest of the modified <acronym>IP</acronym>
header, and for
<constant>COMPRESSED_TCP</constant>, the
compressed <acronym>TCP/IP</acronym> datagram
header
</simpara>
</listitem>
</itemizedlist>
for a total of 16 bytes; the uncompressed <acronym>IP</acronym> datagram follows the header.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_PPP</constant>
</term>
<listitem>
<simpara>
<acronym>PPP</acronym>; if the first 2 bytes are
<literal>0xff</literal> and <literal>0x03</literal>,
it's <acronym>PPP</acronym> in
<acronym>HDLC</acronym>-like framing, with the
<acronym>PPP</acronym> header following those two
bytes, otherwise it's <acronym>PPP</acronym> without
framing, and the packet begins with the
<acronym>PPP</acronym> header.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_FDDI</constant>
</term>
<listitem>
<simpara>
<acronym>FDDI</acronym>
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_ATM_RFC1483</constant>
</term>
<listitem>
<simpara>
<acronym>RFC</acronym> 1483
<acronym>LLC/SNAP</acronym>-encapsulated
<acronym>ATM</acronym>; the packet begins with an
<acronym>IEEE</acronym> 802.2 <acronym>LLC</acronym>
header.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_RAW</constant>
</term>
<listitem>
<simpara>
Raw <acronym>IP</acronym>; the packet begins with an
<acronym>IP</acronym> header.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_PPP_SERIAL</constant>
</term>
<listitem>
<simpara>
<acronym>PPP</acronym> in
<acronym>HDLC</acronym>-like framing, as per
<acronym>RFC</acronym> 1662, or Cisco
<acronym>PPP</acronym> with <acronym>HDLC</acronym>
framing, as per section 4.3.1 of
<acronym>RFC</acronym> 1547; the first byte will be
<literal>0xFF</literal> for <acronym>PPP</acronym>
in <acronym>HDLC</acronym>-like framing, and
will be <literal>0x0F</literal> or
<literal>0x8F</literal> for Cisco
<acronym>PPP</acronym> with <acronym>HDLC</acronym>
framing.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_PPP_ETHER</constant>
</term>
<listitem>
<simpara>
<acronym>PPPoE</acronym>; the packet begins with a
<acronym>PPPoE</acronym> header, as per
<acronym>RFC</acronym> 2516.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_C_HDLC</constant>
</term>
<listitem>
<simpara>
Cisco <acronym>PPP</acronym> with
<acronym>HDLC</acronym> framing, as per section
4.3.1 of <acronym>RFC</acronym> 1547.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_IEEE802_11</constant>
</term>
<listitem>
<simpara>
<acronym>IEEE</acronym> 802.11 wireless
<acronym>LAN</acronym>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_LOOP</constant>
</term>
<listitem>
<simpara>
OpenBSD loopback encapsulation; the link layer
header is a 4-byte field, in network byte
order, containing a <constant>PF_</constant> value
from OpenBSD's <filename
class="headerfile">socket.h</filename> for the
network-layer protocol of the packet.
</simpara>
<note>
<simpara>
Note that, if a <glossterm>savefile</glossterm> is being read, those
<constant>PF_</constant> values are
<emphasis>not</emphasis> necessarily those of the
machine reading the capture file.
</simpara>
</note>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_LINUX_SLL</constant>
</term>
<listitem>
<para>
Linux cooked capture encapsulation; the link layer
header contains, in order:
<itemizedlist>
<listitem>
<para>
a 2-byte "packet type", in network
byte order, which is one of:
<itemizedlist>
<listitem>
<simpara>
<literal>0</literal>; packet was sent to
us by somebody else.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>1</literal>; packet was
broadcast by somebody else.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>2</literal>; packet was
multicast, but not broadcast, by
somebody else.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>3</literal>; packet was sent by
somebody else to somebody else.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>4</literal>; packet was sent by
us.
</simpara>
</listitem>
</itemizedlist>
</para>
</listitem>
<listitem>
<simpara>
a 2-byte field, in network byte order,
containing a Linux
<constant>ARPHRD_</constant> value for the
link layer device type.
</simpara>
</listitem>
<listitem>
<simpara>
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).
</simpara>
</listitem>
<listitem>
<simpara>
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).
</simpara>
</listitem>
<listitem>
<simpara>
a 2-byte field containing an Ethernet
protocol type, in network byte order, or
containing <literal>1</literal> for Novell
802.3 frames without an 802.2
<acronym>LLC</acronym> header or
<literal>4</literal> for frames beginning with
an 802.2 <acronym>LLC</acronym> header.
</simpara>
</listitem>
</itemizedlist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>DLT_LTALK</constant>
</term>
<listitem>
<simpara>
Apple LocalTalk; the packet begins with an AppleTalk
<acronym>LLAP</acronym> header.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>getnonblock / setnonblock</refname>
<refpurpose>
Manipulate the
<firstterm>non-blocking</firstterm> flag
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
int <function>getnonblock</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>
<function>setnonblock</function>
</funcdef>
<paramdef>
int <parameter>state</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>getnonblock</function> returns the current
non-blocking state of the capture descriptor; it
always returns <returnvalue>0</returnvalue> on <glossterm>savefile</glossterm>s.
</para>
</refsect1>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>setnonblock</function> puts a capture descriptor,
opened with <function>open_live</function>, into
non-blocking mode, or takes it out of
non-blocking mode, depending on whether the
<parameter>state</parameter> argument is non-zero or
zero. It has no effect on <glossterm>savefile</glossterm>s. In non-blocking
mode, an attempt to read from the capture descriptor with
<function>dispatch</function> will, if no packets are
currently available to be read, return
<returnvalue>0</returnvalue> immediately rather than
blocking waiting for packets to arrive.
<function>loop</function> and <function>next</function> will
not work in non-blocking mode.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>dump_open</refname>
<refpurpose>Create a Dumper object</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
Dumper <function>dump_open</function>
</funcdef>
<paramdef>
string <parameter>filename</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>dump_open</function> is called to open a <glossterm>savefile</glossterm>
for writing and associate it to a newly created
<classname>Dumper</classname> instance. The name
<filename>-</filename> is a synonym for <filename
class="devicefile">stdout</filename>.
<parameter>filename</parameter> specifies the name of the
file to open.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>close</refname>
<refpurpose>
Close a Reader
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
Reader <function>close</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>close</function> closes a <classname>Reader</classname> using pcap_close.
</para>
</refsect1>
</refentry>
</reference>
<reference>
<title>Dumper Object Reference</title>
<refentry>
<refnamediv>
<refname>dump</refname>
<refpurpose>
Dump a packet to a <glossterm>savefile</glossterm>
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
<function>dump</function>
</funcdef>
<paramdef>
Pkthdr <parameter>header</parameter>
</paramdef>
<paramdef>
string <parameter>data</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>dump</function> outputs a packet to the <glossterm>savefile</glossterm>
opened with <function>dump_open</function> from type
<classname>Reader</classname>.
</para>
</refsect1>
</refentry>
<refentry>
<refnamediv>
<refname>close</refname>
<refpurpose>
Close a Dumper
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
Dumper <function>close</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>close</function> closes a <classname>Dumper</classname>.
</para>
</refsect1>
</refentry>
</reference>
<reference>
<title>Pkthdr Object Reference</title>
<refentry>
<refnamediv>
<refname>getts</refname>
<refname>getcaplen</refname>
<refname>getlen</refname>
<refpurpose>Obtain packet header information</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
(long, long) <function>getts</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>
long <function>getcaplen</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>
long <function>getlen</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>getts</function>, <function>getcaplen</function>
and <function>getlen</function> return the timestamp,
capture length and total length fields of the packet header,
respectively.
</para>
<para>
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).
</para>
</refsect1>
</refentry>
</reference>
<reference>
<title>Bpf Object Reference</title>
<refentry>
<refnamediv>
<refname>filter</refname>
<refpurpose>Test a packet against a compiled filter</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
int <function>filter</function>
</funcdef>
<paramdef>
string <parameter>packet</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>filter</function> tests a packet against a
compiled filter as returned by
<classname>pcapy</classname>'s <function>compile</function>.
If the packet is allowed to pass through
<returnvalue>-1</returnvalue> is returned, otherwise
<function>filter</function> returns
<returnvalue>0</returnvalue>.
</para>
</refsect1>
</refentry>
</reference>
<bibliography>
<title>Bibliography</title>
<bibliodiv>
<title>Sources</title>
<biblioentry>
<bibliomisc>
Portions of this work based on
<citerefentry>
<refentrytitle>pcap</refentrytitle>
<manvolnum>3</manvolnum>
</citerefentry> by the Lawrence
Berkeley National Laboratory, University of California,
Berkeley, CA.
</bibliomisc>
</biblioentry>
</bibliodiv>
</bibliography>
</part>
|