small unittest fixes to decode-raw.c

remotes/origin/master-1.0.x
William Metcalf 16 years ago committed by Victor Julien
parent 8a64321340
commit c5d0b492d3

@ -36,6 +36,9 @@ void DecodeRaw(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
}
#ifdef UNITTESTS
#include "flow.h"
#include "flow-util.h"
/** DecodeRawtest01
* \brief Valid Raw packet
* \retval 0 Expected test value
@ -44,17 +47,16 @@ static int DecodeRawTest01 (void) {
/* IPV6/TCP/no eth header */
uint8_t raw_ip[] = {
0xff, 0x00, 0xac, 0x83, 0xfd, 0xcf, 0xea, 0x6a,
0x24, 0xfb, 0x91, 0xff, 0x00, 0xbd, 0x45, 0x14,
0xca, 0x8f, 0x51, 0xf7, 0x1f, 0xeb, 0x6e, 0x3f,
0xdf, 0x3f, 0xd2, 0x9d, 0x65, 0xfe, 0xbd, 0x7f,
0xeb, 0x89, 0xff, 0x00, 0xd0, 0x4d, 0x14, 0x54,
0xad, 0x83, 0xa9, 0x0f, 0x65, 0xfa, 0xd2, 0x93,
0xfb, 0x8b, 0x9f, 0xaa, 0xff, 0x00, 0xec, 0xd4,
0x51, 0x43, 0x1a, 0x12, 0x4f, 0xf5, 0xaf, 0xff,
0x00, 0x5c, 0xea, 0x2a, 0x28, 0xa6, 0x89, 0x67,
0xff, 0xd9 };
0x60, 0x00, 0x00, 0x00, 0x00, 0x28, 0x06, 0x40,
0x20, 0x01, 0x06, 0x18, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x51, 0x99, 0xcc, 0x70,
0x20, 0x01, 0x06, 0x18, 0x00, 0x01, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
0x8c, 0x9b, 0x00, 0x50, 0x6a, 0xe7, 0x07, 0x36,
0x00, 0x00, 0x00, 0x00, 0xa0, 0x02, 0x16, 0x30,
0x29, 0x9c, 0x00, 0x00, 0x02, 0x04, 0x05, 0x8c,
0x04, 0x02, 0x08, 0x0a, 0x00, 0xdd, 0x1a, 0x39,
0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x02 };
Packet p;
ThreadVars tv;
DecodeThreadVars dtv;
@ -63,13 +65,18 @@ static int DecodeRawTest01 (void) {
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, sizeof(Packet));
DecodeRaw(&tv, &dtv, &p, raw_ip, sizeof(raw_ip), NULL);
p.pktlen = sizeof(raw_ip);
memcpy(p.pkt, raw_ip, p.pktlen);
FlowInitConfig(FLOW_QUIET);
DecodeRaw(&tv, &dtv, &p, raw_ip, p.pktlen, NULL);
if (p.ip6h == NULL) {
printf("expected a valid ipv6 header but it was NULL");
return 0;
return 1;
}
return 1;
return 0;
}
/** DecodeRawtest02
@ -80,16 +87,12 @@ static int DecodeRawTest02 (void) {
/* IPV4/TCP/no eth header */
uint8_t raw_ip[] = {
0x47, 0x45, 0x54, 0x20, 0x2f, 0x2f, 0x72, 0x6f,
0x75, 0x6e, 0x64, 0x31, 0x37, 0x39, 0x2e, 0x78,
0x6d, 0x6c, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f,
0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x43, 0x6f, 0x6e,
0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a,
0x20, 0x4b, 0x65, 0x65, 0x70, 0x2d, 0x41, 0x6c,
0x69, 0x76, 0x65, 0x0d, 0x0a, 0x48, 0x6f, 0x73,
0x74, 0x3a, 0x20, 0x31, 0x39, 0x32, 0x2e, 0x31,
0x36, 0x38, 0x2e, 0x31, 0x30, 0x32, 0x2e, 0x32,
0x0d, 0x0a, 0x0d, 0x0a };
0x45, 0x00, 0x00, 0x30, 0x00, 0xad, 0x40, 0x00,
0x7f, 0x06, 0xac, 0xc5, 0xc0, 0xa8, 0x67, 0x02,
0xc0, 0xa8, 0x66, 0x02, 0x0b, 0xc7, 0x00, 0x50,
0x1d, 0xb3, 0x12, 0x37, 0x00, 0x00, 0x00, 0x00,
0x70, 0x02, 0x40, 0x00, 0xb8, 0xc8, 0x00, 0x00,
0x02, 0x04, 0x05, 0xb4, 0x01, 0x01, 0x04, 0x02 };
Packet p;
ThreadVars tv;
@ -99,13 +102,18 @@ static int DecodeRawTest02 (void) {
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, sizeof(Packet));
DecodeRaw(&tv, &dtv, &p, raw_ip, sizeof(raw_ip), NULL);
p.pktlen = sizeof(raw_ip);
memcpy(p.pkt, raw_ip, p.pktlen);
FlowInitConfig(FLOW_QUIET);
DecodeRaw(&tv, &dtv, &p, raw_ip, p.pktlen, NULL);
if (p.ip4h == NULL) {
printf("expected a valid ipv4 header but it was NULL");
return 0;
return 1;
}
return 1;
return 0;
}
/** DecodeRawtest03
* \brief Valid Raw packet
@ -132,7 +140,12 @@ static int DecodeRawTest03 (void) {
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, sizeof(Packet));
DecodeRaw(&tv, &dtv, &p, raw_ip, sizeof(raw_ip), NULL);
p.pktlen = sizeof(raw_ip);
memcpy(p.pkt, raw_ip, p.pktlen);
FlowInitConfig(FLOW_QUIET);
DecodeRaw(&tv, &dtv, &p, raw_ip, p.pktlen, NULL);
if (DECODER_ISSET_EVENT(&p,IPRAW_INVALID_IPV)) {
return 0;
} else {

Loading…
Cancel
Save