From 83f9880ff0dcad18bb96a6a3587e5cd3782e4b93 Mon Sep 17 00:00:00 2001 From: luwenpeng Date: Thu, 16 Nov 2023 11:17:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E7=9A=84udp=5Fhdr=E5=85=BC=E5=AE=B9=E4=B8=8D=E5=90=8C=E7=9A=84?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/src/packet.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/common/src/packet.cpp b/common/src/packet.cpp index 424cefe..84dc5b0 100644 --- a/common/src/packet.cpp +++ b/common/src/packet.cpp @@ -2,8 +2,8 @@ #include #include #include +#define __FAVOR_BSD 1 #include -#include #include #include @@ -26,6 +26,14 @@ LOG_PACKET, (tag), (next_proto)); \ } +struct udp_hdr +{ + uint16_t uh_sport; /* source port */ + uint16_t uh_dport; /* destination port */ + uint16_t uh_ulen; /* udp length */ + uint16_t uh_sum; /* udp checksum */ +} __attribute__((__packed__)); + /****************************************************************************** * Static API ******************************************************************************/ @@ -341,7 +349,7 @@ static inline void set_four_tuple(const char *data, enum layer_type type, struct const struct ip *ipv4 = NULL; const struct ip6_hdr *ipv6 = NULL; const struct tcphdr *tcp = NULL; - const struct udphdr *udp = NULL; + const struct udp_hdr *udp = NULL; switch (type) { @@ -350,7 +358,7 @@ static inline void set_four_tuple(const char *data, enum layer_type type, struct four_tuple_set_port(tuple, tcp->th_sport, tcp->th_dport); break; case LAYER_TYPE_UDP: - udp = (const struct udphdr *)data; + udp = (const struct udp_hdr *)data; four_tuple_set_port(tuple, udp->uh_sport, udp->uh_dport); break; case LAYER_TYPE_IPV4: @@ -848,7 +856,7 @@ static inline const char *parse_gre(struct packet *handler, const char *data, ui static inline const char *parse_udp(struct packet *handler, const char *data, uint16_t len) { - if (unlikely(len < sizeof(struct udphdr))) + if (unlikely(len < sizeof(struct udp_hdr))) { PACKET_LOG_DATA_INSUFFICIENCY(LAYER_TYPE_UDP); return data; @@ -859,8 +867,8 @@ static inline const char *parse_udp(struct packet *handler, const char *data, ui { return data; } - struct udphdr *hdr = (struct udphdr *)data; - SET_LAYER(handler, layer, LAYER_TYPE_UDP, sizeof(struct udphdr), data, len); + struct udp_hdr *hdr = (struct udp_hdr *)data; + SET_LAYER(handler, layer, LAYER_TYPE_UDP, sizeof(struct udp_hdr), data, len); switch (ntohs(hdr->uh_dport)) {