segevfiner / cypcap

A Cython based Python binding for modern libpcap
https://pypi.org/project/cypcap/
BSD 3-Clause "New" or "Revised" License
14 stars 1 forks source link

Importing cypcap silently exits Python if Npcap is not installed #34

Closed FeldrinH closed 6 months ago

FeldrinH commented 9 months ago

On a Windows 10 machine with cypcap 0.5.0 installed, but Npcap not installed, I tried to execute the following code:

# test.py
print('importing cypcap')
import cypcap
print('cypcap imported')

The result was as follows:

>python test.py
importing cypcap

>echo %errorlevel%
-1066598274

I would have expected to see an error raised, or at least some kind of Python crash or other message indicating that something went wrong, but instead it seems that Python just silently exited with some generic non-zero exit code.

segevfiner commented 9 months ago

Probably the delay load hook throwing an exception, I guess we might be able to use SEH __try in https://github.com/segevfiner/cypcap/blob/a50b9bbf55e96ff29ac9891a97907d2ea48a58d7/cypcap/npcap.pxi and try to convert this to a Python exception so the process won't crash.