My Void Linux
is a virtual machine. I implemented a simple capturing packets program using libpcap, but found the program is blocked in pcap_next_ex()
:
(gdb) bt
#0 0x00007ffff7ad7763 in __GI___poll (fds=fds@entry=0x7fffffffe160, nfds=nfds@entry=1, timeout=-1)
at ../sysdeps/unix/sysv/linux/poll.c:29
#1 0x00007ffff7f8309d in poll (__timeout=<optimized out>, __nfds=1, __fds=0x7fffffffe160) at /usr/include/bits/poll2.h:46
#2 pcap_wait_for_frames_mmap (handle=handle@entry=0x55555556eba0) at ./pcap-linux.c:5018
#3 0x00007ffff7f886f4 in pcap_read_linux_mmap_v3 (handle=0x55555556eba0, max_packets=1, callback=0x7ffff7f82bf0 <pcap_oneshot_mmap>,
user=0x7fffffffe1f0 "\260\355VUUU") at ./pcap-linux.c:5577
#4 0x00007ffff7f8c6a2 in pcap_next_ex (p=<optimized out>, pkt_header=<optimized out>, pkt_data=<optimized out>) at ./pcap.c:505
......
The libpcap
version in Void Linux
is 1.9.1
. After checking code, I found although I set timeout in pcap_open_live()
, this value doesn’t take effect in set_poll_timeout:
......
if (handlep->tp_version == TPACKET_V3 && !broken_tpacket_v3)
handlep->poll_timeout = -1; /* block forever, let TPACKET_V3 wake us up */
......
I don’t have physical machine, so not sure this issue only happens in virtual machine or not.