42 #ifndef _DWMIPV4ADDRESS_HH_ 43 #define _DWMIPV4ADDRESS_HH_ 47 #include <sys/types.h> 48 #include <netinet/in.h> 55 typedef uint32_t ipv4addr_t;
87 inline ipv4addr_t
Raw()
const 95 operator std::string ()
const;
100 inline bool IsV6()
const 110 return(ntohl(_addr) < ntohl(addr._addr));
118 return(ntohl(_addr) > ntohl(addr._addr));
126 return((ntohl(_addr) > ntohl(addr._addr))
127 || (_addr == addr._addr));
135 return((ntohl(_addr) < ntohl(addr._addr))
136 || (_addr == addr._addr));
144 return(_addr == addr._addr);
152 return(_addr != addr._addr);
170 uint32_t a = ntohl(_addr);
171 if (a != 0xFFFFFFFF) {
172 _addr = htonl(a + 1);
182 uint32_t a = ntohl(_addr);
183 if (a != 0xFFFFFFFF) {
184 _addr = htonl(a + 1);
195 uint32_t a = ntohl(_addr);
197 _addr = htonl(a - 1);
207 uint32_t a = ntohl(_addr);
209 _addr = htonl(a - 1);
220 uint32_t a = ntohl(_addr);
222 _addr = htonl(a - i);
237 uint32_t a = ntohl(_addr);
238 if ((uint32_t)(a + i) >= a) {
239 _addr = htonl(a + i);
242 _addr = htonl(0xFFFFFFFF);
247 inline bool BitIsSet(int8_t bit)
const 249 return(((ntohl(_addr) >> bit) & 1) != 0);
252 inline int GetBit(
int bit)
const 258 return (ntohl(_addr) >> (31 - bit)) & 1;
265 static inline uint8_t MaxKeyBits()
279 std::istream &
Read(std::istream & is);
284 std::ostream &
Write(std::ostream & os)
const;
290 ssize_t
Read(
int fd);
296 ssize_t
Write(
int fd)
const;
301 size_t Read(FILE * f);
306 size_t Write(FILE * f)
const;
312 int Read(gzFile gzf);
318 int Write(gzFile gzf)
const;
330 int BZWrite(BZFILE *bzf)
const;
335 friend std::ostream &
operator << (std::ostream & os,
346 uint32_t
IpSum()
const;
354 #endif // _DWMIPV4ADDRESS_HH_ Ipv4Address & operator--()
Pre-decrement operator.
Definition: DwmIpv4Address.hh:205
int BZRead(BZFILE *bzf)
Reads from a BZFILE pointer.
Ipv4Address()
Constructor.
Ipv4Address & operator-=(uint32_t i)
-= operator.
Definition: DwmIpv4Address.hh:218
uint32_t IpSum() const
Returns the partial sum of the IP address, as would be used when calculating the IP header checksum o...
This class encapsulates an IPv4 address.
Definition: DwmIpv4Address.hh:62
Dwm::IpAddress class definition.
uint32_t StreamedLength() const
Returns the number of bytes that would be written if we called one of the Write() members...
Ipv4Address & operator&=(const Ipv4Address &mask)
Mask operator.
Definition: DwmIpv4Address.hh:158
friend std::ostream & operator<<(std::ostream &os, const Ipv4Address &addr)
Prints an Ipv4Address to an ostream in human-readable form.
bool operator>=(const Ipv4Address &addr) const
Greater than or equal-to operator.
Definition: DwmIpv4Address.hh:124
int BZWrite(BZFILE *bzf) const
Writes to a BZFILE pointer.
Ipv4Address & operator++()
Pre-increment operator.
Definition: DwmIpv4Address.hh:180
Ipv4Address & operator+=(uint32_t i)
+= operator.
Definition: DwmIpv4Address.hh:235
bool operator==(const Ipv4Address &addr) const
Equal-to operator.
Definition: DwmIpv4Address.hh:142
Definition: DwmBZ2IO.hh:67
bool operator<=(const Ipv4Address &addr) const
Less-than or equal-to operator.
Definition: DwmIpv4Address.hh:133
Ipv4Address(ipv4addr_t addr)
Construct from an ipv4addr_t (32-bit value in network byte order).
Definition: DwmIpv4Address.hh:74
std::istream & Read(std::istream &is)
Reads from an istream. Returns the istream.
This class encapsulates an IP address.
Definition: DwmIpAddress.hh:63
bool operator>(const Ipv4Address &addr) const
Greater-than operator.
Definition: DwmIpv4Address.hh:116
ipv4addr_t Raw() const
Returns an ipv4addr_t representation (32-bit value in network byte order).
Definition: DwmIpv4Address.hh:87
std::ostream & Write(std::ostream &os) const
Writes to an ostream. Returns the ostream.
bool operator!=(const Ipv4Address &addr) const
Not-equal-to operator.
Definition: DwmIpv4Address.hh:150
bool operator<(const Ipv4Address &addr) const
less-than operator.
Definition: DwmIpv4Address.hh:108