[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] add a tor_dup_addr() function to simplify malloc()+tor_inet...
Update of /home2/or/cvsroot/tor/src/common
In directory moria:/home/arma/work/onion/cvs/tor/src/common
Modified Files:
compat.c util.c util.h
Log Message:
add a tor_dup_addr() function to simplify malloc()+tor_inet_ntoa()
Index: compat.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/compat.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- compat.c 22 Aug 2005 00:34:23 -0000 1.64
+++ compat.c 26 Aug 2005 07:37:07 -0000 1.65
@@ -579,6 +579,7 @@
* something.
*/
struct in_addr iaddr;
+ tor_assert(name);
tor_assert(addr);
if (!*name) {
/* Empty address is an error. */
Index: util.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/util.c,v
retrieving revision 1.215
retrieving revision 1.216
diff -u -d -r1.215 -r1.216
--- util.c 12 Aug 2005 17:24:53 -0000 1.215
+++ util.c 26 Aug 2005 07:37:07 -0000 1.216
@@ -1314,6 +1314,20 @@
(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
Index: util.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/util.h,v
retrieving revision 1.135
retrieving revision 1.136
diff -u -d -r1.135 -r1.136
--- util.h 3 Aug 2005 20:42:17 -0000 1.135
+++ util.h 26 Aug 2005 07:37:07 -0000 1.136
@@ -134,6 +134,7 @@
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);
+char *tor_dup_addr(uint32_t addr);
int is_plausible_address(const char *name);
int get_interface_address(uint32_t *addr);