42 #ifndef _DWMIPV4PREFIX_HH_ 43 #define _DWMIPV4PREFIX_HH_ 48 typedef uint32_t ipv4addr_t;
103 memcpy(_data,prefix._data,5);
112 memcpy(_data,prefix._data,5);
126 return(*(ipv4addr_t *)this->_data);
129 inline ipv4addr_t NetworkRaw()
const 131 return(*(ipv4addr_t *)this->_data);
149 if (maskLength < _data[4]) {
150 if (maskLength == 0) {
151 *(uint32_t *)_data = 0;
155 uint32_t mask = htonl(0xffffffff << (32 - maskLength));
156 *(uint32_t *)_data &= mask;
158 _data[4] = maskLength;
160 else if (maskLength < 33) {
161 _data[4] = maskLength;
238 ssize_t
Read(
int fd);
244 ssize_t
Write(
int fd)
const;
250 size_t Read(FILE *f);
256 size_t Write(FILE *f)
const;
261 std::istream &
Read(std::istream & is);
266 std::ostream &
Write(std::ostream & os)
const;
272 int Read(gzFile gzf);
278 int Write(gzFile gzf)
const;
290 int BZWrite(BZFILE *bzf)
const;
296 friend std::ostream &
operator << (std::ostream & os,
324 inline const uint8_t *
Data()
const 343 #endif // _DWMIPV4PREFIX_HH_ friend std::ostream & operator<<(std::ostream &os, const Ipv4Prefix &prefix)
Prints an Ipv4Prefix to an ostream in 'a.b.c.d/n' form.
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
std::vector< Ipv4Prefix > Ipv4RangePrefixes(const Ipv4Address &addr1, const Ipv4Address &addr2)
Returns the minimal set of IPv4 prefixes that cover the entire range between addr1 and addr2...
int BZRead(BZFILE *bzf)
Reads a prefix from a BZFILE pointer.
std::string ToShortString() const
Returns a string representation of the prefix in 'a.b.c.d/n' form, but with unnecessary trailing zero...
Dwm::Writable pure virtual class definition.
Dwm::BZ2Readable pure virtual class definition.
bool operator!=(const Ipv4Prefix &prefix) const
Not-equal-to operator.
virtual ~Ipv4Prefix()
Destructor.
Dwm::GZReadable pure virtual class definition.
This class encapsulates an IPv4 address.
Definition: DwmIpv4Address.hh:62
Dwm::Readable pure virtual class definition.
bool operator<(const Ipv4Prefix &prefix) const
Returns true if this is less than prefix.
ssize_t Read(int fd)
Reads a prefix from a file descriptor.
This class encapsulates an IPv4 address and netmask.
Definition: DwmIpv4Prefix.hh:69
Ipv4Address Netmask() const
Returns the netmask portion of the prefix.
ssize_t Write(int fd) const
Writes a prefix to a file descriptor.
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmBZ2Readable.hh:57
bool operator>(const Ipv4Prefix &prefix) const
Returns true if this is greater than prefix.
bool operator==(const Ipv4Prefix &prefix) const
Equal-to operator.
Ipv4Prefix(const Ipv4Prefix &prefix)
Copy constructor.
Definition: DwmIpv4Prefix.hh:101
std::string ToString() const
Returns a string representation of the prefix in 'a.b.c.d/n' form.
bool Adjacent(const Ipv4Prefix &prefix) const
Returns true if the given prefix is adjacent.
Ipv4Prefix & operator=(const Ipv4Prefix &prefix)
operator =
Definition: DwmIpv4Prefix.hh:109
Dwm::BZ2Writable pure virtual class definition.
bool Contains(const Ipv4Address &address) const
Returs true if address falls within the prefix.
Definition: DwmBZ2IO.hh:67
uint8_t MaskLength() const
Returns the length of the netmask (number of significant bits).
Ipv4Address Network() const
Returns the network portion of the prefix.
Definition: DwmIpv4Prefix.hh:124
const uint8_t * Data() const
Returns a pointer to the 5-byte data.
Definition: DwmIpv4Prefix.hh:324
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmGZReadable.hh:57
uint32_t StreamedLength() const
Returns the number of bytes that should be written if a Write() member was called.
Definition: DwmIpv4Prefix.hh:314
Dwm::Ipv4Address class definition.
This class defines an interface for classes that can write their contents to an ostream, file descriptor or FILE pointer.
Definition: DwmWritable.hh:58
int BZWrite(BZFILE *bzf) const
Writes a prefix to a BZFILE pointer.
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmBZ2Writable.hh:57
Dwm::GZWritable pure virtual class definition.
This class defines an interface for classes that can read their contents from an istream, file descriptor or FILE pointer.
Definition: DwmReadable.hh:58
bool Set(const Ipv4Address &network, uint8_t maskLength)
Initializes the prefix using an IP address and a netmask length.
Ipv4Prefix()
Constructor. Initializes the prefix to 255.255.255.255/32.
uint8_t MaskLength(uint8_t maskLength)
Changes the length of the netmask (number of significant bits).
Definition: DwmIpv4Prefix.hh:147
Ipv4Address LastAddress() const
Returns the last IPv4 address in the prefix's range.
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...
Ipv4Address FirstAddress() const
Returns the first IPv4 address in the prefix's range.