From 22f723e4a3fc32983480c7403af9d7e77a3200ea Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Fri, 1 Oct 2010 21:31:09 -0400 Subject: refactor all these tor_inet_ntoa idioms but don't refactor the ones that look messy --- src/common/address.c | 12 ++++++++++++ src/common/address.h | 1 + 2 files changed, 13 insertions(+) (limited to 'src/common') diff --git a/src/common/address.c b/src/common/address.c index c35f04c18..dfe8f518e 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -927,6 +927,18 @@ fmt_addr(const tor_addr_t *addr) return buf; } +/** Like fmt_addr(), but for IPv4 addresses. Also not thread-safe, also + * clobbers its return buffer on repeated calls. */ +const char * +fmt_addr32(uint32_t addr) +{ + static char buf[INET_NTOA_BUF_LEN]; + struct in_addr in; + in.s_addr = htonl(addr); + tor_inet_ntoa(&in, buf, sizeof(buf)); + return buf; +} + /** Convert the string in src to a tor_addr_t addr. The string * may be an IPv4 address, an IPv6 address, or an IPv6 address surrounded by * square brackets. diff --git a/src/common/address.h b/src/common/address.h index 6116bb4b1..9a3c3ef60 100644 --- a/src/common/address.h +++ b/src/common/address.h @@ -108,6 +108,7 @@ tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u) int tor_addr_lookup(const char *name, uint16_t family, tor_addr_t *addr_out); char *tor_dup_addr(const tor_addr_t *addr) ATTR_MALLOC; const char *fmt_addr(const tor_addr_t *addr); +const char * fmt_addr32(uint32_t addr); int get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr); /** Flag to specify how to do a comparison between addresses. In an "exact" -- cgit v1.2.3