From e197f5072709958ab24b7f159f64e476012769f1 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Thu, 3 Mar 2011 15:27:21 +0100 Subject: [PATCH] Fix IP-Only unittests failing on Big Endian. --- src/detect.c | 26 +++++++++++++------------- src/util-unittest-helper.c | 14 +++++++++++++- src/util-unittest-helper.h | 2 ++ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/detect.c b/src/detect.c index 2fac62facb..890a27b910 100644 --- a/src/detect.c +++ b/src/detect.c @@ -5359,8 +5359,8 @@ int SigTest19Real (int mpm_type) { memset(p, 0, SIZE_OF_PACKET); p->pkt = (uint8_t *)(p + 1); p->src.family = AF_INET; - p->src.addr_data32[0] = 0x0102080a; - p->dst.addr_data32[0] = 0x04030201; + p->src.addr_data32[0] = UTHSetIPv4Address("192.168.0.1"); + p->dst.addr_data32[0] = UTHSetIPv4Address("1.2.3.4"); p->dst.family = AF_INET; p->payload = buf; p->payload_len = buflen; @@ -5430,8 +5430,8 @@ static int SigTest20Real (int mpm_type) { memset(p, 0, SIZE_OF_PACKET); p->pkt = (uint8_t *)(p + 1); p->src.family = AF_INET; - p->src.addr_data32[0] = 0x0102080a; - p->dst.addr_data32[0] = 0x04030201; + p->src.addr_data32[0] = UTHSetIPv4Address("192.168.0.1"); + p->dst.addr_data32[0] = UTHSetIPv4Address("1.2.3.4"); p->dst.family = AF_INET; p->payload = buf; p->payload_len = buflen; @@ -8013,8 +8013,8 @@ int SigTest40NoPacketInspection01(void) { memset(&tcphdr, 0, sizeof(tcphdr)); p->src.family = AF_INET; - p->src.addr_data32[0] = 0x0102080a; - p->dst.addr_data32[0] = 0x04030201; + p->src.addr_data32[0] = UTHSetIPv4Address("192.168.0.1"); + p->dst.addr_data32[0] = UTHSetIPv4Address("1.2.3.4"); p->dst.family = AF_INET; p->payload = buf; p->payload_len = buflen; @@ -8619,7 +8619,7 @@ static int SigTestSgh03 (void) { p->payload_len = 1; p->proto = IPPROTO_TCP; p->dp = 80; - p->dst.addr_data32[0] = 0x04030201; + p->dst.addr_data32[0] = UTHSetIPv4Address("1.2.3.4"); DetectEngineCtx *de_ctx = DetectEngineCtxInit(); if (de_ctx == NULL) { @@ -8696,7 +8696,7 @@ static int SigTestSgh03 (void) { goto end; } - p->dst.addr_data32[0] = 0x05030201; + p->dst.addr_data32[0] = UTHSetIPv4Address("1.2.3.5"); sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p); if (sgh == NULL) { @@ -8735,7 +8735,7 @@ static int SigTestSgh03 (void) { } - p->dst.addr_data32[0] = 0x06030201; + p->dst.addr_data32[0] = UTHSetIPv4Address("1.2.3.6"); sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p); if (sgh == NULL) { @@ -8791,7 +8791,7 @@ static int SigTestSgh04 (void) { p->payload_len = 1; p->proto = IPPROTO_TCP; p->dp = 80; - p->dst.addr_data32[0] = 0x04030201; + p->dst.addr_data32[0] = UTHSetIPv4Address("1.2.3.4"); DetectEngineCtx *de_ctx = DetectEngineCtxInit(); if (de_ctx == NULL) { @@ -8867,7 +8867,7 @@ static int SigTestSgh04 (void) { printf("sgh->sig_size %u\n", sgh->sig_size); printf("sgh->refcnt %u\n", sgh->refcnt); #endif - p->dst.addr_data32[0] = 0x05030201; + p->dst.addr_data32[0] = UTHSetIPv4Address("1.2.3.5"); sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p); if (sgh == NULL) { @@ -8903,7 +8903,7 @@ static int SigTestSgh04 (void) { printf("sgh->sig_size %u\n", sgh->sig_size); printf("sgh->refcnt %u\n", sgh->refcnt); #endif - p->dst.addr_data32[0] = 0x06030201; + p->dst.addr_data32[0] = UTHSetIPv4Address("1.2.3.6"); sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p); if (sgh == NULL) { @@ -8984,7 +8984,7 @@ static int SigTestSgh05 (void) { p->payload_len = 1; p->proto = IPPROTO_TCP; p->dp = 80; - p->dst.addr_data32[0] = 0x04030201; + p->dst.addr_data32[0] = UTHSetIPv4Address("1.2.3.4"); DetectEngineCtx *de_ctx = DetectEngineCtxInit(); if (de_ctx == NULL) { diff --git a/src/util-unittest-helper.c b/src/util-unittest-helper.c index 7906a056b8..f2ac57ce52 100644 --- a/src/util-unittest-helper.c +++ b/src/util-unittest-helper.c @@ -27,7 +27,6 @@ #include "suricata-common.h" #include - #include "decode.h" #include "flow-private.h" @@ -43,6 +42,19 @@ #include "util-unittest.h" #include "util-unittest-helper.h" +/** + * \brief return the uint32_t for a ipv4 address string + * + * \param str Valid ipaddress in string form (e.g. 1.2.3.4) + * + * \retval uint the uin32_t representation + */ +uint32_t UTHSetIPv4Address(char *str) { + struct in_addr in; + inet_pton(AF_INET, str, &in); + return (uint32_t)in.s_addr; +} + /** * \brief UTHBuildPacketReal is a function that create tcp/udp packets for unittests * specifying ip and port sources and destinations (IPV6) diff --git a/src/util-unittest-helper.h b/src/util-unittest-helper.h index 1dfb6b7a59..241a89d458 100644 --- a/src/util-unittest-helper.h +++ b/src/util-unittest-helper.h @@ -24,6 +24,8 @@ #ifndef __UTIL_UNITTEST_HELPER__ #define __UTIL_UNITTEST_HELPER__ +uint32_t UTHSetIPv4Address(char *); + Packet *UTHBuildPacketReal(uint8_t *, uint16_t, uint16_t, char *, char *, uint16_t, uint16_t); Packet *UTHBuildPacket(uint8_t *, uint16_t, uint16_t); Packet *UTHBuildPacketSrcDst(uint8_t *, uint16_t, uint16_t, char *, char *);