diff options
Diffstat (limited to 'src/lib/net')
-rw-r--r-- | src/lib/net/address.c | 3 | ||||
-rw-r--r-- | src/lib/net/address.h | 9 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/lib/net/address.c b/src/lib/net/address.c index 4193053ee1..437ffe652e 100644 --- a/src/lib/net/address.c +++ b/src/lib/net/address.c @@ -1188,8 +1188,7 @@ fmt_addr_impl(const tor_addr_t *addr, int decorate) const char * fmt_addrport(const tor_addr_t *addr, uint16_t port) { - /* Add space for a colon and up to 5 digits. */ - static char buf[TOR_ADDR_BUF_LEN + 6]; + static char buf[TOR_ADDRPORT_BUF_LEN]; tor_snprintf(buf, sizeof(buf), "%s:%u", fmt_and_decorate_addr(addr), port); return buf; } diff --git a/src/lib/net/address.h b/src/lib/net/address.h index b5754087cc..e5016ee4fe 100644 --- a/src/lib/net/address.h +++ b/src/lib/net/address.h @@ -213,6 +213,15 @@ tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u) */ #define TOR_ADDR_BUF_LEN 48 +/** Length of a buffer containing an IP address along with a port number and + * a seperating colon. + * + * This allows enough space for + * "[ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255]:12345", + * plus a terminating NUL. + */ +#define TOR_ADDRPORT_BUF_LEN (TOR_ADDR_BUF_LEN + 6) + char *tor_addr_to_str_dup(const tor_addr_t *addr) ATTR_MALLOC; /** Wrapper function of fmt_addr_impl(). It does not decorate IPv6 |