如何使用 pcap 从多个接口捕获流量

ziu*_*ziu 5 c linux interface pcap

为了使用 pcap 从多个接口嗅探,我将执行以下操作(在伪代码中):

foreach interface:
    open a file descriptor using pcap_open_live()
    set the file descriptor to non-blocking

while true:
    check for a ready file descriptor using select() or an equivalent I/O multiplexer
    read data from every ready file descriptor using pcap_dispatch()
    handle EndOfStream or Errors and break out of loop if needed
Run Code Online (Sandbox Code Playgroud)

这是否足够或者是否有一些特别的注意事项需要考虑?

gno*_*ule 1

我在尝试使用 pcap 从特定接口捕获时遇到了一些问题,并在此询问。似乎很少有人熟悉pcap。我的问题以及我最终得到的答案指出了非常有用的细节,可以在以下链接中找到,您可能会发现有用:

对 libcap (pcap) 和无线感到困惑