使用自定义的udp_hdr替换linux的udphdr

This commit is contained in:
luwenpeng
2023-02-17 17:53:21 +08:00
parent 0ba7fefba5
commit 551abde887
6 changed files with 33 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
#include <netinet/udp.h>
#include <netinet/ip.h>
#include <netinet/ether.h>
#include "utils.h"
#include "g_vxlan.h"
void g_vxlan_set_packet_dir(struct g_vxlan *hdr, int dir_is_e2i)
@@ -38,7 +38,7 @@ int g_vxlan_get_traffic_type(struct g_vxlan *hdr)
// return -1 : error
int g_vxlan_decode(struct g_vxlan **g_vxlan_hdr, const char *raw_data, int raw_len)
{
if (raw_len <= (int)(sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udphdr) + sizeof(struct g_vxlan)))
if (raw_len <= (int)(sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udp_hdr) + sizeof(struct g_vxlan)))
{
return -1;
}
@@ -55,13 +55,13 @@ int g_vxlan_decode(struct g_vxlan **g_vxlan_hdr, const char *raw_data, int raw_l
return -1;
}
struct udphdr *udp_hdr = (struct udphdr *)((char *)ip_hdr + sizeof(struct ip));
struct udp_hdr *udp_hdr = (struct udp_hdr *)((char *)ip_hdr + sizeof(struct ip));
if (udp_hdr->uh_dport != htons(4789))
{
return -1;
}
*g_vxlan_hdr = (struct g_vxlan *)((char *)udp_hdr + sizeof(struct udphdr));
*g_vxlan_hdr = (struct g_vxlan *)((char *)udp_hdr + sizeof(struct udp_hdr));
return 0;
}