21 #ifndef INCLUDE_OLA_NETWORK_IPV4ADDRESS_H_
22 #define INCLUDE_OLA_NETWORK_IPV4ADDRESS_H_
27 #include <netinet/in.h>
52 : m_address(address) {
56 m_address.s_addr = address;
60 : m_address(other.m_address) {
65 m_address = other.m_address;
71 return m_address.s_addr == other.m_address.s_addr;
75 return !(*
this == other);
81 return m_address.s_addr < other.m_address.s_addr;
85 return m_address.s_addr > other.m_address.s_addr;
88 const struct in_addr Address() const {
92 uint32_t AsInt()
const {
return m_address.s_addr; }
94 bool IsWildcard()
const {
95 return m_address.s_addr == INADDR_ANY;
100 void Get(uint8_t ptr[LENGTH]) {
102 reinterpret_cast<uint8_t*>(&m_address.s_addr),
106 std::string ToString()
const;
108 friend ostream& operator<< (ostream &out,
const IPV4Address &address) {
109 return out << address.ToString();
112 static IPV4Address* FromString(
const std::string &address);
113 static bool FromString(
const std::string &address,
IPV4Address *target);
115 static IPV4Address FromStringOrDie(
const std::string &address);
128 struct in_addr m_address;
132 #endif // INCLUDE_OLA_NETWORK_IPV4ADDRESS_H_