karpierz / pcap-ct

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

sendpacket is broken #8

Closed Senator3223 closed 2 years ago

Senator3223 commented 2 years ago

in _pcap.py the sendpacket function is defined as below:

    def sendpacket(self, buf) -> int:
        """Send a raw network packet on the interface."""
        if _pcap.sendpacket(self.__pcap, buf, len(buf)) == -1:
            raise OSError(self.geterr())
        return len(buf)

when i try to send a packet, i receive the following error:

Traceback (most recent call last):
  File ".\sig.py", line 50, in <module>
    for ip in spoofer:
  File "C:\Users\<redacted>\Desktop\sig\sig\spoofer.py", line 78, in __next__
    self.pc.sendpacket(self.arp_poison_victim)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\pcap\_pcap.py", line 312, in sendpacket
    if _pcap.sendpacket(self.__pcap, buf, len(buf)) == -1:
ctypes.ArgumentError: argument 2: <class 'TypeError'>: expected LP_c_ubyte instance instead of bytes

The following fix will resolve the error:

    def sendpacket(self, buf) -> int:
        """Send a raw network packet on the interface."""
        if _pcap.sendpacket(self.__pcap, ct.cast(ct.c_char_p(buf), ct.POINTER(ct.c_ubyte)), len(buf)) == -1:
            raise OSError(self.geterr())
        return len(buf)

can you fix it in your source?

karpierz commented 2 years ago

Ready (also on PyPi). Thank you very much @EvanSonnemans for report and fix :)

Adam