[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Add fmt_addrport.



commit 78e2d8c7a85c8ec2defe5d1873ae19ba9b82b14c
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Thu Oct 4 19:43:44 2012 -0700

    Add fmt_addrport.
    
    This function formats an addr:port pair, and always decorates IPv6
    addresses.
---
 src/common/address.c |   13 +++++++++++++
 src/common/address.h |    1 +
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/common/address.c b/src/common/address.c
index dffbcaf..9a61872 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -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. */
diff --git a/src/common/address.h b/src/common/address.h
index 7a779d8..68775fb 100644
--- a/src/common/address.h
+++ b/src/common/address.h
@@ -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);
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits