Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Is there some way to disable this buffering on libpcap</p> </blockquote> <p>There's currently no libpcap API to do that.</p> <p>However, depending on what OS you're running, there may be ways to do it for that particular OS, i.e. you can do it, but in a non-portable fashion.</p> <p>For systems that use BPF, including *BSD and...</p> <p>...OS X, which, given the <code>"en0"</code>, I suspect you're using, the way to do it is to do something such as:</p> <p>Creating a <code>set_immediate_mode.h</code> header file containing:</p> <pre><code>extern int set_immediate_mode(int fd); </code></pre> <p>Creating a <code>set_immediate_mode.c</code> source file containing:</p> <pre><code>#include &lt;sys/types.h&gt; #include &lt;sys/time.h&gt; #include &lt;sys/ioctl.h&gt; #include &lt;net/bpf.h&gt; #include "set_immediate_mode.h" int set_immediate_mode(int fd) { int on = 1; return ioctl(fd, BIOCIMMEDIATE, &amp;on); } </code></pre> <p>Adding <code>#include &lt;string.h&gt;</code> and <code>#include &lt;errno.h&gt;</code> to your program if it's not already including those files, adding <code>#include "set_immediate_mode.h"</code> to your program, and adding, after the <code>pcap_open_live()</code> call succeeds, the following code:</p> <pre><code>int fd; fd = pcap_fileno(handle); if (fd == -1) { fprintf(stderr, "Can't get file descriptor for pcap_t (this should not happen)\n"); return 2; } if (set_immediate_mode(fd) == -1) { fprintf(stderr, "BIOCIMMEDIATE failed: %s\n", strerror(errno)); return 2; } </code></pre> <p>That will <em>completely</em> disable the buffering that BPF normally does (that's the buffering you're seeing with libpcap; see the BPF(4) man page), so that packets are delivered as soon as they arrive. That changes the way buffering is done in ways that might cause BPF's internal buffers to fill up faster than they would if the normal buffering is done, so that <em>might</em> cause packets to be lost when they wouldn't otherwise be lost, but using <code>pcap_set_buffer_size()</code>, as suggested by Kiran Bandla, could help that <em>if</em> it happens (which it might not, especially given that you're using a filter to keep "uninteresting" packets from being put into BPF's buffer in the first place).</p> <p>On Linux, this is currently not necessary - what buffering is done doesn't have a timeout for the delivery of packets. On Solaris, it would be done similarly on Solaris 11 (as libpcap uses BPF), but would be done differently on earlier versions of Solaris (as they didn't have BPF and libpcap uses DLPI). On Windows with WinPcap, <code>pcap_open()</code> has a flag for that.</p> <p>A future version of libpcap will probably have an API for this; I can't promise when that will happen.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload