New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
immediate os error in osx and linux platform #12
Comments
@yangbh so this code seems to work fine for me on OSX import pcap
print 'Opening interface...'
pc = pcap.pcap(promisc=True)
for timestamp, packet in pc:
print 'Packet...', repr(packet) On OSX, if I set immediate=True obviously I get packets right away.. if I don't I have to wait about 45 seconds and then stuff starts spitting out.. I think because I don't see that much traffic on my home network. On Linux I have to do some defensive coding.. as you often can't get immediate mode... try:
self.pcap = pcap.pcap(name=self.iface_name, promisc=True, immediate=True)
except OSError:
try:
logging.warning('Could not get immediate mode, turning flag off')
self.pcap = pcap.pcap(name=self.iface_name, promisc=True, immediate=False) The above code is pulled from https://github.com/SuperCowPowers/chains |
@brifordwylie 3ks for answer On Linux, if set immediate=False, pcap.loop() will exit if there is no packet in a few seconds, so i must restart pcap.loop(), but this causes packet loss.
Do you have any good idea? Thanks very much. |
@yangbh can you check to see if the fix introduce in PR#15 addresses the issues you had? It will be included inside of a new release of pypcap. |
@hellais yes, it works fine now, thanks very much |
@yangbh excellent. I will make a new release of pypcap today then. |
There's no guarantee that you can set immediate mode after you've opened a capture device; it doesn't work on Linux systems using TPACKET_V3 (which will be the case with newer kernels and newer versions of libpcap). If libpcap has
This works on all UN*Xes, and works on Windows if you have a version of WinPcap/Npcap that supports |
pypcap v1.1.4
in mac osx, if i set immediate=False, can not sniff any packet
if i set immediate=True, my code works right
in linux, if i set immediate=True, it will throws this execption
File "/root/work/pytscan/pytscan/scan.py", line 735, in pypcapParse
pc = pcap.pcap(name=self.iface,immediate=True)
File "pcap.pyx", line 210, in pcap.pcap.init (pcap.c:1773)
OSError: couldn't enable immediate mode
thank you, guys
The text was updated successfully, but these errors were encountered: