From 3ec5f6672986d520d37300d9b5d382c7a6bff815 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 5 Aug 2008 00:09:36 +0200 Subject: [PATCH] Fix some address code related compiler warnings. --- src/detect-address-ipv4.c | 7 +--- src/detect-address-ipv6.c | 88 +++++++++++++++++++-------------------- src/detect-address.h | 5 +++ 3 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/detect-address-ipv4.c b/src/detect-address-ipv4.c index 39c702b342..61bce8bfdc 100644 --- a/src/detect-address-ipv4.c +++ b/src/detect-address-ipv4.c @@ -47,11 +47,6 @@ int AddressCmpIPv4(DetectAddressData *a, DetectAddressData *b) { printf("Internal Error: should be unreachable\n"); } - printf("a->ip[0] %u, a->ip2[0] %u\n", ntohl(a->ip[0]), ntohl(a->ip2[0])); - DetectAddressDataPrint(a); - printf("b->ip[0] %u, b->ip2[0] %u\n", ntohl(b->ip[0]), ntohl(b->ip2[0])); - DetectAddressDataPrint(b); - printf ("ADDRESS_ER\n"); return ADDRESS_ER; } @@ -76,7 +71,7 @@ int AddressCutIPv4(DetectAddressData *a, DetectAddressData *b, DetectAddressData /* default to NULL */ *c = NULL; - int r = AddressCmp(a,b); + int r = AddressCmpIPv4(a,b); if (r != ADDRESS_ES && r != ADDRESS_EB && r != ADDRESS_LE && r != ADDRESS_GE) { goto error; } diff --git a/src/detect-address-ipv6.c b/src/detect-address-ipv6.c index 906bc5ea52..38d410d067 100644 --- a/src/detect-address-ipv6.c +++ b/src/detect-address-ipv6.c @@ -75,6 +75,49 @@ int AddressIPv6Ge(u_int32_t *a, u_int32_t *b) { return 0; } +int AddressCmpIPv6(DetectAddressData *a, DetectAddressData *b) { + /* ADDRESS_EQ */ + if (AddressIPv6Eq(a->ip, b->ip) == 1 && + AddressIPv6Eq(a->ip2, b->ip2) == 1) { + //printf("ADDRESS_EQ\n"); + return ADDRESS_EQ; + /* ADDRESS_ES */ + } else if (AddressIPv6Ge(a->ip, b->ip) == 1 && + AddressIPv6Lt(a->ip, b->ip2) == 1 && + AddressIPv6Le(a->ip2, b->ip2) == 1) { + //printf("ADDRESS_ES\n"); + return ADDRESS_ES; + /* ADDRESS_EB */ + } else if (AddressIPv6Le(a->ip, b->ip) == 1 && + AddressIPv6Ge(a->ip2, b->ip2) == 1) { + //printf("ADDRESS_EB\n"); + return ADDRESS_EB; + } else if (AddressIPv6Lt(a->ip, b->ip) == 1 && + AddressIPv6Lt(a->ip2, b->ip2) == 1 && + AddressIPv6Gt(a->ip2, b->ip) == 1) { + //printf("ADDRESS_LE\n"); + return ADDRESS_LE; + } else if (AddressIPv6Lt(a->ip, b->ip) == 1 && + AddressIPv6Lt(a->ip2, b->ip2) == 1) { + //printf("ADDRESS_LT\n"); + return ADDRESS_LT; + } else if (AddressIPv6Gt(a->ip, b->ip) == 1 && + AddressIPv6Lt(a->ip, b->ip2) == 1 && + AddressIPv6Gt(a->ip2, b->ip2) == 1) { + //printf("ADDRESS_GE\n"); + return ADDRESS_GE; + } else if (AddressIPv6Gt(a->ip, b->ip2) == 1) { + //printf("ADDRESS_GT\n"); + return ADDRESS_GT; + } else { + /* should be unreachable */ + printf("Internal Error: should be unreachable\n"); + } + +// printf ("ADDRESS_ER\n"); + return ADDRESS_ER; +} + /* address is in host order! */ static void AddressCutIPv6CopySubOne(u_int32_t *a, u_int32_t *b) { u_int32_t t = a[3]; @@ -152,7 +195,7 @@ int AddressCutIPv6(DetectAddressData *a, DetectAddressData *b, DetectAddressData /* default to NULL */ *c = NULL; - int r = AddressCmp(a,b); + int r = AddressCmpIPv6(a,b); if (r != ADDRESS_ES && r != ADDRESS_EB && r != ADDRESS_LE && r != ADDRESS_GE) { goto error; } @@ -297,49 +340,6 @@ error: return -1; } -int AddressCmpIPv6(DetectAddressData *a, DetectAddressData *b) { - /* ADDRESS_EQ */ - if (AddressIPv6Eq(a->ip, b->ip) == 1 && - AddressIPv6Eq(a->ip2, b->ip2) == 1) { - //printf("ADDRESS_EQ\n"); - return ADDRESS_EQ; - /* ADDRESS_ES */ - } else if (AddressIPv6Ge(a->ip, b->ip) == 1 && - AddressIPv6Lt(a->ip, b->ip2) == 1 && - AddressIPv6Le(a->ip2, b->ip2) == 1) { - //printf("ADDRESS_ES\n"); - return ADDRESS_ES; - /* ADDRESS_EB */ - } else if (AddressIPv6Le(a->ip, b->ip) == 1 && - AddressIPv6Ge(a->ip2, b->ip2) == 1) { - //printf("ADDRESS_EB\n"); - return ADDRESS_EB; - } else if (AddressIPv6Lt(a->ip, b->ip) == 1 && - AddressIPv6Lt(a->ip2, b->ip2) == 1 && - AddressIPv6Gt(a->ip2, b->ip) == 1) { - //printf("ADDRESS_LE\n"); - return ADDRESS_LE; - } else if (AddressIPv6Lt(a->ip, b->ip) == 1 && - AddressIPv6Lt(a->ip2, b->ip2) == 1) { - //printf("ADDRESS_LT\n"); - return ADDRESS_LT; - } else if (AddressIPv6Gt(a->ip, b->ip) == 1 && - AddressIPv6Lt(a->ip, b->ip2) == 1 && - AddressIPv6Gt(a->ip2, b->ip2) == 1) { - //printf("ADDRESS_GE\n"); - return ADDRESS_GE; - } else if (AddressIPv6Gt(a->ip, b->ip2) == 1) { - //printf("ADDRESS_GT\n"); - return ADDRESS_GT; - } else { - /* should be unreachable */ - printf("Internal Error: should be unreachable\n"); - } - -// printf ("ADDRESS_ER\n"); - return ADDRESS_ER; -} - /* TESTS */ diff --git a/src/detect-address.h b/src/detect-address.h index a5f15da894..70d9ae4e12 100644 --- a/src/detect-address.h +++ b/src/detect-address.h @@ -35,5 +35,10 @@ typedef struct DetectAddressGroup_ { } DetectAddressGroup; +typedef struct DetectAddressGroups_ { + DetectAddressGroup *ipv4_head; + DetectAddressGroup *ipv6_head; +} DetectAddressGroups; + #endif /* __DETECT_ADDRESS_H__ */