From 4760a91c48a7635264fcdeeec0651dae3bf5ac07 Mon Sep 17 00:00:00 2001 From: dowright Date: Tue, 24 Aug 2021 20:56:24 -0700 Subject: [PATCH] work on new packet --- new_packet.pxd | 18 ++++++++++++------ new_packet.pyx | 4 ++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/new_packet.pxd b/new_packet.pxd index 2ecd7f7..413ac18 100644 --- a/new_packet.pxd +++ b/new_packet.pxd @@ -13,14 +13,14 @@ cdef enum: ENOBUFS = 105 # No buffer space available # cython define -cdef extern from "netinet/ip.h": - struct iphdr: - u_int8_t tos +cdef struct iphdr: + u_int8_t ihl_ver + u_int8_t tos u_int16_t tot_len u_int16_t id u_int16_t frag_off - u_int8_t ttl - u_int8_t protocol + u_int8_t ttl + u_int8_t protocol u_int16_t check u_int32_t saddr u_int32_t daddr @@ -34,7 +34,7 @@ cdef struct tcphdr: u_int8_t th_off - u_int8_t th_flags + u_int8_t th_flags u_int16_t th_win u_int16_t th_sum u_int16_t th_urp @@ -65,6 +65,7 @@ cdef extern from "sys/time.h": struct timeval: time_t tv_sec time_t tv_usec + struct timezone: pass @@ -83,6 +84,7 @@ cdef extern from "libnfnetlink/linux_nfnetlink.h": cdef extern from "libnfnetlink/libnfnetlink.h": struct nfnl_handle: pass + unsigned int nfnl_rcvbufsiz(nfnl_handle *h, unsigned int size) cdef extern from "libnetfilter_queue/linux_nfnetlink_queue.h": @@ -90,6 +92,7 @@ cdef extern from "libnetfilter_queue/linux_nfnetlink_queue.h": NFQNL_COPY_NONE NFQNL_COPY_META NFQNL_COPY_PACKET + struct nfqnl_msg_packet_hdr: u_int32_t packet_id u_int16_t hw_protocol @@ -98,10 +101,13 @@ cdef extern from "libnetfilter_queue/linux_nfnetlink_queue.h": cdef extern from "libnetfilter_queue/libnetfilter_queue.h": struct nfq_handle: pass + struct nfq_q_handle: pass + struct nfq_data: pass + struct nfqnl_msg_packet_hw: u_int8_t hw_addr[8] diff --git a/new_packet.pyx b/new_packet.pyx index 6dd086a..0da96f3 100644 --- a/new_packet.pyx +++ b/new_packet.pyx @@ -151,6 +151,7 @@ cdef class CPacket: cdef tuple ip_header ip_header = ( + self.ip_header.ihl_ver, self.ip_header.tos, ntohs(self.ip_header.tot_len), ntohs(self.ip_header.id), @@ -200,6 +201,9 @@ cdef class CPacket: self.icmp_header.type, ) + else: + proto_header = () + return proto_header def get_payload(self):