29 #ifndef INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_
30 #define INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_
38 #include <sys/socket.h>
60 virtual uint16_t Family()
const = 0;
61 virtual bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const = 0;
62 virtual std::string ToString()
const = 0;
64 friend std::ostream& operator<<(std::ostream &out,
66 return out << address.ToString();
92 m_port(other.m_port) {
99 m_host = other.m_host;
100 m_port = other.m_port;
106 return m_host == other.m_host && m_port == other.m_port;
110 return !(*
this == other);
119 if (m_host == other.m_host)
120 return m_port < other.m_port;
122 return m_host < other.m_host;
131 if (m_host == other.m_host)
132 return m_port > other.m_port;
134 return m_host > other.m_host;
137 uint16_t Family()
const {
return AF_INET; }
139 void Host(
const IPV4Address &host) { m_host = host; }
140 uint16_t Port()
const {
return m_port; }
141 void Port(uint16_t port) { m_port = port; }
143 std::string ToString()
const;
145 static bool FromString(
const std::string &str,
146 IPV4SocketAddress *socket_address);
149 static IPV4SocketAddress FromStringOrDie(
const std::string &address);
151 bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const;
171 memset(reinterpret_cast<uint8_t*>(&m_addr), 0,
sizeof(m_addr));
174 bool IsValid()
const;
176 uint16_t Family()
const {
177 return m_addr.sa_family;
181 if (
this != &other) {
182 memcpy(&m_addr, &(other.m_addr),
sizeof(m_addr));
187 bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const {
193 std::string ToString()
const;
200 struct sockaddr m_addr;
207 #endif // INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_