TSG-7784 PacketAdapter支持CI自动构建RPM; 修改代码结构
This commit is contained in:
48
common/src/decode_udp.c
Normal file
48
common/src/decode_udp.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "decode_udp.h"
|
||||
|
||||
#define UDP_GET_LEN(udp_hdr) ((uint16_t)ntohs((udp_hdr)->udp_len))
|
||||
#define UDP_GET_SRC_PORT(udp_hdr) ((uint16_t)ntohs((udp_hdr)->udp_src_port))
|
||||
#define UDP_GET_DST_PORT(udp_hdr) ((uint16_t)ntohs((udp_hdr)->udp_dst_port))
|
||||
|
||||
int decode_udp(udp_info_t *packet, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
if (len < UDP_HEADER_LEN)
|
||||
{
|
||||
LOG_ERROR("Parser UDP Header: packet length too small %d", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
packet->hdr = (udp_header_t *)data;
|
||||
// 检查 UDP header len
|
||||
if (len < UDP_GET_LEN(packet->hdr))
|
||||
{
|
||||
LOG_ERROR("Parser UDP Header: UDP packet too small %d", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 检查 UDP header len
|
||||
if (len != UDP_GET_LEN(packet->hdr))
|
||||
{
|
||||
LOG_ERROR("Parser UDP Header: invalid UDP header length %d", UDP_GET_LEN(packet->hdr));
|
||||
return -1;
|
||||
}
|
||||
|
||||
packet->src_port = UDP_GET_SRC_PORT(packet->hdr);
|
||||
packet->dst_port = UDP_GET_DST_PORT(packet->hdr);
|
||||
|
||||
packet->hdr_len = UDP_HEADER_LEN;
|
||||
packet->payload = (uint8_t *)data + UDP_HEADER_LEN;
|
||||
packet->payload_len = len - UDP_HEADER_LEN;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dump_udp_info(uint32_t pkt_id, udp_info_t *packet)
|
||||
{
|
||||
LOG_DEBUG("id: %u, udp_info: {src_port: %u, dst_port: %u, hdr_len: %u, data_len: %u}",
|
||||
pkt_id,
|
||||
packet->src_port,
|
||||
packet->dst_port,
|
||||
packet->hdr_len,
|
||||
packet->payload_len);
|
||||
}
|
||||
Reference in New Issue
Block a user