Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

WvIPNet Class Reference

#include <wvaddr.h>

Inherits WvIPAddr.

Collaboration diagram for WvIPNet:

[legend]
List of all members.

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 306 of file wvaddr.h.

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.

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

virtual ~WvIPNet ()
virtual unsigned WvHash () const
 Override the hash and comparison functions.

WvIPAddr base () const
 Get the 'base IP address' component, netmask, network, and broadcast.

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

bool includes (const WvIPNet &addr) const
 determine whether the given address is already included in this net

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

void normalize ()
bool is_default () const
 is this net the default gateway? (0.0.0.0/0)

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

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
__u32 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

WvAddrgen (struct sockaddr *addr)

Public Attributes

unsigned char binaddr [4]

Protected Member Functions

virtual WvString printable () const

Protected Attributes

WvIPAddr mask


Constructor & Destructor Documentation

WvIPNet::WvIPNet const WvIPNet _net  ) 
 

Definition at line 523 of file wvaddr.cc.

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

Definition at line 314 of file wvaddr.h.

WvIPNet::WvIPNet WvStringParm  string  )  [inline]
 

Definition at line 316 of file wvaddr.h.

References WvStringParm.

WvIPNet::WvIPNet const WvIPAddr base,
const WvIPAddr _mask
 

Definition at line 557 of file wvaddr.cc.

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 561 of file wvaddr.cc.

References __u32, and mask.

WvIPNet::WvIPNet  ) 
 

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

Definition at line 520 of file wvaddr.cc.

WvIPNet::~WvIPNet  )  [virtual]
 

Definition at line 572 of file wvaddr.cc.


Member Function Documentation

__u32 WvIPAddr::addr  )  const [inline, inherited]
 

Definition at line 277 of file wvaddr.h.

References __u32.

Referenced by bits(), WvIPAddr::operator+(), WvIPAddr::operator-(), and WvIPAddr::sockaddr().

WvIPAddr WvIPNet::base  )  const [inline]
 

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

Definition at line 341 of file wvaddr.h.

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

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 618 of file wvaddr.cc.

References __u32, WvIPAddr::addr(), bits(), and mask.

Referenced by bits(), normalize(), printable(), WvInterface::setipaddr(), and string_init().

WvIPAddr WvIPNet::broadcast  )  const [inline]
 

Definition at line 347 of file wvaddr.h.

Referenced by WvInterfaceDict::islocal(), and WvInterface::setipaddr().

bool WvIPNet::comparator const WvAddr a2,
bool  first_pass = true
const [virtual]
 

Reimplemented from WvIPAddr.

Definition at line 593 of file wvaddr.cc.

References WvAddr::comparator(), comparator(), mask, WvAddr::type(), and WVIPNET.

Referenced by comparator().

WvEncap WvIPAddr::encap  )  const [virtual, inherited]
 

Implements WvAddr.

Definition at line 481 of file wvaddr.cc.

WvAddr * WvAddr::gen struct sockaddr *  addr  )  [static, inherited]
 

Definition at line 89 of file wvaddr.cc.

References WvEncap::cap, WvAddr::encap(), and WvAddr::gen().

Referenced by WvAddr::gen().

void WvIPNet::include const WvIPNet addr  ) 
 

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

Definition at line 605 of file wvaddr.cc.

References include(), and mask.

Referenced by include().

bool WvIPNet::includes const WvIPNet addr  )  const
 

determine whether the given address is already included in this net

Definition at line 611 of file wvaddr.cc.

References base(), includes(), netmask(), and network().

Referenced by includes(), and WvInterfaceDict::on_local_net().

bool WvIPNet::is_default  )  const [inline]
 

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

Definition at line 370 of file wvaddr.h.

References WvIPAddr::binaddr.

Referenced by WvInterface::delroute(), and realtable().

bool WvIPNet::is_host  )  const [inline]
 

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

Definition at line 374 of file wvaddr.h.

References WvIPAddr::binaddr.

Referenced by WvInterface::addarp().

bool WvIPAddr::is_zero  )  const [inline, inherited]
 

Definition at line 280 of file wvaddr.h.

bool WvAddr::isbroadcast  )  const [virtual, inherited]
 

Reimplemented in WvEtherAddr.

Definition at line 114 of file wvaddr.cc.

WvIPAddr WvIPNet::netmask  )  const [inline]
 

Definition at line 343 of file wvaddr.h.

Referenced by WvInterface::addarp(), includes(), WvIPRoute::operator==(), and WvInterface::setipaddr().

WvIPAddr WvIPNet::network  )  const [inline]
 

Definition at line 345 of file wvaddr.h.

Referenced by WvInterface::addarp(), includes(), WvIPRoute::operator==(), and printable().

void WvIPNet::normalize  ) 
 

Definition at line 632 of file wvaddr.cc.

References __u32, bits(), and mask.

WvIPAddr WvIPAddr::operator & const WvIPAddr a2  )  const [inherited]
 

Definition at line 421 of file wvaddr.cc.

References WvIPAddr::binaddr.

WvAddr::operator WvString  )  const [inline, inherited]
 

Definition at line 123 of file wvaddr.h.

References WvAddr::printable().

bool WvAddr::operator!= const WvAddr a2  )  const [inline, inherited]
 

Definition at line 142 of file wvaddr.h.

WvIPAddr WvIPAddr::operator+ int  n  )  const [inherited]
 

Definition at line 467 of file wvaddr.cc.

References __u32, and WvIPAddr::addr().

WvIPAddr WvIPAddr::operator- int  n  )  const [inherited]
 

Definition at line 474 of file wvaddr.cc.

References __u32, and WvIPAddr::addr().

bool WvAddr::operator== const WvAddr a2  )  const [inline, inherited]
 

Definition at line 140 of file wvaddr.h.

WvIPAddr WvIPAddr::operator^ const WvIPAddr a2  )  const [inherited]
 

Definition at line 443 of file wvaddr.cc.

References WvIPAddr::binaddr.

WvIPAddr WvIPAddr::operator| const WvIPAddr a2  )  const [inherited]
 

Definition at line 432 of file wvaddr.cc.

References WvIPAddr::binaddr.

WvIPAddr WvIPAddr::operator~  )  const [inherited]
 

Definition at line 454 of file wvaddr.cc.

References WvIPAddr::binaddr.

WvString WvIPNet::printable  )  const [protected, virtual]
 

Reimplemented from WvIPAddr.

Definition at line 578 of file wvaddr.cc.

References bits(), network(), and WvIPAddr::printable().

const unsigned char * WvIPAddr::rawdata  )  const [virtual, inherited]
 

Reimplemented from WvAddr.

Definition at line 487 of file wvaddr.cc.

References WvIPAddr::binaddr.

Referenced by WvIPAddr::comparator().

size_t WvIPAddr::rawdata_len  )  const [virtual, inherited]
 

Reimplemented from WvAddr.

Definition at line 493 of file wvaddr.cc.

Referenced by WvIPAddr::comparator().

sockaddr_bin * WvIPAddr::sockaddr  )  const [virtual, inherited]
 

Implements WvAddr.

Reimplemented in WvIPPortAddr.

Definition at line 502 of file wvaddr.cc.

References WvIPAddr::addr(), and sockaddr_bin.

Referenced by WvInterface::addarp(), WvInterface::setipaddr(), WvIPPortAddr::sockaddr(), WvIPRawStream::uwrite(), and WvIPRawStream::WvIPRawStream().

size_t WvIPAddr::sockaddr_len  )  const [virtual, inherited]
 

Implements WvAddr.

Definition at line 514 of file wvaddr.cc.

Referenced by WvInterface::addarp(), WvTCPConn::do_connect(), WvInterface::setipaddr(), WvUDPStream::uwrite(), WvIPRawStream::uwrite(), WvIPRawStream::WvIPRawStream(), WvTCPListener::WvTCPListener(), and WvUDPStream::WvUDPStream().

void WvIPNet::string_init const char  string[]  ) 
 

Reimplemented from WvIPAddr.

Definition at line 528 of file wvaddr.cc.

References __u32, bits(), mask, and string_init().

Referenced by string_init().

virtual const char* WvIPNet::type  )  const [inline, virtual]
 

Reimplemented from WvIPAddr.

Definition at line 322 of file wvaddr.h.

References WVIPNET.

unsigned WvIPNet::WvHash  )  const [virtual]
 

Override the hash and comparison functions.

Reimplemented from WvAddr.

Definition at line 587 of file wvaddr.cc.

References mask, and WvAddr::WvHash().


Member Data Documentation

unsigned char WvIPAddr::binaddr[4] [inherited]
 

Definition at line 248 of file wvaddr.h.

Referenced by WvIPAddr::comparator(), is_default(), is_host(), WvIPAddr::operator &(), WvIPAddr::operator^(), WvIPAddr::operator|(), WvIPAddr::operator~(), WvIPAddr::printable(), WvIPAddr::rawdata(), WvIPAddr::string_init(), and WvIPAddr::WvIPAddr().

WvIPAddr WvIPNet::mask [protected]
 

Definition at line 309 of file wvaddr.h.

Referenced by bits(), comparator(), include(), normalize(), string_init(), WvHash(), and WvIPNet().


The documentation for this class was generated from the following files:
Generated on Tue Oct 5 01:09:27 2004 for WvStreams by doxygen 1.3.7