Add a net::ToString() to help stringify ipaddr_t

Android, in particular, has problems with fmt's built-in variant
handling for this type for some reason.
pull/2008/head
Jason Rhinelander 2 years ago
parent 25d73d627a
commit bc071231c8
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262

@ -10,6 +10,6 @@ namespace llarp::net
name,
index,
fmt::join(addrs, ","),
gateway ? fmt::format("{}", *gateway) : "none");
gateway ? net::ToString(*gateway) : "none");
}
} // namespace llarp::net

@ -1,6 +1,7 @@
#include "net_int.hpp"
#include "ip.hpp"
#include <string>
#include <variant>
#include <oxenc/endian.h>
@ -155,4 +156,11 @@ namespace llarp
{
return std::to_string(ntohs(n));
}
std::string
net::ToString(const ipaddr_t& ipaddr)
{
return std::visit([](const auto& ip) { return ip.ToString(); }, ipaddr);
}
} // namespace llarp

@ -230,6 +230,9 @@ namespace llarp
using ipv6addr_t = n_uint128_t;
using ipaddr_t = std::variant<ipv4addr_t, ipv6addr_t>;
std::string
ToString(const ipaddr_t& ip);
huint16_t ToHost(port_t);
huint32_t ToHost(ipv4addr_t);
huint128_t ToHost(ipv6addr_t);

Loading…
Cancel
Save