29 #ifndef INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_
30 #define INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_
34 #include <sys/socket.h>
55 virtual uint16_t Family()
const = 0;
56 virtual bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const = 0;
57 virtual std::string ToString()
const = 0;
59 friend std::ostream& operator<<(std::ostream &out,
61 return out << address.ToString();
87 m_port(other.m_port) {
94 m_host = other.m_host;
95 m_port = other.m_port;
101 return m_host == other.m_host && m_port == other.m_port;
105 return !(*
this == other);
109 if (m_host == other.m_host)
110 return m_port < other.m_port;
112 return m_host < other.m_host;
115 uint16_t Family()
const {
return AF_INET; }
117 void Host(
const IPV4Address &host) { m_host = host; }
118 uint16_t
Port()
const {
return m_port; }
119 void Port(uint16_t port) { m_port = port; }
121 std::string ToString()
const;
123 static bool FromString(
const std::string &str,
129 bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const;
149 memset(reinterpret_cast<uint8_t*>(&m_addr), 0,
sizeof(m_addr));
152 bool IsValid()
const;
154 uint16_t Family()
const {
155 return m_addr.sa_family;
159 if (
this != &other) {
160 memcpy(&m_addr, &(other.m_addr),
sizeof(m_addr));
165 bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const {
171 std::string ToString()
const;
178 struct sockaddr m_addr;
185 #endif // INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_