To fix #25, only parse self._hw.hw_addr if self._hw is not NULL

This commit is contained in:
Matt Fox 2017-01-30 23:36:46 -08:00
parent 24e6ab5d5a
commit 1a9815fdfd
3 changed files with 505 additions and 468 deletions

View File

@ -3,6 +3,9 @@ from netfilterqueue import NetfilterQueue
def print_and_accept(pkt):
print(pkt)
hw = pkt.get_hw()
if hw:
print(":".join("{:02x}".format(ord(c)) for c in hw[0:6]))
pkt.accept()
nfqueue = NetfilterQueue()

File diff suppressed because it is too large Load Diff

View File

@ -57,12 +57,10 @@ cdef class Packet:
self._qh = qh
self._nfa = nfa
self._hdr = nfq_get_msg_packet_hdr(nfa)
self._hw = nfq_get_packet_hw(nfa)
self.id = ntohl(self._hdr.packet_id)
self.hw_protocol = ntohs(self._hdr.hw_protocol)
self.hook = self._hdr.hook
self.hw_addr = self._hw.hw_addr
self.payload_len = nfq_get_payload(self._nfa, &self.payload)
if self.payload_len < 0:
@ -101,6 +99,11 @@ cdef class Packet:
def get_hw(self):
"""Return the hardware address as Python string."""
self._hw = nfq_get_packet_hw(self._nfa)
if self._hw == NULL:
# nfq_get_packet_hw doesn't work on OUTPUT and PREROUTING chains
return None
self.hw_addr = self._hw.hw_addr
cdef object py_string
if cpython.version.PY_MAJOR_VERSION >= 3:
py_string = PyBytes_FromStringAndSize(<char*>self.hw_addr, 8)