|
18 | 18 | <para>The Npcap API is exported by <filename>wpcap.dll</filename> and is the |
19 | 19 | Windows port of <ulink url="https://www.tcpdump.org/">libpcap</ulink>. |
20 | 20 | The API and functions are described in |
21 | | - <ulink url="wpcap/pcap.html">the pcap(1) man page</ulink>. |
| 21 | + <ulink url="wpcap/pcap.html">the pcap(1) man page</ulink>. |
| 22 | + This port varies from the standard Unix libpcap API in just a few ways. |
| 23 | + First, the <literal>pcap_get_selectable_fd()</literal> and |
| 24 | + <literal>pcap_get_required_select_timeout()</literal> |
| 25 | + functions are not defined or exported. Second, as described in |
| 26 | + <xref linkend="npcap-api-extensions"/>, Npcap extends the libpcap API with |
| 27 | + a set of non-portable functions. Lastly, Npcap includes functions from the |
| 28 | + remote capture API of libpcap, which is described in |
| 29 | + <xref linkend="npcap-api-remote"/>. |
22 | 30 | </para> |
| 31 | + |
23 | 32 | <sect2 id="npcap-api-extensions"> |
24 | 33 | <title>Extensions to libpcap for Windows</title> |
25 | 34 | <para> |
|
278 | 287 |
|
279 | 288 | </variablelist> |
280 | 289 | </sect2> |
| 290 | + |
| 291 | + <sect2 id="npcap-api-remote"> |
| 292 | + <title>The libpcap remote capture API</title> |
| 293 | + <para> |
| 294 | + WinPcap introduced several additional functions to the libpcap API in |
| 295 | + order to support remote capture. While the upstream libpcap project has |
| 296 | + absorbed these functions, they have not yet published documentation on |
| 297 | + them. Here is a brief overview. |
| 298 | + </para> |
| 299 | + <variablelist> |
| 300 | + <varlistentry> |
| 301 | + <term> |
| 302 | + <code>pcap_open</code> |
| 303 | + </term> |
| 304 | + <listitem> |
| 305 | + <para> |
| 306 | + Opens a remote or local capture handle. |
| 307 | + </para> |
| 308 | + <code>pcap_t* pcap_open(const char * source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth *auth, char *errbuf);</code> |
| 309 | + <para> |
| 310 | + This routine can open a savefile, a local device, or a device on |
| 311 | + a remote machine running an RPCAP server. |
| 312 | + </para> |
| 313 | + <variablelist> |
| 314 | + <varlistentry> |
| 315 | + <term><code>source</code></term> |
| 316 | + <listitem> |
| 317 | + <para> |
| 318 | + Zero-terminated string containing the source name to open. |
| 319 | + The source name must be in one of the following formats: |
| 320 | + </para> |
| 321 | + <itemizedlist> |
| 322 | + <listitem><para><literal>file://path/to/file.pcap</literal></para></listitem> |
| 323 | + <listitem><para> |
| 324 | + <literal>rpcap://devicename</literal> (or the equivalent, |
| 325 | + <literal>devicename</literal>) |
| 326 | + </para></listitem> |
| 327 | + <listitem><para><literal>rpcap://host/devicename</literal></para></listitem> |
| 328 | + <listitem><para><literal>rpcap://host:port/devicename</literal></para></listitem> |
| 329 | + </itemizedlist> |
| 330 | + <para> |
| 331 | + Adapter names returned by <literal>pcap_findalldevs_ex()</literal> |
| 332 | + are already in this format. For convenience, compatible source |
| 333 | + strings can be built with the helper function, |
| 334 | + <literal>int pcap_createsrcstr(char *source, int type, const char *host, const char *port, const char *name, char *errbuf)</literal>, |
| 335 | + where <literal>type</literal> is one of |
| 336 | + <literal>PCAP_SRC_FILE</literal>, |
| 337 | + <literal>PCAP_SRC_IFLOCAL</literal>, or |
| 338 | + <literal>PCAP_SRC_IFREMOTE</literal>, |
| 339 | + and <literal>source</literal> is a user-allocated buffer of |
| 340 | + at least <literal>PCAP_BUF_SIZE</literal> bytes. |
| 341 | + </para> |
| 342 | + </listitem> |
| 343 | + </varlistentry> |
| 344 | + <varlistentry> |
| 345 | + <term><code>snaplen</code></term> |
| 346 | + <listitem> |
| 347 | + <para> |
| 348 | + See the documentation for |
| 349 | + <ulink url="wpcap/pcap_open_live.html">pcap_open_live()</ulink>. |
| 350 | + </para> |
| 351 | + </listitem> |
| 352 | + </varlistentry> |
| 353 | + <varlistentry> |
| 354 | + <term><code>flags</code></term> |
| 355 | + <listitem> |
| 356 | + <para> |
| 357 | + Keeps several flags that can be needed for capturing packets. |
| 358 | + The allowed flags are defined in the pcap_open() flags . |
| 359 | + </para> |
| 360 | + </listitem> |
| 361 | + </varlistentry> |
| 362 | + <varlistentry> |
| 363 | + <term><code>read_timeout></code></term> |
| 364 | + <listitem> |
| 365 | + <para> |
| 366 | + See the documentation for |
| 367 | + <ulink url="wpcap/pcap_open_live.html">pcap_open_live()</ulink>. |
| 368 | + </para> |
| 369 | + </listitem> |
| 370 | + </varlistentry> |
| 371 | + <varlistentry> |
| 372 | + <term><code>auth</code></term> |
| 373 | + <listitem> |
| 374 | + <para> |
| 375 | + A pointer to a 'struct pcap_rmtauth' that keeps the |
| 376 | + information required to authenticate the user on a remote |
| 377 | + machine. In case this is not a remote capture, this pointer |
| 378 | + can be set to NULL. |
| 379 | + </para> |
| 380 | + </listitem> |
| 381 | + </varlistentry> |
| 382 | + <varlistentry> |
| 383 | + <term><code>errbuf</code></term> |
| 384 | + <listitem> |
| 385 | + <para> |
| 386 | + <para> |
| 387 | + See the documentation for |
| 388 | + <ulink url="wpcap/pcap_open_live.html">pcap_open_live()</ulink>. |
| 389 | + </para> |
| 390 | + </listitem> |
| 391 | + </varlistentry> |
| 392 | + </variablelist> |
| 393 | + |
| 394 | + <para> |
| 395 | + <emphasis>Portability notes:</emphasis> For opening a savefile, the |
| 396 | + <ulink url="wpcap/pcap_open_offline.html">pcap_open_offline</ulink> |
| 397 | + routines can be used, and will work just as well; code using them |
| 398 | + will work on more platforms than code using <literal>pcap_open()</literal> |
| 399 | + to open savefiles. |
| 400 | + </para> |
| 401 | + |
| 402 | + <para> |
| 403 | + For opening a local device, |
| 404 | + <ulink url="wpcap/pcap_open_live.html">pcap_open_live()</ulink> |
| 405 | + can be used; it supports most of the capabilities than |
| 406 | + <literal>pcap_open()</literal> supports, and code using it will work |
| 407 | + on more platforms than code using <literal>pcap_open()</literal>. |
| 408 | + <ulink url="wpcap/pcap_create.html">pcap_create()</ulink> and |
| 409 | + <ulink url="wpcap/pcap_activate.html">pcap_activate()</literal> |
| 410 | + can also be used; they support all capabilities that |
| 411 | + <literal>pcap_open()</literal> supports, except for the Windows-only |
| 412 | + <literal>PCAP_OPENFLAG_NOCAPTURE_LOCAL</literal>, |
| 413 | + and they support additional capabilities. |
| 414 | + </para> |
| 415 | + |
| 416 | + <para> |
| 417 | + For opening a remote capture, <literal>pcap_open()</literal> is |
| 418 | + currently the only API available. |
| 419 | + </para> |
| 420 | + </listitem> |
| 421 | + </varlistentry> |
| 422 | + <varlistentry> |
| 423 | + <term> |
| 424 | + <code>pcap_findalldevs_ex</code> |
| 425 | + </term> |
| 426 | + <listitem> |
| 427 | + <para> |
| 428 | + Lists local and remote capture sources. |
| 429 | + </para> |
| 430 | + <code>int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf);</code> |
| 431 | + <variablelist> |
| 432 | + <varlistentry> |
| 433 | + <term><code>source</code></term> |
| 434 | + <listitem> |
| 435 | + <para> |
| 436 | + Zero-terminated string containing the source name to list. |
| 437 | + The source name must be in one of the following formats: |
| 438 | + </para> |
| 439 | + <itemizedlist> |
| 440 | + <listitem><para> |
| 441 | + <literal>file://path/to/directory</literal> |
| 442 | + - lists capture files in a directory |
| 443 | + </para></listitem> |
| 444 | + <listitem><para> |
| 445 | + <literal>rpcap://</literal> - lists local adapters |
| 446 | + </para></listitem> |
| 447 | + <listitem><para> |
| 448 | + <literal>rpcap://host[:port]</literal> |
| 449 | + - lists remote adapters |
| 450 | + </para></listitem> |
| 451 | + </itemizedlist> |
| 452 | + </listitem> |
| 453 | + </varlistentry> |
| 454 | + <varlistentry> |
| 455 | + <term><code>auth</code></term> |
| 456 | + <listitem> |
| 457 | + <para>See <literal>pcap_open()</literal>.</para> |
| 458 | + </listitem> |
| 459 | + </varlistentry> |
| 460 | + <varlistentry> |
| 461 | + <term><code>alldevs</code></term> |
| 462 | + <listitem> |
| 463 | + <para> |
| 464 | + See <ulink href="wpcap/pcap_findalldevs.html">pcap_findalldevs()</ulink>. |
| 465 | + </para> |
| 466 | + </listitem> |
| 467 | + </varlistentry> |
| 468 | + <varlistentry> |
| 469 | + <term><code>errbuf</code></term> |
| 470 | + <listitem> |
| 471 | + <para> |
| 472 | + See <ulink href="wpcap/pcap_findalldevs.html">pcap_findalldevs()</ulink>. |
| 473 | + </para> |
| 474 | + </listitem> |
| 475 | + </varlistentry> |
| 476 | + </variablelist> |
| 477 | + <para> |
| 478 | + As with <literal> pcap_findalldevs()</literal>, the buffer returned in |
| 479 | + <literal>alldevs</literal> must be freed using |
| 480 | + <ulink href="wpcap/pcap_freealldevs.html">pcap_freealldevs()</ulink>. |
| 481 | + </para> |
| 482 | + </listitem> |
| 483 | + </varlistentry> |
| 484 | + </variablelist> |
| 485 | + </sect2> |
281 | 486 | </sect1> |
0 commit comments