ffalcinelli / pydivert

A Python binding for WinDivert driver
GNU Lesser General Public License v3.0
200 stars 36 forks source link

OSError: [WinError 87] for inbound packet #42

Open ly3too opened 5 years ago

ly3too commented 5 years ago

I got a lot of WinError 87 exceptions for this code in windows 10. any one could help me please?

with pydivert.WinDivert("inbound and ip") as wd:
        for pkt in wd:
            wd.send(pkt)

Traceback (most recent call last): File "C:/cygwin64/code/python/pydivert_reset/test_pydivert.py", line 78, in wd.send(pkt) File "C:\Python37\lib\site-packages\pydivert\windivert.py", line 237, in send byref(send_len)) File "C:\Python37\lib\site-packages\pydivert\windivert_dll__init__.py", line 54, in wrapper raise err

Protowalker commented 5 years ago

I got this error a lot and found out that it was an issue with my filter. I would check there first.

majibow commented 5 years ago

The error is created by packets with larger than the DEFAULT_PACKET_BUFFER_SIZE=1500.

Example receiving some fragments that get reassembled into a large packet. Or trying to send a packet that will fragment. (if you put 'outbound' in your filter) ping -l 1600 google.com

The maximum packet size for IPv4 is 65535 and for IPv6 is 65535+40.

You could change the constant I mentioned above to 65575 and be safe for ever in the file C:\Program Files\Python36\Lib\site-packages\pydivert\windivert.py

Or you could add to your filter "((ip and ip.Length<=1500) or (ipv6 and ipv6.Length<=1500))".

Or instead of using the for loop iterator you could use the .recv() method just pass it a large enough buffer size. 5000 is probably fine and 65575 would be the maximum needed as i said before.