21 #ifndef INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_
22 #define INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_
24 #include <ola/network/IPV4Address.h>
26 #include <sys/socket.h>
43 virtual uint16_t Family()
const = 0;
44 virtual bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const = 0;
45 virtual string ToString()
const = 0;
47 friend ostream& operator<< (ostream &out,
const SocketAddress &address) {
48 return out << address.ToString();
72 m_port(other.m_port) {
79 m_host = other.m_host;
80 m_port = other.m_port;
86 return m_host == other.m_host && m_port == other.m_port;
90 return !(*
this == other);
94 if (m_host == other.m_host)
95 return m_port < other.m_port;
97 return m_host < other.m_host;
100 uint16_t Family()
const {
return AF_INET; }
102 void Host(
const IPV4Address &host) { m_host = host; }
103 uint16_t
Port()
const {
return m_port; }
104 void Port(uint16_t port) { m_port = port; }
106 string ToString()
const {
107 std::ostringstream str;
108 str << Host() <<
":" <<
Port();
118 bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const;
136 memset(reinterpret_cast<uint8_t*>(&m_addr), 0,
sizeof(m_addr));
139 bool IsValid()
const {
140 return Family() != AF_UNSPEC;
143 uint16_t Family()
const {
144 return m_addr.sa_family;
148 if (
this != &other) {
149 memcpy(&m_addr, &(other.m_addr),
sizeof(m_addr));
154 bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const {
160 string ToString()
const;
167 struct sockaddr m_addr;
171 #endif // INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_