WvStreams
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
WvIPNet Class Reference

An IP network comprises two WvIPAddr structures: an address and a netmask. More...

#include <wvaddr.h>

Inheritance diagram for WvIPNet:
Inheritance graph
[legend]

Public Member Functions

 WvIPNet (const WvIPNet &_net)
 
 WvIPNet (const char string[])
 
 WvIPNet (WvStringParm string)
 
void string_init (const char string[])
 
 WvIPNet (const WvIPAddr &base, const WvIPAddr &_mask)
 
virtual bool comparator (const WvAddr *a2, bool first_pass=true) const
 
virtual const char * type () const
 
 WvIPNet (const WvIPAddr &base, int bits=32)
 construct an IPNet from a base address and a number of bits in the netmask. More...
 
 WvIPNet ()
 construct an empty IPNet for later copying (probably by operator=) More...
 
virtual unsigned WvHash () const
 Override the hash and comparison functions. More...
 
WvIPAddr base () const
 Get the 'base IP address' component, netmask, network, and broadcast. More...
 
WvIPAddr netmask () const
 
WvIPAddr network () const
 
WvIPAddr broadcast () const
 
void include (const WvIPNet &addr)
 adjust the netmask so that 'addr' would be included in this network More...
 
bool includes (const WvIPNet &addr) const
 determine whether the given address is already included in this net More...
 
int bits () const
 weird netmasks such as 255.0.255.0 (easy example) are almost never used – they have '0' bits in the middle. More...
 
void normalize ()
 
bool is_default () const
 is this net the default gateway? (0.0.0.0/0) More...
 
bool is_host () const
 is it a plain host? (x.x.x.x/32) More...
 
WvIPAddr operator& (const WvIPAddr &a2) const
 
WvIPAddr operator| (const WvIPAddr &a2) const
 
WvIPAddr operator^ (const WvIPAddr &a2) const
 
WvIPAddr operator~ () const
 
WvIPAddr operator+ (int n) const
 
WvIPAddr operator- (int n) const
 
uint32_t addr () const
 
bool is_zero () const
 
virtual WvEncap encap () const
 
virtual struct sockaddr * sockaddr () const
 
virtual size_t sockaddr_len () const
 
virtual const unsigned char * rawdata () const
 
virtual size_t rawdata_len () const
 
 operator WvString () const
 
virtual bool isbroadcast () const
 
bool operator== (const WvAddr &a2) const
 
bool operator!= (const WvAddr &a2) const
 

Static Public Member Functions

static WvAddrgen (struct sockaddr *addr)
 

Public Attributes

unsigned char binaddr [4]
 

Protected Member Functions

virtual WvString printable () const
 

Protected Attributes

WvIPAddr mask
 

Detailed Description

An IP network comprises two WvIPAddr structures: an address and a netmask.

The two ANDed together comprise the "network address", which, if it is correct, can be ORed with any IP address on the network without changing the address. Together, a network address and netmask provide a good description of the IP addresses available on a network.

WvIPNet internally stores a base IP address (the inherited WvIPAddr) and the netmask (a member variable).

Note that the rawdata() function is inherited from WvIPAddr, so it does not include the netmask in the raw data.

Definition at line 312 of file wvaddr.h.

Constructor & Destructor Documentation

◆ WvIPNet() [1/6]

WvIPNet::WvIPNet ( const WvIPNet _net)

Definition at line 537 of file wvaddr.cc.

◆ WvIPNet() [2/6]

WvIPNet::WvIPNet ( const char  string[])
inline

Definition at line 320 of file wvaddr.h.

◆ WvIPNet() [3/6]

WvIPNet::WvIPNet ( WvStringParm  string)
inline

Definition at line 322 of file wvaddr.h.

◆ WvIPNet() [4/6]

WvIPNet::WvIPNet ( const WvIPAddr base,
const WvIPAddr _mask 
)

Definition at line 571 of file wvaddr.cc.

◆ WvIPNet() [5/6]

WvIPNet::WvIPNet ( const WvIPAddr base,
int  bits = 32 
)

construct an IPNet from a base address and a number of bits in the netmask.

The default of 32 gives a one-host network, (netmask 255.255.255.255).

Definition at line 575 of file wvaddr.cc.

References bits().

◆ WvIPNet() [6/6]

WvIPNet::WvIPNet ( )

construct an empty IPNet for later copying (probably by operator=)

Definition at line 534 of file wvaddr.cc.

◆ ~WvIPNet()

WvIPNet::~WvIPNet ( )
virtual

Definition at line 586 of file wvaddr.cc.

Member Function Documentation

◆ printable()

WvString WvIPNet::printable ( ) const
protectedvirtual

Reimplemented from WvIPAddr.

Definition at line 592 of file wvaddr.cc.

◆ string_init()

void WvIPNet::string_init ( const char  string[])

Definition at line 542 of file wvaddr.cc.

◆ comparator()

bool WvIPNet::comparator ( const WvAddr a2,
bool  first_pass = true 
) const
virtual

Reimplemented from WvIPAddr.

Definition at line 607 of file wvaddr.cc.

◆ type()

virtual const char * WvIPNet::type ( ) const
inlinevirtual

Reimplemented from WvIPAddr.

Definition at line 328 of file wvaddr.h.

◆ WvHash()

unsigned WvIPNet::WvHash ( ) const
virtual

Override the hash and comparison functions.

Reimplemented from WvAddr.

Definition at line 601 of file wvaddr.cc.

◆ base()

WvIPAddr WvIPNet::base ( ) const
inline

Get the 'base IP address' component, netmask, network, and broadcast.

Definition at line 347 of file wvaddr.h.

Referenced by includes(), and WvInterface::setipaddr().

◆ netmask()

WvIPAddr WvIPNet::netmask ( ) const
inline

Definition at line 349 of file wvaddr.h.

◆ network()

WvIPAddr WvIPNet::network ( ) const
inline

Definition at line 351 of file wvaddr.h.

◆ broadcast()

WvIPAddr WvIPNet::broadcast ( ) const
inline

Definition at line 353 of file wvaddr.h.

◆ include()

void WvIPNet::include ( const WvIPNet addr)

adjust the netmask so that 'addr' would be included in this network

Definition at line 619 of file wvaddr.cc.

◆ includes()

bool WvIPNet::includes ( const WvIPNet addr) const

determine whether the given address is already included in this net

Definition at line 625 of file wvaddr.cc.

References base().

◆ bits()

int WvIPNet::bits ( ) const

weird netmasks such as 255.0.255.0 (easy example) are almost never used – they have '0' bits in the middle.

However, using the include() function will result in odd netmasks like this, since it will not eliminate a '1' bit unless absolutely necessary. normalize() would convert the above netmask into 255.0.0.0, which is probably the netmask really in use. bits() calculates the number of leading '1' bits in the normalized netmask, without actually doing the normalization.

Definition at line 632 of file wvaddr.cc.

References bits().

Referenced by bits(), WvInterface::setipaddr(), and WvIPNet().

◆ normalize()

void WvIPNet::normalize ( )

Definition at line 646 of file wvaddr.cc.

◆ is_default()

bool WvIPNet::is_default ( ) const
inline

is this net the default gateway? (0.0.0.0/0)

Definition at line 376 of file wvaddr.h.

◆ is_host()

bool WvIPNet::is_host ( ) const
inline

is it a plain host? (x.x.x.x/32)

Definition at line 380 of file wvaddr.h.

◆ operator&()

WvIPAddr WvIPAddr::operator& ( const WvIPAddr a2) const
inherited

Definition at line 435 of file wvaddr.cc.

◆ operator|()

WvIPAddr WvIPAddr::operator| ( const WvIPAddr a2) const
inherited

Definition at line 446 of file wvaddr.cc.

◆ operator^()

WvIPAddr WvIPAddr::operator^ ( const WvIPAddr a2) const
inherited

Definition at line 457 of file wvaddr.cc.

◆ operator~()

WvIPAddr WvIPAddr::operator~ ( ) const
inherited

Definition at line 468 of file wvaddr.cc.

◆ operator+()

WvIPAddr WvIPAddr::operator+ ( int  n) const
inherited

Definition at line 481 of file wvaddr.cc.

◆ operator-()

WvIPAddr WvIPAddr::operator- ( int  n) const
inherited

Definition at line 488 of file wvaddr.cc.

◆ addr()

uint32_t WvIPAddr::addr ( ) const
inlineinherited

Definition at line 283 of file wvaddr.h.

◆ is_zero()

bool WvIPAddr::is_zero ( ) const
inlineinherited

Definition at line 286 of file wvaddr.h.

◆ encap()

WvEncap WvIPAddr::encap ( ) const
virtualinherited

Implements WvAddr.

Definition at line 495 of file wvaddr.cc.

◆ sockaddr()

sockaddr_bin * WvIPAddr::sockaddr ( ) const
virtualinherited

Implements WvAddr.

Definition at line 516 of file wvaddr.cc.

◆ sockaddr_len()

size_t WvIPAddr::sockaddr_len ( ) const
virtualinherited

Implements WvAddr.

Definition at line 528 of file wvaddr.cc.

◆ rawdata()

const unsigned char * WvIPAddr::rawdata ( ) const
virtualinherited

Reimplemented from WvAddr.

Definition at line 501 of file wvaddr.cc.

◆ rawdata_len()

size_t WvIPAddr::rawdata_len ( ) const
virtualinherited

Reimplemented from WvAddr.

Definition at line 507 of file wvaddr.cc.

◆ gen()

WvAddr * WvAddr::gen ( struct sockaddr *  addr)
staticinherited

Definition at line 99 of file wvaddr.cc.

◆ operator WvString()

WvAddr::operator WvString ( ) const
inlineinherited

Definition at line 129 of file wvaddr.h.

◆ isbroadcast()

bool WvAddr::isbroadcast ( ) const
virtualinherited

Definition at line 127 of file wvaddr.cc.

◆ operator==()

bool WvAddr::operator== ( const WvAddr a2) const
inlineinherited

Definition at line 146 of file wvaddr.h.

◆ operator!=()

bool WvAddr::operator!= ( const WvAddr a2) const
inlineinherited

Definition at line 148 of file wvaddr.h.

Member Data Documentation

◆ mask

WvIPAddr WvIPNet::mask
protected

Definition at line 315 of file wvaddr.h.

◆ binaddr

unsigned char WvIPAddr::binaddr[4]
inherited

Definition at line 254 of file wvaddr.h.


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