Expose packet's HW addr

This commit is contained in:
Yiannis Tsiouris 2016-10-29 00:22:52 +03:00 committed by Yiannis Tsiouris
parent adb254540b
commit b55344e288
3 changed files with 1400 additions and 1300 deletions

File diff suppressed because it is too large Load Diff

View File

@ -170,6 +170,7 @@ cdef class Packet:
cdef nfq_q_handle *_qh
cdef nfq_data *_nfa
cdef nfqnl_msg_packet_hdr *_hdr
cdef nfqnl_msg_packet_hw *_hw
cdef bint _verdict_is_set # True if verdict has been issued,
# false otherwise
cdef bint _mark_is_set # True if a mark has been given, false otherwise
@ -186,6 +187,8 @@ cdef class Packet:
cdef Py_ssize_t payload_len
cdef readonly char *payload
cdef timeval timestamp
cdef u_int8_t hw_addr[8]
# TODO: implement these
#cdef u_int8_t hw_addr[8] # A eui64-formatted address?
#cdef readonly u_int32_t nfmark

View File

@ -57,10 +57,12 @@ 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:
@ -97,6 +99,15 @@ cdef class Packet:
self._verdict_is_set = True
def get_hw(self):
"""Return the hardware address as Python string."""
cdef object py_string
if cpython.version.PY_MAJOR_VERSION >= 3:
py_string = PyBytes_FromStringAndSize(<char*>self.hw_addr, 8)
else:
py_string = PyString_FromStringAndSize(<char*>self.hw_addr, 8)
return py_string
def get_payload(self):
"""Return payload as Python string."""
cdef object py_string