suricata
util-cidr.c File Reference
#include "suricata-common.h"
#include "util-cidr.h"
#include "util-unittest.h"
Include dependency graph for util-cidr.c:

Go to the source code of this file.

Functions

int CIDRFromMask (uint32_t netmask)
 turn 32 bit mask into CIDR More...
 
uint32_t CIDRGet (int cidr)
 
void CIDRGetIPv6 (int cidr, struct in6_addr *in6)
 Creates a cidr ipv6 netblock, based on the cidr netblock value. More...
 
void UtilCIDRTests (void)
 

Detailed Description

Author
Victor Julien victo.nosp@m.r@in.nosp@m.linia.nosp@m.c.ne.nosp@m.t

CIDR utility functions

Definition in file util-cidr.c.

Function Documentation

◆ CIDRFromMask()

int CIDRFromMask ( uint32_t  netmask)

turn 32 bit mask into CIDR

Return values
cidrcidr value or -1 if the netmask can't be expressed as cidr

Definition at line 33 of file util-cidr.c.

◆ CIDRGet()

uint32_t CIDRGet ( int  cidr)

Definition at line 55 of file util-cidr.c.

References SCLogDebug.

Referenced by SCRadixAddKeyIPV4String().

Here is the caller graph for this function:

◆ CIDRGetIPv6()

void CIDRGetIPv6 ( int  cidr,
struct in6_addr *  in6 
)

Creates a cidr ipv6 netblock, based on the cidr netblock value.

   For example if we send a cidr of 7 as argument, an ipv6 address
   mask of the value FE:00:00:00:00:00:00:00 is created and updated
   in the argument struct in6_addr *in6.
Todo:
I think for the final section: while (cidr > 0), we can simply replace it with a if (cidr > 0) { in6->s6_addr[i] = -1 << (8 - cidr);
Parameters
cidrThe value of the cidr.
in6Pointer to an ipv6 address structure(struct in6_addr) which will hold the cidr netblock result.

Definition at line 80 of file util-cidr.c.

Referenced by SCRadixAddKeyIPV6String().

Here is the caller graph for this function:

◆ UtilCIDRTests()

void UtilCIDRTests ( void  )

Definition at line 147 of file util-cidr.c.

References UtRegisterTest().

Here is the call graph for this function: