diff options
author | Roger Dingledine <arma@torproject.org> | 2010-10-01 21:31:09 -0400 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2010-10-01 21:31:09 -0400 |
commit | 22f723e4a3fc32983480c7403af9d7e77a3200ea (patch) | |
tree | b33e4fec4ffa0e350e5c4193e050cb3441e2958e /src/common | |
parent | 165aaf560a7249a388e916659d55ec6fa1d2fd24 (diff) | |
download | tor-22f723e4a3fc32983480c7403af9d7e77a3200ea.tar tor-22f723e4a3fc32983480c7403af9d7e77a3200ea.tar.gz |
refactor all these tor_inet_ntoa idioms
but don't refactor the ones that look messy
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/address.c | 12 | ||||
-rw-r--r-- | src/common/address.h | 1 |
2 files changed, 13 insertions, 0 deletions
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 <b>src</b> to a tor_addr_t <b>addr</b>. 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" |