OSError: [WinError 127] The specified procedure could not be found.
joveice opened this issue · comments
with pydivert.WinDivert("tcp.DstPort == 80 and tcp.PayloadLength > 0") as w:
for packet in w:
print(packet.src_addr)
w.send(packet)
Error:
Traceback (most recent call last):
File "tester.py", line 7, in <module>
w.send(packet)
File "pydivert\windivert.py", line 227, in send
packet.recalculate_checksums()
File "pydivert\packet\__init__.py", line 308, in recalculate_checksums
num = windivert_dll.WinDivertHelperCalcChecksums(ctypes.byref(buff_), len(self.raw), flags)
File "pydivert\windivert_dll\__init__.py", line 54, in wrapper
raise err
OSError: [WinError 127] The specified procedure could not be found.
Whats this? Why can't I get the IP?
Turns out, I get the IP but I can't send it again unless I do w.send(packet, False) and when I do that the packet doesn't get sendt / ends up somewhere else.
More info. It seems to be different from time to time, sometimes I can print the IP and send it, sometimes I can't print and send it.
I got the same bug
This seems to be due to changes in WinDivert 1.4: https://reqrypt.org/windivert-changelog.txt. The PyPI wheel bundles 1.3, so not sure how you are getting that. Are you installing from source?
Installed from pip and it's including 1.3 not 1.4.
I noticed if you access both src and dst address it works 10 of 10 times.
I found if I call some other function, that could set the LastError. and w.send() calls checksum helper function, which checks it. I tryed windll.kernel32.SetLastError(0) before w.send(). it helped.
I had this problem in this code:
for itm in psutil.net_connections():
if itm.laddr.port == lport: # and itm.laddr.ip == lip:
pname = psutil.Process(itm.pid).name()
print("pkt from process {}".format(pname))
windll.kernel32.SetLastError(0) # this helped
wd.send(pkt)