From 504b16fb757d14f58e20294f7aca338dc6826140 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 7 May 2020 20:59:10 +1000 Subject: relay: Rewrite inform_testing_reachability() Rewrite inform_testing_reachability() to use separate buffers for IPv4 ORPort, IPv6 ORPort, and IPv4 DirPort. And use consistent APIs to fill those buffers. Part of 33222. --- src/lib/net/address.c | 11 +++++++++++ src/lib/net/address.h | 1 + 2 files changed, 12 insertions(+) (limited to 'src/lib') diff --git a/src/lib/net/address.c b/src/lib/net/address.c index 7f63593875..76c7aadd22 100644 --- a/src/lib/net/address.c +++ b/src/lib/net/address.c @@ -1206,6 +1206,17 @@ fmt_addr32(uint32_t addr) return buf; } +/** Like fmt_addrport(), but takes addr as a host-order IPv4 + * addresses. Also not thread-safe, also clobbers its return buffer on + * repeated calls. */ +const char * +fmt_addr32_port(uint32_t addr, uint16_t port) +{ + static char buf[INET_NTOA_BUF_LEN + 6]; + snprintf(buf, sizeof(buf), "%s:%u", fmt_addr32(addr), port); + return buf; +} + /** Return a string representing family. * * This string is a string constant, and must not be freed. diff --git a/src/lib/net/address.h b/src/lib/net/address.h index eca5ddab75..5ab654ef1d 100644 --- a/src/lib/net/address.h +++ b/src/lib/net/address.h @@ -236,6 +236,7 @@ const char *fmt_addr_impl(const tor_addr_t *addr, int decorate); const char *fmt_addrport(const tor_addr_t *addr, uint16_t port); #define fmt_addrport_ap(ap) fmt_addrport(&(ap)->addr, (ap)->port) const char *fmt_addr32(uint32_t addr); +const char *fmt_addr32_port(uint32_t addr, uint16_t port); const char *fmt_af_family(sa_family_t family); const char *fmt_addr_family(const tor_addr_t *addr); -- cgit v1.2.3-54-g00ecf