21 lines
685 B
C
21 lines
685 B
C
#include <stdbool.h>
|
|
#include "udp_packet.h"
|
|
#include "etherlib/utils.h"
|
|
|
|
#define ETH_UDP_HEADER_SIZE (8)
|
|
|
|
int parse_udp(const uint8_t *hdr, uint32_t size, PcktProps * props) {
|
|
UDPProps * udpProps = (UDPProps *)props;
|
|
COPY_WORD_H2N_ADVANCE(&udpProps->SourcePort, hdr);
|
|
COPY_WORD_H2N_ADVANCE(&udpProps->DestinationPort, hdr);
|
|
COPY_WORD_H2N_ADVANCE(&udpProps->Length, hdr);
|
|
COPY_WORD_H2N_ADVANCE(&udpProps->Checksum, hdr);
|
|
|
|
// common fields...
|
|
udpProps->headerSize = ETH_UDP_HEADER_SIZE;
|
|
udpProps->validityOK = size == udpProps->Length; // TODO UDP checksum validation!
|
|
udpProps->containedPacketClass = 0;
|
|
|
|
return udpProps->validityOK ? 0 : -1;
|
|
}
|