ucc::cidr Class Reference

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

#include <socket.h>

Inheritance diagram for ucc::cidr:
Inheritance graph
[legend]
Collaboration diagram for ucc::cidr:
Collaboration graph
[legend]

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 (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.
 cidr (const cidr &existing)
 Construct a copy of an existing cidr.
const char * getName (void) const
 Get the saved name of our cidr.
int getFamily (void) const
 Get the address family of our cidr block object.
inethostaddr_t getNetwork (void) const
 Get the network host base address of our cidr block.
inethostaddr_t getNetmask (void) const
 Get the effective network mask for our cidr block.
inethostaddr_t getBroadcast (void) const
 Get the broadcast host address represented by our cidr.
unsigned getMask (void) const
 Get the number of bits in the cidr bitmask.
void set (const char *string)
 Set our cidr to a string address.
bool isMember (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 within this cidr.
bool operator!= (const struct sockaddr *address) const
 Test if a given socket address falls outside this cidr.

Static Public Member Functions

static cidrfind (policy *policy, const struct sockaddr *address)
 Find the smallest cidr entry in a list that matches the socket address.
static cidrcontainer (policy *policy, const struct sockaddr *address)
 Get the largest container cidr entry in a list that matches the socket address.

Protected Member Functions

unsigned getMask (const char *cp) const

Protected Attributes

int family
inethostaddr_t netmask
inethostaddr_t network
char name [16]

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@gnutelephony.org>

Definition at line 148 of file socket.h.


Constructor & Destructor Documentation

ucc::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:
string for cidr block.
ucc::cidr::cidr ( policy **  policy,
const char *  string 
)

Create an unnamed cidr entry on a specified policy chain.

Parameters:
policy chain to link cidr to.
string for cidr block.
ucc::cidr::cidr ( policy **  policy,
const char *  string,
const char *  name 
)

Create a named cidr entry on a specified policy chain.

Parameters:
policy chain to link cidr to.
string for cidr block.
name of this policy object.
ucc::cidr::cidr ( const cidr existing  ) 

Construct a copy of an existing cidr.

Parameters:
existing cidr we copy from.

Member Function Documentation

static cidr* ucc::cidr::container ( policy policy,
const struct sockaddr *  address 
) [static]

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

Parameters:
policy chain to search.
address to search for.
Returns:
largest cidr or NULL if none match.
static cidr* ucc::cidr::find ( policy policy,
const struct sockaddr *  address 
) [static]

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

Parameters:
policy chain to search.
address to search for.
Returns:
smallest cidr or NULL if none match.
inethostaddr_t ucc::cidr::getBroadcast ( void   )  const

Get the broadcast host address represented by our cidr.

Returns:
binary broadcast host address.
int ucc::cidr::getFamily ( void   )  const [inline]

Get the address family of our cidr block object.

Returns:
family of our cidr.

Definition at line 227 of file socket.h.

unsigned ucc::cidr::getMask ( void   )  const

Get the number of bits in the cidr bitmask.

Returns:
bit mask of cidr.
const char* ucc::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 220 of file socket.h.

inethostaddr_t ucc::cidr::getNetmask ( void   )  const [inline]

Get the effective network mask for our cidr block.

Returns:
binary network mask for our cidr.

Definition at line 241 of file socket.h.

inethostaddr_t ucc::cidr::getNetwork ( void   )  const [inline]

Get the network host base address of our cidr block.

Returns:
binary network host address.

Definition at line 234 of file socket.h.

bool ucc::cidr::isMember ( const struct sockaddr *  address  )  const

Test if a given socket address falls within this cidr.

Parameters:
address of socket to test.
Returns:
true if address is within cidr.
bool ucc::cidr::operator!= ( const struct sockaddr *  address  )  const [inline]

Test if a given socket address falls outside this cidr.

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

Definition at line 282 of file socket.h.

Here is the call graph for this function:

bool ucc::cidr::operator== ( const struct sockaddr *  address  )  const [inline]

Test if a given socket address falls within this cidr.

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

Definition at line 274 of file socket.h.

Here is the call graph for this function:

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

Set our cidr to a string address.

Replaces prior value.

Parameters:
string to set for cidr.

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

Generated on 28 Dec 2009 for UCommon by  doxygen 1.6.1