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

Unable to identify when epcap binary is ready to capture packets #23

Closed brennana closed 6 years ago

brennana commented 6 years ago

I have found that after calling epcap:start_link/1, the function call will finish before the epcap binary itself is bound to the chosen interface and ready to actually capture packets.

I imagine it's not possible to actually tell if epcap is ready from erlang's side after the binary has started; however, would it be possible for the binary to let erlang know when it is ready to capture packets, which could be sent to the epcap caller in the form of a message (e.g. epcap_ready)?

Without knowing when epcap is ready to capture packets, I am forced to use timer:sleep/1 for about 500ms in the hopes that it is ready by then. Usually it is, but under heavy system load this isn't always the case, and it would not be good to wait longer. Receiving a ready message would be very helpful so that I do not miss packets that I expect to capture due to epcap starting later than estimated.

msantos commented 6 years ago

Thanks for the feedback! That is a great idea. Maybe the simplest way would be to make start_link() block until the epcap_ready message is received. I will have a look at doing this in the next few days.

Thanks again!