ref: e7d315db2f32145030007b4d9431e5aa128f8f16
dir: /udp.c/
#include <stdio.h>
#include <stdint.h>
#include <pcap.h>
#include "common.h"
int
parseUdp(const u_char *pkt, Udp *udp)
{
int pos = 0;
udp->srcport = get2(pkt + pos);
pos += UDP_SRCPORT;
udp->dstport = get2(pkt + pos);
pos += UDP_DSTPORT;
udp->len = get2(pkt + pos);
pos += UDP_LEN;
udp->sum = get2(pkt + pos);
pos += UDP_SUM;
return 1;
}
void
printUdp(Udp udp)
{
printf("udp pkt:\n"
"\tsrcport: %d\tdstport: %d\n"
"\tlen: %d\tsum 0x%x\n",
udp.srcport, udp.dstport, udp.len, udp.sum);
}
Parser udpParser = {
.parse = parseUdp,
.print = printDns,
};