开发者

Listening on two devices at once with libpcap

I am trying to listen on two devices with libpcap but I still cant find out how to do the trick. I tried to set device to "any" but it isnt working. I am trying to write dhcp relay agent so i need to listen on eth0 and eth1.

I tried to create two pcap_loops, each with different device and handler, but only first pcap_loop works, second one is ignored.

Is there any way how to do this or should I leave libpcap and try to do it with raw so开发者_如何学运维ckets?


You'll need to run your pcap_loop() in separate threads, one for each interface, we do that, and it works.

Some parts of libpcap, isn't thread safe though, atleast pcap_setfilter(), so provide your own locking around that.

If you do no want to use threads, you'll have to provide an event loop yourself, where you monitor the file descriptors of each device with select/poll or similar. You can get the file descriptor for a device handle with pcap_get_selectable_fd().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜