msantos / epcap

Erlang packet capture interface using pcap
http://listincomprehension.com/2009/12/erlang-packet-sniffer-using-ei-and.html
BSD 3-Clause "New" or "Revised" License
178 stars 56 forks source link

Combine 'timeout' and 'immediate' options #30

Closed erlbeck closed 3 years ago

erlbeck commented 3 years ago

Currently the 'timeout' and 'immediate' options map to pcap_set_timeout and pcap_set_immediate_mode, where the latter is activated by default. Thus the timeout is only honoured when 'immediate' is set to false. In addition the timeout value 0 has an undefined behaviour according to pcap_set_timeout(3PCAP) and may cause infinity waiting according to pcap(3PCAP).

See also #29 for a related discussion.

Erlang/OTP timeouts are generally given by either the number of milliseconds to wait, 'infinity' to disable the timeout or 0 (if permitted) to do something immediately.

Change the behaviour of the 'timeout' parameter to be similar to be compatible with the Erlang/OTP way:

Remove the stand-alone 'immediate' option.

Change the epcap command line option -t to use 0 for immediate mode and <0 to represent 'infinity'.

Note that this will change the behaviour for {timeout, 0} on Linux when using libpcap >1.5.0.

Note also that according to pcap(3PCAP) the support of "packet buffer timeouts" may not be provided by all platforms.

msantos commented 3 years ago

@erlbeck sorry for the delay, it seems a bad gmail filter I setup accidentally my github notifications and I missed this.

Thank you for the patch!