This class encapsulates an IPv4 address and netmask. More...
#include <DwmIpv4Prefix.hh>
Public Member Functions | |
| Ipv4Prefix () | |
| Constructor. Initializes the prefix to 255.255.255.255/32. | |
| Ipv4Prefix (const Ipv4Address &network, uint8_t maskLength) | |
| Constructor accepting an IP address and a netmask length. | |
| Ipv4Prefix (const Ipv4Address &network, const Ipv4Address &netmask) | |
| Construct from an IP address and netmask. | |
| Ipv4Prefix (const std::string &prefix) | |
| Construct from a string of the form a.b.c.d/n. | |
| Ipv4Prefix (const Ipv4Address &addr) | |
| Construct from an Ipv4Address. Sets the netmask to 255.255.255.255. | |
| Ipv4Prefix (const Ipv4Prefix &prefix) | |
| Copy constructor. | |
| Ipv4Prefix & | operator= (const Ipv4Prefix &prefix) |
| operator = | |
| virtual | ~Ipv4Prefix () |
| Destructor. | |
| Ipv4Address | Network () const |
| Returns the network portion of the prefix. | |
| ipv4addr_t | NetworkRaw () const |
| Ipv4Address | Netmask () const |
| Returns the netmask portion of the prefix. | |
| uint8_t | MaskLength () const |
| Returns the length of the netmask (number of significant bits). | |
| uint8_t | MaskLength (uint8_t maskLength) |
| Changes the length of the netmask (number of significant bits). | |
| Ipv4Address | FirstAddress () const |
| Returns the first IPv4 address in the prefix's range. | |
| Ipv4Address | LastAddress () const |
| Returns the last IPv4 address in the prefix's range. | |
| bool | Set (const Ipv4Address &network, uint8_t maskLength) |
| Initializes the prefix using an IP address and a netmask length. | |
| void | Set (const Ipv4Address &network, const Ipv4Address &netmask) |
| Initializes the prefix using an IP address and a netmask. | |
| bool | operator< (const Ipv4Prefix &prefix) const |
Returns true if this is less than prefix. | |
| bool | operator> (const Ipv4Prefix &prefix) const |
Returns true if this is greater than prefix. | |
| bool | operator== (const Ipv4Prefix &prefix) const |
| Equal-to operator. | |
| bool | operator!= (const Ipv4Prefix &prefix) const |
| Not-equal-to operator. | |
| Ipv4Prefix & | operator++ () |
| Pre-increment operator. | |
| Ipv4Prefix | operator++ (int) |
| Post-increment operator. | |
| Ipv4Prefix & | operator-- () |
| Pre-decrement operator. | |
| Ipv4Prefix | operator-- (int) |
| Post-decrement operator. | |
| bool | Contains (const Ipv4Address &address) const |
Returs true if address falls within the prefix. | |
| bool | Contains (const Ipv4Prefix &prefix) const |
Returns true if prefix is a subnet of this. | |
| bool | Adjacent (const Ipv4Prefix &prefix) const |
Returns true if the given prefix is adjacent. | |
| std::pair< bool, Ipv4Prefix > | Combine (const Ipv4Prefix &prefix) const |
If the given prefix can be combined with this prefix to form a single prefix, returns [true,combinedPrefix]. | |
| ssize_t | Read (int fd) |
| Reads a prefix from a file descriptor. | |
| ssize_t | Write (int fd) const |
| Writes a prefix to a file descriptor. | |
| size_t | Read (FILE *f) |
| Reads a prefix from a FILE pointer. | |
| size_t | Write (FILE *f) const |
| Writes a prefix to a FILE pointer. | |
| std::istream & | Read (std::istream &is) |
| Reads a prefix from an istream. Returns the istream. | |
| std::ostream & | Write (std::ostream &os) const |
| Writes a prefix to an ostream. Returns the ostream. | |
| int | Read (gzFile gzf) |
| Reads a prefix from a gzFile. | |
| int | Write (gzFile gzf) const |
| Writes a prefix to a gzFile. | |
| int | BZRead (BZFILE *bzf) |
| Reads a prefix from a BZFILE pointer. | |
| int | BZWrite (BZFILE *bzf) const |
| Writes a prefix to a BZFILE pointer. | |
| bool | Read (boost::asio::ip::tcp::socket &s, boost::system::error_code &ec) |
Reads the prefix from s. | |
| bool | Write (boost::asio::ip::tcp::socket &s, boost::system::error_code &ec) const |
Writes the prefix to s. | |
| bool | Read (boost::asio::local::stream_protocol::socket &s, boost::system::error_code &ec) |
Reads the prefix from s. | |
| bool | Write (boost::asio::local::stream_protocol::socket &s, boost::system::error_code &ec) const |
Writes the prefix to s. | |
| bool | Read (boost::asio::generic::stream_protocol::socket &s, boost::system::error_code &ec) |
Reads the prefix from s. | |
| bool | Write (boost::asio::generic::stream_protocol::socket &s, boost::system::error_code &ec) const |
Writes the prefix to s. | |
| std::string | ToString () const |
| Returns a string representation of the prefix in 'a.b.c.d/n' form. | |
| std::string | ToShortString () const |
| Returns a string representation of the prefix in 'a.b.c.d/n' form, but with unnecessary trailing zeros removed from the IP address. | |
| uint64_t | StreamedLength () const |
| Returns the number of bytes that should be written if a Write() member was called. | |
| const uint8_t * | Data () const |
| Returns a pointer to the 5-byte data. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const Ipv4Prefix &prefix) |
| Prints an Ipv4Prefix to an ostream in 'a.b.c.d/n' form. | |
This class encapsulates an IPv4 address and netmask.
| Dwm::Ipv4Prefix::Ipv4Prefix | ( | const std::string & | prefix | ) |
Construct from a string of the form a.b.c.d/n.
Note we accept short addresses, for example 128.35/16 or 10/8. We also accept host addresses with netmasks, and will properly apply the netmask.
| int Dwm::Ipv4Prefix::BZRead | ( | BZFILE * | bzf | ) |
Reads a prefix from a BZFILE pointer.
Returns the number of bytes read on success, -1 on failure.
| int Dwm::Ipv4Prefix::BZWrite | ( | BZFILE * | bzf | ) | const |
Writes a prefix to a BZFILE pointer.
Returns the number of bytes written on success, -1 on failure.
| std::pair< bool, Ipv4Prefix > Dwm::Ipv4Prefix::Combine | ( | const Ipv4Prefix & | prefix | ) | const |
If the given prefix can be combined with this prefix to form a single prefix, returns [true,combinedPrefix].
Else returns [false,255.255.255.255/32]. Prefixes may be combined if one contains the other or they are adjacent and have the same netmask length.
|
inline |
Returns a pointer to the 5-byte data.
This should not be used by typical applications; it is only needed by things like hash algorithms (such as that used by the Ipv4Routes template class).
| bool Dwm::Ipv4Prefix::operator< | ( | const Ipv4Prefix & | prefix | ) | const |
Returns true if this is less than prefix.
The comparison uses the typical ordering: if the IP address of this is less than the IP address of prefix, returns true. If the IP address of this is equal to the IP address of prefix, returns true if the netmask length of this is lower than the netmask length of prefix. In all other cases, returns false.
| bool Dwm::Ipv4Prefix::operator> | ( | const Ipv4Prefix & | prefix | ) | const |
Returns true if this is greater than prefix.
The comparison uses the typical ordering: if the IP address of this is greater than the IP address of prefix, returns true. If the IP address of this is equal to the IP address of prefix, returns true if the netmask length of this is higher than the netmask length of prefix. In all other cases, returns false.
| bool Dwm::Ipv4Prefix::Read | ( | boost::asio::generic::stream_protocol::socket & | s, |
| boost::system::error_code & | ec ) |
Reads the prefix from s.
Returns true on success, false on failure. On failure ec will be set to the error code.
| bool Dwm::Ipv4Prefix::Read | ( | boost::asio::ip::tcp::socket & | s, |
| boost::system::error_code & | ec ) |
Reads the prefix from s.
Returns true on success, false on failure. On failure ec will be set to the error code.
| bool Dwm::Ipv4Prefix::Read | ( | boost::asio::local::stream_protocol::socket & | s, |
| boost::system::error_code & | ec ) |
Reads the prefix from s.
Returns true on success, false on failure. On failure ec will be set to the error code.
| size_t Dwm::Ipv4Prefix::Read | ( | FILE * | f | ) |
Reads a prefix from a FILE pointer.
Returns 1 on success, 0 on failure.
| int Dwm::Ipv4Prefix::Read | ( | gzFile | gzf | ) |
Reads a prefix from a gzFile.
Returns the number of bytes read on success, -1 on failure.
| ssize_t Dwm::Ipv4Prefix::Read | ( | int | fd | ) |
Reads a prefix from a file descriptor.
Returns the number of bytes read on success, -1 on failure.
| bool Dwm::Ipv4Prefix::Write | ( | boost::asio::generic::stream_protocol::socket & | s, |
| boost::system::error_code & | ec ) const |
Writes the prefix to s.
Returns true on success, false on failure. On failure ec will be set to the error code.
| bool Dwm::Ipv4Prefix::Write | ( | boost::asio::ip::tcp::socket & | s, |
| boost::system::error_code & | ec ) const |
Writes the prefix to s.
Returns true on success, false on failure. On failure ec will be set to the error code.
| bool Dwm::Ipv4Prefix::Write | ( | boost::asio::local::stream_protocol::socket & | s, |
| boost::system::error_code & | ec ) const |
Writes the prefix to s.
Returns true on success, false on failure. On failure ec will be set to the error code.
| size_t Dwm::Ipv4Prefix::Write | ( | FILE * | f | ) | const |
Writes a prefix to a FILE pointer.
Returns 1 on success, 0 on failure.
| int Dwm::Ipv4Prefix::Write | ( | gzFile | gzf | ) | const |
Writes a prefix to a gzFile.
Returns the number of bytes written on success, -1 on failure.
| ssize_t Dwm::Ipv4Prefix::Write | ( | int | fd | ) | const |
Writes a prefix to a file descriptor.
Returns the number of bytes written on success, -1 on failure.
|
friend |
Prints an Ipv4Prefix to an ostream in 'a.b.c.d/n' form.
Returns the ostream.