UCommon
ucommon::cidr Class Reference

A class to hold internet segment routing rules. More...

#include <socket.h>

Inheritance diagram for ucommon::cidr:
Collaboration diagram for ucommon::cidr:

Public Types

typedef LinkedObject policy
 A convenience type for using a pointer to a linked list as a policy chain.
 

Public Member Functions

 cidr ()
 Create an uninitialized cidr.
 
 cidr (const char *string)
 Create an unlinked cidr from a string.
 
 cidr (const cidr &existing)
 Construct a copy of an existing cidr.
 
 cidr (policy **policy, const char *string)
 Create an unnamed cidr entry on a specified policy chain.
 
 cidr (policy **policy, const char *string, const char *name)
 Create a named cidr entry on a specified policy chain.
 
struct hostaddr_internet getBroadcast (void) const
 Get the broadcast host address represented by our cidr.
 
int getFamily (void) const
 Get the address family of our cidr block object.
 
unsigned getMask (void) const
 Get the number of bits in the cidr bitmask.
 
const char * getName (void) const
 Get the saved name of our cidr.
 
struct hostaddr_internet getNetmask (void) const
 Get the effective network mask for our cidr block.
 
struct hostaddr_internet getNetwork (void) const
 Get the network host base address of our cidr block.
 
bool is_member (const struct sockaddr *address) const
 Test if a given socket address falls within this cidr.
 
bool operator!= (const struct sockaddr *address) const
 Test if a given socket address falls outside this cidr.
 
bool operator== (const struct sockaddr *address) const
 Test if a given socket address falls within this cidr.
 
void set (const char *string)
 Set our cidr to a string address.
 
- Public Member Functions inherited from ucommon::LinkedObject
void delist (LinkedObject **root)
 Locate and remove ourselves from a list of objects.
 
void enlist (LinkedObject **root)
 Add our object to an existing linked list through a pointer.
 
LinkedObjectgetNext (void) const
 Get next effective object when iterating.
 
bool is_member (LinkedObject *list) const
 Search to see if we are a member of a specific list.
 
virtual void release (void)
 Release list, mark as no longer linked.
 
virtual void retain (void)
 Retain by marking as self referenced list.
 
- Public Member Functions inherited from ucommon::ObjectProtocol
ObjectProtocolcopy (void)
 Retain (increase retention of) object when copying.
 
void operator++ (void)
 Increase retention operator.
 
void operator-- (void)
 Decrease retention operator.
 
virtual ~ObjectProtocol ()
 Required virtual destructor.
 

Static Public Member Functions

static const cidrcontainer (const policy *policy, const struct sockaddr *address)
 Get the largest container cidr entry in a list that matches the socket address.
 
static const cidrfind (const policy *policy, const struct sockaddr *address)
 Find the smallest cidr entry in a list that matches the socket address.
 
- Static Public Member Functions inherited from ucommon::LinkedObject
static unsigned count (const LinkedObject *root)
 Count the number of linked objects in a list.
 
static LinkedObjectgetIndexed (LinkedObject *root, unsigned index)
 Get member by index.
 
static void purge (LinkedObject *root)
 Release all objects from a list.
 

Protected Member Functions

struct hostaddr_internet broadcast (void) const
 
unsigned mask (const char *cp) const
 
unsigned mask (void) const
 
- Protected Member Functions inherited from ucommon::LinkedObject
 LinkedObject ()
 Construct base class unattached to anyone.
 
 LinkedObject (const LinkedObject &from)
 
 LinkedObject (LinkedObject **root)
 Construct base class attached to a chain of objects.
 

Protected Attributes

int Family
 
char Name [16]
 
struct hostaddr_internet Netmask Network
 
- Protected Attributes inherited from ucommon::LinkedObject
LinkedObjectNext
 

Detailed Description

A class to hold internet segment routing rules.

This class can be used to provide a stand-alone representation of a cidr block of internet addresses or chained together into some form of access control list. The cidr class can hold segments for both IPV4 and IPV6 addresses. The class accepts cidr's defined as C strings, typically in the form of address/bits or address/submask. These routines auto-detect ipv4 and ipv6 addresses.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 167 of file socket.h.

Member Typedef Documentation

◆ policy

A convenience type for using a pointer to a linked list as a policy chain.

Definition at line 184 of file socket.h.

Constructor & Destructor Documentation

◆ cidr() [1/4]

ucommon::cidr::cidr ( const char * string)

Create an unlinked cidr from a string.

The string is typically in the form base-host-address/range, where range might be a bit count or a network mask.

Parameters
stringfor cidr block.

◆ cidr() [2/4]

ucommon::cidr::cidr ( policy ** policy,
const char * string )

Create an unnamed cidr entry on a specified policy chain.

Parameters
policychain to link cidr to.
stringfor cidr block.

◆ cidr() [3/4]

ucommon::cidr::cidr ( policy ** policy,
const char * string,
const char * name )

Create a named cidr entry on a specified policy chain.

Parameters
policychain to link cidr to.
stringfor cidr block.
nameof this policy object.

◆ cidr() [4/4]

ucommon::cidr::cidr ( const cidr & existing)

Construct a copy of an existing cidr.

Parameters
existingcidr we copy from.

Member Function Documentation

◆ container()

static const cidr * ucommon::cidr::container ( const policy * policy,
const struct sockaddr * address )
static

Get the largest container cidr entry in a list that matches the socket address.

Parameters
policychain to search.
addressto search for.
Returns
largest cidr or NULL if none match.

◆ find()

static const cidr * ucommon::cidr::find ( const policy * policy,
const struct sockaddr * address )
static

Find the smallest cidr entry in a list that matches the socket address.

Parameters
policychain to search.
addressto search for.
Returns
smallest cidr or NULL if none match.

◆ getBroadcast()

struct hostaddr_internet ucommon::cidr::getBroadcast ( void ) const
inline

Get the broadcast host address represented by our cidr.

Returns
binary broadcast host address.

Definition at line 276 of file socket.h.

◆ getFamily()

int ucommon::cidr::getFamily ( void ) const
inline

Get the address family of our cidr block object.

Returns
family of our cidr.

Definition at line 252 of file socket.h.

◆ getMask()

unsigned ucommon::cidr::getMask ( void ) const
inline

Get the number of bits in the cidr bitmask.

Returns
bit mask of cidr.

Definition at line 284 of file socket.h.

◆ getName()

const char * ucommon::cidr::getName ( void ) const
inline

Get the saved name of our cidr.

This is typically used with find when the same policy name might be associated with multiple non- overlapping cidr blocks. A typical use might to have a cidr block like 127/8 named "localdomain", as well as the ipv6 "::1".

Returns
name of cidr.

Definition at line 244 of file socket.h.

◆ getNetmask()

struct hostaddr_internet ucommon::cidr::getNetmask ( void ) const
inline

Get the effective network mask for our cidr block.

Returns
binary network mask for our cidr.

Definition at line 268 of file socket.h.

◆ getNetwork()

struct hostaddr_internet ucommon::cidr::getNetwork ( void ) const
inline

Get the network host base address of our cidr block.

Returns
binary network host address.

Definition at line 260 of file socket.h.

◆ is_member()

bool ucommon::cidr::is_member ( const struct sockaddr * address) const

Test if a given socket address falls within this cidr.

Parameters
addressof socket to test.
Returns
true if address is within cidr.

◆ operator!=()

bool ucommon::cidr::operator!= ( const struct sockaddr * address) const
inline

Test if a given socket address falls outside this cidr.

Parameters
addressof socket to test.
Returns
true if address is outside cidr.

Definition at line 315 of file socket.h.

◆ operator==()

bool ucommon::cidr::operator== ( const struct sockaddr * address) const
inline

Test if a given socket address falls within this cidr.

Parameters
addressof socket to test.
Returns
true if address is within cidr.

Definition at line 306 of file socket.h.

◆ set()

void ucommon::cidr::set ( const char * string)

Set our cidr to a string address.

Replaces prior value.

Parameters
stringto set for cidr.

Field Documentation

◆ Family

int ucommon::cidr::Family
protected

Definition at line 170 of file socket.h.

◆ Name

char ucommon::cidr::Name[16]
protected

Definition at line 172 of file socket.h.

◆ Network

struct hostaddr_internet Netmask ucommon::cidr::Network
protected

Definition at line 171 of file socket.h.


The documentation for this class was generated from the following file: