]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add fmt_addrport.
authorDavid Fifield <david@bamsoftware.com>
Fri, 5 Oct 2012 02:43:44 +0000 (19:43 -0700)
committerNick Mathewson <nickm@torproject.org>
Thu, 11 Oct 2012 02:25:30 +0000 (22:25 -0400)
This function formats an addr:port pair, and always decorates IPv6
addresses.

src/common/address.c
src/common/address.h

index dffbcaff44a45c3f73fa25f0eb78fd8c283e9f65..9a61872af3b7641dbd144e82a6b99a67b570b8aa 100644 (file)
@@ -1006,6 +1006,19 @@ fmt_addr_impl(const tor_addr_t *addr, int decorate)
     return "???";
 }
 
+/** Return a string representing the pair <b>addr</b> and <b>port</b>.
+ * This calls fmt_and_decorate_addr internally, so IPv6 addresses will
+ * have brackets, and the caveats of fmt_addr_impl apply.
+ */
+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];
+  tor_snprintf(buf, sizeof(buf), "%s:%u", fmt_and_decorate_addr(addr), port);
+  return buf;
+}
+
 /** Like fmt_addr(), but takes <b>addr</b> as a host-order IPv4
  * addresses. Also not thread-safe, also clobbers its return buffer on
  * repeated calls. */
index 7a779d8880c14790fd2b8624c7a14e9a2b0d3523..68775fb291072a60fad256374f08ec0eea3eabb4 100644 (file)
@@ -145,6 +145,7 @@ char *tor_dup_addr(const tor_addr_t *addr) ATTR_MALLOC;
  *  addresses. */
 #define fmt_and_decorate_addr(a) fmt_addr_impl((a), 1)
 const char *fmt_addr_impl(const tor_addr_t *addr, int decorate);
+const char *fmt_addrport(const tor_addr_t *addr, uint16_t port);
 const char * fmt_addr32(uint32_t addr);
 int get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr);