summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2023-11-16 11:17:18 +0800
committerluwenpeng <[email protected]>2023-11-16 11:26:57 +0800
commit83f9880ff0dcad18bb96a6a3587e5cd3782e4b93 (patch)
treecab7b7d90d7a461805a67e1374b302ae2d9ff123
parent96011379371d6b0a49cbc1642b621c8e126047b5 (diff)
使用自定义的udp_hdr兼容不同的编译环境v1.2.2-20231116
-rw-r--r--common/src/packet.cpp20
1 files 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 <stdlib.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
+#define __FAVOR_BSD 1
#include <netinet/tcp.h>
-#include <netinet/udp.h>
#include <netinet/ether.h>
#include <linux/ppp_defs.h>
@@ -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))
{