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);
114 if (m_host == other.m_host)
115 return m_port < other.m_port;
117 return m_host < other.m_host;
120 uint16_t Family()
const {
return AF_INET; }
122 void Host(
const IPV4Address &host) { m_host = host; }
123 uint16_t
Port()
const {
return m_port; }
124 void Port(uint16_t port) { m_port = port; }
126 std::string ToString()
const;
128 static bool FromString(
const std::string &str,
134 bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const;
154 memset(reinterpret_cast<uint8_t*>(&m_addr), 0,
sizeof(m_addr));
157 bool IsValid()
const;
159 uint16_t Family()
const {
160 return m_addr.sa_family;
164 if (
this != &other) {
165 memcpy(&m_addr, &(other.m_addr),
sizeof(m_addr));
170 bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const {
176 std::string ToString()
const;
183 struct sockaddr m_addr;
190 #endif // INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_