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=)
 
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. More...
 
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
 
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()

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().

Member Function Documentation

◆ 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.

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


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