work on new packet

This commit is contained in:
dowright 2021-08-23 21:53:54 -07:00 committed by DOWRIGHT
parent f0f68aff24
commit 532f2a43b5
2 changed files with 7 additions and 12 deletions

View File

@ -193,5 +193,5 @@ cdef class CPacket:
cdef int nf_callback(self, nfq_q_handle *qh, nfgenmsg *nfmsg, nfq_data *nfa, void *data)
cdef parse(self, nfq_q_handle *qh, nfq_data *nfa) nogil
cdef _parse(self, unsigned char *data)
cdef _parse(self, unsigned char **data)
cdef void verdict(self, u_int32_t verdict)

View File

@ -79,7 +79,7 @@ cdef class CPacket:
self._mark = nfq_get_nfmark(nfa)
# splitting packet by tcp/ip layers
self._parse(data)
self._parse(&data)
# if (self.continue_condition):
# self._before_exit()
@ -88,7 +88,7 @@ cdef class CPacket:
# with gil:
# callback(self)
cdef _parse(self, unsigned char *data):
cdef _parse(self, unsigned char **data):
'''Index tcp/ip packet layers 3 & 4 for use as instance objects.
the before_exit method will be called before returning, which can be used to create
subclass specific objects like namedtuples or application layer data.'''
@ -101,23 +101,18 @@ cdef class CPacket:
cdef udphdr *udp_header
cdef icmphdr *icmp_header
self.ip_header = ip_header
if (ip_header.protocol == IPPROTO_TCP):
tcp_header[0] = <tcphdr*>data[iphdr_len:]
self.tcp_header = tcp_header
self.tcp_header = <tcphdr*>data[iphdr_len:]
if (ip_header.protocol == IPPROTO_UDP):
udp_header[0] = <udphdr*>data[iphdr_len:]
self.udp_header = udp_header
self.udp_header = <udphdr*>data[iphdr_len:]
if (ip_header.protocol == IPPROTO_ICMP):
icmp_header[0] = <icmphdr*>data[iphdr_len:]
self.icmp_header = icmp_header
self.icmp_header = <icmphdr*>data[iphdr_len:]
cdef void verdict(self, u_int32_t verdict):
'''Call appropriate set_verdict... function on packet.'''