karpierz / pcap-ct

Python wrapper for the pcap library.
BSD 3-Clause "New" or "Revised" License
19 stars 4 forks source link

Are SIGINTs from python passed to Cpyhton? #4

Closed gil-obradors closed 3 years ago

gil-obradors commented 3 years ago

I think that I can't start capturing because the signals aren't passed.

Can be?

import pcap

sniffer = pcap.pcap(name=None, promisc=True, immediate=True, timeout_ms=50)
addr = lambda pkt, offset: '.'.join(str(ord(pkt[i])) for i in range(offset, offset + 4))
for ts, pkt in sniffer:
    print('%d\tSRC %-16s\tDST %-16s' % (ts, addr(pkt, sniffer.dloff + 12),
                                        addr(pkt, sniffer.dloff + 16)))

the error:

runfile('/home/gil/PycharmProjects/netdiscover/main.py', wdir='/home/gil/PycharmProjects/netdiscover')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/snap/pycharm-professional/230/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/snap/pycharm-professional/230/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/gil/PycharmProjects/netdiscover/main.py", line 7, in <module>
    for ts, pkt in sniffer:
  File "/home/gil/PycharmProjects/netdiscover/venv/lib/python3.8/site-packages/pcap/_pcap.py", line 375, in __iter__
    _pcap_ex.setup(self.__pcap)
  File "/home/gil/PycharmProjects/netdiscover/venv/lib/python3.8/site-packages/pcap/_pcap_ex.py", line 132, in setup
    libc.signal(SIGINT, __signal_handler)
NameError: name 'SIGINT' is not defined

From here? https://github.com/karpierz/pcap-ct/blob/60528e71bf2313bc76715e433db1a32dd4327706/src/pcap/_pcap_ex.py#L132

karpierz commented 3 years ago

Forgive me. This module has never been tested in anything other than Windows :( Just fixed (on master branch), but without any tests.

gil-obradors commented 3 years ago

Nothing to forgive, the other way around, thank you very much !

Can I help with something? I want to learn this type of coding, between python and C. I think I can do this tests, but I need some guidance...

Again thank you!

karpierz commented 3 years ago

:Can I help with something?

Yes. Ev. (in the near future) in test on Linux Thank you very much