29 #ifndef INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_
30 #define INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_
37 #include <ola/win/CleanWinSock2.h>
39 #include <sys/socket.h>
61 virtual uint16_t Family()
const = 0;
62 virtual bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const = 0;
63 virtual std::string ToString()
const = 0;
65 friend std::ostream& operator<<(std::ostream &out,
67 return out << address.ToString();
93 m_port(other.m_port) {
100 m_host = other.m_host;
101 m_port = other.m_port;
107 return m_host == other.m_host && m_port == other.m_port;
111 return !(*
this == other);
120 if (m_host == other.m_host)
121 return m_port < other.m_port;
123 return m_host < other.m_host;
132 if (m_host == other.m_host)
133 return m_port > other.m_port;
135 return m_host > other.m_host;
138 uint16_t Family()
const {
return AF_INET; }
140 void Host(
const IPV4Address &host) { m_host = host; }
141 uint16_t Port()
const {
return m_port; }
142 void Port(uint16_t port) { m_port = port; }
144 std::string ToString()
const;
146 static bool FromString(
const std::string &str,
147 IPV4SocketAddress *socket_address);
150 static IPV4SocketAddress FromStringOrDie(
const std::string &address);
152 bool ToSockAddr(
struct sockaddr *addr,
unsigned int size)
const;
172 memset(reinterpret_cast<uint8_t*>(&m_addr), 0,
sizeof(m_addr));
175 bool IsValid()
const;
177 uint16_t Family()
const {
178 return m_addr.sa_family;
182 if (
this != &other) {
183 memcpy(&m_addr, &(other.m_addr),
sizeof(m_addr));
188 bool ToSockAddr(
struct sockaddr *addr,
194 std::string ToString()
const;
201 struct sockaddr m_addr;
208 #endif // INCLUDE_OLA_NETWORK_SOCKETADDRESS_H_
IPV4SocketAddress V4Addr() const
Definition: SocketAddress.cpp:121
Represents a IPv4 Address.
Definition: IPV4Address.h:55
#define OLA_UNUSED
Mark unused arguments & types.
Definition: Macro.h:62
bool operator<(const IPV4SocketAddress &other) const
Less than operator for partial ordering.
Definition: SocketAddress.h:119
Represents an IPv4 Address.
bool ToSockAddr(struct sockaddr *addr, unsigned int size) const
Definition: SocketAddress.cpp:55
static bool FromString(const std::string &str, IPV4SocketAddress *socket_address)
Definition: SocketAddress.cpp:74
bool operator>(const IPV4SocketAddress &other) const
Greater than operator.
Definition: SocketAddress.h:131
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
The base SocketAddress.
Definition: SocketAddress.h:57
An IPv4 SocketAddress.
Definition: SocketAddress.h:77
a Generic Socket Address
Definition: SocketAddress.h:165