我想將一個基於libpcap的程序移植到macos,它似乎是爲windows和linux編寫的。在pcap_open_live函數中,讀取超時設置爲-1,與PacketOpen相同,在macOS上,當嘗試打開接口BIOCSRTIMEOUT時會導致錯誤:無效的參數。我無法找到什麼-1讀取超時實際上做任何文檔。另外,有沒有一個版本可以讓我在基於BPF的libpcap上做同樣的事情?在winpcap和linux libpcap上做什麼to_ms = -1?
0
A
回答
1
在winpcap和linux libpcap上做什麼to_ms = -1?
無法預測。引用主分支pcap(3pcap)手冊頁:
packet buffer timeout
If, when capturing, packets are delivered as soon as they
arrive, the application capturing the packets will be woken up
for each packet as it arrives, and might have to make one or
more calls to the operating system to fetch each packet.
If, instead, packets are not delivered as soon as they arrive,
but are delivered after a short delay (called a "packet buffer
timeout"), more than one packet can be accumulated before the
packets are delivered, so that a single wakeup would be done for
multiple packets, and each set of calls made to the operating
system would supply multiple packets, rather than a single
packet. This reduces the per‐packet CPU overhead if packets are
arriving at a high rate, increasing the number of packets per
second that can be captured.
The packet buffer timeout is required so that an application
won’t wait for the operating system’s capture buffer to fill up
before packets are delivered; if packets are arriving slowly,
that wait could take an arbitrarily long period of time.
Not all platforms support a packet buffer timeout; on platforms
that don’t, the packet buffer timeout is ignored. A zero value
for the timeout, on platforms that support a packet buffer time‐
out, will cause a read to wait forever to allow enough packets
to arrive, with no timeout.
NOTE: the packet buffer timeout cannot be used to cause calls
that read packets to return within a limited period of time,
because, on some platforms, the packet buffer timeout isn’t sup‐
ported, and, on other platforms, the timer doesn’t start until
at least one packet arrives. This means that the packet buffer
timeout should NOT be used, for example, in an interactive
application to allow the packet capture loop to ‘‘poll’’ for
user input periodically, as there’s no guarantee that a call
reading packets will return after the timeout expires even if no
packets have arrived.
沒有關於負超時的說法;我會更新它明確地說不應該使用負值。 (不是在Windows上,不在MacOS上,不在Linux上,不在* BSD上,不在Solaris上,不在AIX上,不在HP-UX上,不在Tru64 UNIX上,不在IRIX上,而不在上,任何東西)
通過將超時設置爲-1,它們可能是意圖將pcap_t
置於「非阻塞模式」,其中嘗試讀取將在沒有數據包等待讀取時立即返回,而不是等待數據包到達。因此,請在pcap_open_live()
調用之後提供例如100(表示1/10秒)的超時並使用pcap_setnonblock()
將pcap_t
置於非阻塞模式。這應該在全部平臺上工作。
相關問題
- 1. linux上的winpcap
- 2. WinPcap的 - LIBPCAP - packet_handler通知
- 3. $ {1}和$ {*}做什麼?
- 4. 什麼是Wireshark和WinPcap?
- 5. winpcap/libpcap與原始套接字
- 6. [1]在功能上做了什麼?
- 7. libpcap和winpcap中的函數是否有相同的名稱?
- 8. 「if(1)」做什麼?
- 9. 什麼是ld-linux.so.2和linux-gate.so.1?
- 10. Verilog爲什麼[NumberOfBits-1:0]和它在做什麼
- 11. 做什麼:+和:或者在計劃上做什麼?
- 12. `sort +0 -1`做什麼?
- 13. linux下的libpcap編程
- 14. JavaScript中做什麼(0&1)?
- 15. b!= a&1做什麼?
- 16. 丘比特在Linux中做什麼?
- 17. Winpcap和DeviceIoControl - Win7上的錯誤代碼1
- 18. 什麼是0xaa和0x55在做什麼?
- 19. 在這裏做什麼`end + 1`行?
- 20. $ 1在jest config中做了什麼?
- 21. c - struct - 額外的「:1」在做什麼?
- 22. * zoom:1在bootstrap中做了什麼?
- 23. 是什麼,而(1)在Gmail中做
- 24. 「$ K2ko {$ D} {$ C} = 1」在perl中做什麼?
- 25. 這段代碼在做什麼? (size_t)-1
- 26. WPF能做什麼和不做什麼?
- 27. $ /和$ \做什麼?
- 28. 什麼是Linux上
- 29. [[和]]在vim中做什麼?
- 30. 爲什麼alah [j + 1]在這裏什麼都不做?