Add to/from in6_addr to SockAddr

pull/1261/head
Stephen Shelton 4 years ago
parent fd145d6eeb
commit dfe71309f1
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -152,13 +152,23 @@ namespace llarp
IpAddress
AddressInfo::toIpAddress() const
{
throw std::runtime_error("FIXME - AddressInfo::toIpAddress()");
SockAddr addr(ip);
addr.setPort(port);
return IpAddress(addr);
}
void
AddressInfo::fromIpAddress(const IpAddress& address)
{
throw std::runtime_error("FIXME - AddressInfo::fromIpAddress()");
SockAddr addr = address.createSockAddr();
const sockaddr_in6* addr6 = addr;
memcpy(ip.s6_addr, addr6->sin6_addr.s6_addr, sizeof(ip.s6_addr));
auto maybePort = address.getPort();
if (maybePort)
port = maybePort.value();
else
port = 0;
}
std::ostream&

@ -120,6 +120,23 @@ namespace llarp
return *this;
}
SockAddr::SockAddr(const in6_addr& addr)
{
*this = addr;
}
SockAddr&
SockAddr::operator=(const in6_addr& other)
{
init();
memcpy(&m_addr.sin6_addr.s6_addr, &other.s6_addr, sizeof(m_addr.sin6_addr.s6_addr));
m_empty = false;
return *this;
}
SockAddr::operator const sockaddr*() const
{
return (sockaddr*)&m_addr;

@ -32,6 +32,10 @@ namespace llarp
SockAddr&
operator=(const sockaddr_in6& addr);
SockAddr(const in6_addr& addr);
SockAddr&
operator=(const in6_addr& addr);
operator const sockaddr*() const;
operator const sockaddr_in6*() const;

Loading…
Cancel
Save