使用自定义的udp_hdr兼容不同的编译环境
This commit is contained in:
@@ -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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user