pynetwork / pypcap

pypcap - python libpcap module, forked from code.google.com/p/pypcap
Other
299 stars 75 forks source link

Windows 10 : call to `__next__()` leads to a Memory Error and `loop()` leads to kernel crash [closed] #97

Closed python-villon closed 4 years ago

python-villon commented 4 years ago

Hello,

When using a pypcap script on a RaspberryPi unit I have no problem (Thanks for the work !) and I can capture Ethernet frames. But on Windows 10 machine, a call to the __next__() method leads me to a Memory Error (with a mention to the buffer). [I should here tell that very few times the first call to __next__() method works fine but the second fails]. I read many posts here, I wonder if it's a big vs little endian problem or a misunderstanding of the access to the buffer that should be flushed. However my programming skills are not sufficient to investigate furthermore. Help would be appreciated.

This piece of code works fine :

interface_name = '\\Device\\NPF_{9303466E-F849-4980-8C88-9BF9B5064A37}'
pc = pcap.pcap(name = interface_name, immediate=True, timeout_ms = 50)

But a call to __next__() leads to a Memory error :

x = pc.__next__()

Hope I'm not wasting your time ...

python-villon commented 4 years ago

I believe I don't use the :

for timestamp, packet in pc:

as I should since the dispatch metchod works fine.

I've just found the pyx file (it's the first time I install a package via setup.py so I couldn't find the module) so I'm going to investigate furthermore. I deeply apologize for the time you would lost.

Thanks

python-villon commented 4 years ago

Furthermore exploration leads to :

import pcap
import time

interface_name = '\\Device\\NPF_{9303466E-F849-4980-8C88-9BF9B5064A37}'
my_list = []

def my_callback(ts, packet, some_list):
    some_list.append('baz')

pc = pcap.pcap(name = interface_name, immediate=True, timeout_ms = 50)

time.sleep(0.2)

pc.loop(20, my_callback, my_list)

works fine.

But if I remove the time.sleep(0.2) instruction, the kernel crashes. Also, the use of dispatch function works fine in every case, even with cnt = -1 and no 'time.sleep(0.2)'.