lokinet/llarp/quic/address.cpp

50 lines
970 B
C++
Raw Normal View History

2021-03-10 15:11:42 +00:00
#include "address.hpp"
#include <cstring>
2021-03-10 15:11:42 +00:00
#include <iostream>
namespace llarp::quic
{
using namespace std::literals;
Address::Address(service::ConvoTag tag) : saddr{tag.ToV6()}
{}
2021-03-10 15:11:42 +00:00
Address&
Address::operator=(const Address& other)
2021-03-10 15:11:42 +00:00
{
std::memmove(&saddr, &other.saddr, sizeof(saddr));
a.addrlen = other.a.addrlen;
2021-03-10 15:11:42 +00:00
return *this;
}
service::ConvoTag
Address::Tag() const
{
service::ConvoTag tag{};
tag.FromV6(saddr);
return tag;
}
2021-03-10 15:11:42 +00:00
std::string
Address::to_string() const
{
if (a.addrlen != sizeof(sockaddr_in6))
2021-03-10 15:11:42 +00:00
return "(unknown-addr)";
char buf[INET6_ADDRSTRLEN] = {0};
inet_ntop(AF_INET6, &saddr.sin6_addr, buf, INET6_ADDRSTRLEN);
return buf;
2021-03-10 15:11:42 +00:00
}
std::ostream&
operator<<(std::ostream& o, const Address& a)
{
return o << a.to_string();
}
std::ostream&
operator<<(std::ostream& o, const Path& p)
{
return o << p.local << "<-" << p.remote;
}
} // namespace llarp::quic