summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2005-08-26 07:37:07 +0000
committerRoger Dingledine <arma@torproject.org>2005-08-26 07:37:07 +0000
commitd5e426ab51b7fec1f7411da2c10b08d651846aee (patch)
tree5762f6c0ff9a83f9d37738bcc6a647452e40c644 /src/common/util.c
parente68bed87822f2dd1854c46609cd501746297415f (diff)
downloadtor-d5e426ab51b7fec1f7411da2c10b08d651846aee.tar.gz
tor-d5e426ab51b7fec1f7411da2c10b08d651846aee.zip
add a tor_dup_addr() function to simplify malloc()+tor_inet_ntoa()
svn:r4838
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index acc5cb9d44..280f161d4c 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1314,6 +1314,20 @@ tor_inet_ntoa(struct in_addr *in, char *buf, size_t buf_len)
(int)(uint8_t)((a )&0xff));
}
+/** Given a host-order <b>addr</b>, call tor_inet_ntoa() on it
+ * and return a strdup of the resulting address.
+ */
+char *
+tor_dup_addr(uint32_t addr)
+{
+ char buf[INET_NTOA_BUF_LEN];
+ struct in_addr in;
+
+ in.s_addr = htonl(addr);
+ tor_inet_ntoa(&in, buf, sizeof(buf));
+ return tor_strdup(buf);
+}
+
/* Return true iff <b>name</b> looks like it might be a hostname or IP
* address of some kind. */
int