tcpdump mailing list archives

Multiple call to pcap_open_live


From: Benjamin Vanheuverzwijn <bvanheu () gmail com>
Date: Mon, 18 Nov 2013 00:38:24 -0500

Hi,

libpcap version: 1.4.0 (on archlinux)

Is it possible to have multiple call to "pcap_open_live()" followed by
pcap_close() ?

It seems like pcap_close() doesn't cleanly close opened resources, if you
strace the following program, you will see file descriptors growing up.

Am i doing it wrong? How it should be done?

Thanks,

To reproduce:
// Compile with gcc -o openlive openlive.c -l pcap
#include <pcap.h>

int main(int argc, char *argv[]) {
    int i=0;
    for (i = 0; i != 2000; ++i) {
        char errbuf[256];
        pcap_t *pcap = pcap_open_live("wls3", 1024, 1, 0, errbuf);
        pcap_close(pcap);
    }
    return 0;
}

$ strace ./openlive
[...]
open("/sys/bus/usb/devices/4-2/devnum", O_RDONLY) = 16
fstat(16, {st_mode=S_IFREG|0444, st_size=4096, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7f5e040f0000
read(16, "8\n", 4096)                   = 2
[...]
open("/sys/bus/usb/devices/usb4/speed", O_RDONLY) = 91
fstat(91, {st_mode=S_IFREG|0444, st_size=4096, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7fc006371000
read(91, "480\n", 4096)                 = 4


-- 
Benjamin Vanheuverzwijn
_______________________________________________
tcpdump-workers mailing list
tcpdump-workers () lists tcpdump org
https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers


Current thread: