You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
suricata/src/decode-udp.c

60 lines
1.3 KiB
C

/* Copyright (c) 2008 Victor Julien <victor@inliniac.net> */
#include "eidps-common.h"
#include "decode.h"
#include "decode-udp.h"
#include "decode-events.h"
17 years ago
#include "flow.h"
static int DecodeUDPPacket(ThreadVars *t, Packet *p, uint8_t *pkt, uint16_t len)
{
p->udph = (UDPHdr *)pkt;
if (len < UDP_GET_LEN(p)) {
DECODER_SET_EVENT(p, UDP_PKT_TOO_SMALL);
return -1;
}
if (len < UDP_HEADER_LEN) {
DECODER_SET_EVENT(p, UDP_HLEN_TOO_SMALL);
return -1;
}
if (len != UDP_GET_LEN(p)) {
DECODER_SET_EVENT(p, UDP_HLEN_INVALID);
return -1;
}
SET_UDP_SRC_PORT(p,&p->sp);
SET_UDP_DST_PORT(p,&p->dp);
p->payload = pkt + UDP_HEADER_LEN;
p->payload_len = len - UDP_HEADER_LEN;
p->proto = IPPROTO_UDP;
return 0;
}
void DecodeUDP(ThreadVars *t, Packet *p, uint8_t *pkt, uint16_t len)
{
PerfCounterIncr(COUNTER_DECODER_UDP, t->pca);
if (DecodeUDPPacket(t, p,pkt,len) < 0)
return;
#ifdef DEBUG
/** \todo XXX This has only 4 args for 5 formatters??? */
#if 0
printf("UDP sp: %" PRIu32 " -> dp: %" PRIu32 " - HLEN: %" PRIu32 " LEN: %" PRIu32 " TEST: %" PRIu32 "\n",
UDP_GET_SRC_PORT(p), UDP_GET_DST_PORT(p), UDP_HEADER_LEN, p->payload_len);
#endif
#endif
17 years ago
/* Flow is an integral part of us */
FlowHandlePacket(t, p);
return;
}