37 netmask = ntohl(netmask);
59 if (cidr <= 0 || cidr > 32)
61 uint32_t netmask = htonl(0xFFFFFFFF << (32UL - (uint32_t)cidr));
62 SCLogDebug(
"CIDR %d -> netmask %08X", cidr, netmask);
86 memset(in6, 0,
sizeof(
struct in6_addr));
89 in6->s6_addr[i] = 0xff;
95 in6->s6_addr[i] |= 0x80;
97 in6->s6_addr[i] = in6->s6_addr[i] >> 1;
103static int CIDRFromMaskTest01(
void)
106 int v = inet_pton(AF_INET,
"255.255.255.0", &in);
114static int CIDRFromMaskTest02(
void)
117 int v = inet_pton(AF_INET,
"255.255.0.42", &in);
125static int CIDRFromMaskTest03(
void)
128 int v = inet_pton(AF_INET,
"0.0.0.0", &in);
136static int CIDRFromMaskTest04(
void)
139 int v = inet_pton(AF_INET,
"255.255.255.255", &in);
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define PASS
Pass the test.
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
int CIDRFromMask(uint32_t netmask)
Turn 32 bit mask into CIDR.
void CIDRGetIPv6(int cidr, struct in6_addr *in6)
Creates a cidr ipv6 netblock, based on the cidr netblock value.
uint32_t CIDRGet(int cidr)