From 6e6d95b3db091d4ae107c8d4f03354ccadd20757 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 22 Feb 2005 08:18:36 +0000 Subject: Change from inet_ntoa to a threadproof tor_inet_ntoa. svn:r3656 --- src/common/util.c | 11 +++++++++++ src/common/util.h | 2 ++ 2 files changed, 13 insertions(+) (limited to 'src/common') diff --git a/src/common/util.c b/src/common/util.c index 4b17454e80..339572e449 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1255,6 +1255,17 @@ parse_addr_and_port_range(const char *s, uint32_t *addr_out, return -1; } +int +tor_inet_ntoa(struct in_addr *in, char *buf, size_t buf_len) +{ + uint32_t a = ntohl(in->s_addr); + return tor_snprintf(buf, buf_len, "%d.%d.%d.%d", + (int)(uint8_t)((a>>24)&0xff), + (int)(uint8_t)((a>>16)&0xff), + (int)(uint8_t)((a>>8 )&0xff), + (int)(uint8_t)((a )&0xff)); +} + /* ===== * Process helpers * ===== */ diff --git a/src/common/util.h b/src/common/util.h index 2f139515af..fde2557f58 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -126,6 +126,8 @@ int parse_addr_port(const char *addrport, char **address, uint32_t *addr, int parse_addr_and_port_range(const char *s, uint32_t *addr_out, uint32_t *mask_out, uint16_t *port_min_out, uint16_t *port_max_out); +#define INET_NTOA_BUF_LEN 16 +int tor_inet_ntoa(struct in_addr *in, char *buf, size_t buf_len); /* Process helpers */ void start_daemon(const char *desired_cwd); -- cgit v1.2.3-54-g00ecf