senf::INet4Network Class Reference

IPv4 network prefix. More...

#include <senf/Socket/Protocols/INet/INet4Address.hh>

Inheritance diagram for senf::INet4Network:

Public Member Functions

INet4Address const & address () const
 Get the networks address. More...
 
unsigned prefix_len () const
 Get the networks prefix length. More...
 
bool boolean_test () const
 true, if INet4Network is non-empty More...
 
bool operator== (INet4Network const &other) const
 Compare to networks for equality. More...
 
bool match (INet4Address const &addr) const
 true, if the network includes addr More...
 
bool match (INet4Network const &net) const
 true, if the network includes net More...
 
INet4Address host (boost::uint32_t number)
 Return the host with the given number. More...
 
INet4Network subnet (boost::uint32_t net, unsigned prefix_len)
 Return the given subnet of this. More...
 
- Public Member Functions inherited from senf::comparable_safe_bool< INet4Network >
 operator bool_type () const
 
bool operator! () const
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, INet4Network const &addr)
 Output INet4Network instance as it's string representation. More...
 
std::istream & operator>> (std::istream &is, INet4Network &addr)
 Initialize INet4Address instance from a string representation. More...
 

Structors and default members

 INet4Network ()
 Construct empty (0.0.0.0/0) network. More...
 
 INet4Network (INet4Address const &address, unsigned prefix_len)
 Construct network from given address and prefix length. More...
 
 INet4Network (std::string const &s)
 Construct network from CIDR notation. More...
 

Additional Inherited Members

- Protected Types inherited from senf::safe_bool_base
typedef void(safe_bool_base::* bool_type) () const
 
- Protected Member Functions inherited from senf::comparable_safe_bool< INet4Network >
 ~comparable_safe_bool ()
 
- Protected Member Functions inherited from senf::safe_bool_base
void this_type_does_not_support_comparisons () const
 
 safe_bool_base ()
 
 safe_bool_base (const safe_bool_base &)
 
safe_bool_baseoperator= (const safe_bool_base &)
 
 ~safe_bool_base ()
 

Detailed Description

IPv4 network prefix.

This class represents an IPv4 network prefix in CIDR notation.

Definition at line 208 of file INet4Address.hh.

Constructor & Destructor Documentation

◆ INet4Network() [1/3]

senf::INet4Network::INet4Network ( )

Construct empty (0.0.0.0/0) network.

◆ INet4Network() [2/3]

senf::INet4Network::INet4Network ( INet4Address const &  address,
unsigned  prefix_len 
)

Construct network from given address and prefix length.

◆ INet4Network() [3/3]

senf::INet4Network::INet4Network ( std::string const &  s)
explicit

Construct network from CIDR notation.

Definition at line 116 of file INet4Address.cc.

Member Function Documentation

◆ address()

INet4Address const& senf::INet4Network::address ( ) const

Get the networks address.

◆ boolean_test()

bool senf::INet4Network::boolean_test ( ) const

true, if INet4Network is non-empty

◆ host()

INet4Address senf::INet4Network::host ( boost::uint32_t  number)

Return the host with the given number.

Returns the host with the given number within the network. If the number is larger than the maximum host number in the network, it is truncated. So host(0) is the networks own address, host(1) customarily is the default router and host(-1) is the broadcast address.

◆ match() [1/2]

bool senf::INet4Network::match ( INet4Address const &  addr) const

true, if the network includes addr

◆ match() [2/2]

bool senf::INet4Network::match ( INet4Network const &  net) const

true, if the network includes net

The is true, if net is sub-network (or the same as) this.

◆ operator==()

bool senf::INet4Network::operator== ( INet4Network const &  other) const

Compare to networks for equality.

◆ prefix_len()

unsigned senf::INet4Network::prefix_len ( ) const

Get the networks prefix length.

◆ subnet()

INet4Network senf::INet4Network::subnet ( boost::uint32_t  net,
unsigned  prefix_len 
)

Return the given subnet of this.

The returned INet4Network will be a subnet of this with the given network number. The network number is comprised by the bits above prefix_len:

INet4Network("192.168.0.0/16").subnet(111u,24u) == INet4Network("192.168.111.0/24")
INet4Network("192.168.111.0/24").subnet(1u,28u) == INet4Network("192.168.111.16/28")
Parameters
[in]netnetwork number
[in]prefix_lenlength of subnet prefix

Friends And Related Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
INet4Network const &  addr 
)
related

Output INet4Network instance as it's string representation.

◆ operator>>()

std::istream & operator>> ( std::istream &  is,
INet4Network addr 
)
related

Initialize INet4Address instance from a string representation.

sets std::ios::failbit on the stream if an error occurred

See also
INet4Address from_string()

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