diff --git a/gms/inet_address.hh b/gms/inet_address.hh index b1359f7a38..f1ca1a7bbd 100644 --- a/gms/inet_address.hh +++ b/gms/inet_address.hh @@ -89,3 +89,19 @@ struct hash { size_t operator()(gms::inet_address a) const noexcept { return std::hash()(a._addr); } }; } + +template <> +struct fmt::formatter : fmt::formatter { + template + auto format(const ::gms::inet_address& x, FormatContext& ctx) const { + if (x.addr().is_ipv4()) { + return fmt::format_to(ctx.out(), "{}", x.addr()); + } + // print 2 bytes in a group, and use ':' as the delimeter + format_to(ctx.out(), "{:2:}", fmt_hex(x.bytes())); + if (x.addr().scope() != seastar::net::inet_address::invalid_scope) { + return format_to(ctx.out(), "%{}", x.addr().scope()); + } + return ctx.out(); + } +};