[or-cvs] Generate 18.0.0.0/8 address policy format in descs when we ...

Nick Mathewson nickm at seul.org
Sun Feb 12 23:58:25 UTC 2006


Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv30154/src/common

Modified Files:
	util.c util.h 
Log Message:
Generate 18.0.0.0/8 address policy format in descs when we can; warn when the mask is not reducible to a bit-prefix.

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.c,v
retrieving revision 1.244
retrieving revision 1.245
diff -u -p -d -r1.244 -r1.245
--- util.c	9 Feb 2006 05:46:48 -0000	1.244
+++ util.c	12 Feb 2006 23:58:22 -0000	1.245
@@ -1420,6 +1420,20 @@ parse_addr_port(const char *addrport, ch
   return ok ? 0 : -1;
 }
 
+/** If <b>mask</b> is an address mask for a bit-prefix, return the number of
+ * bits.  Otherwise, return -1. */
+int
+addr_mask_get_bits(uint32_t mask)
+{
+  int i;
+  for (i=0; i<=32; ++i) {
+    if (mask == ~((1<<(32-i))-1)) {
+      return i;
+    }
+  }
+  return -1;
+}
+
 /** Parse a string <b>s</b> in the format of
  * (IP(/mask|/mask-bits)?|*):(*|port(-maxport)?), setting the various
  * *out pointers as appropriate.  Return 0 on success, -1 on failure.

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.h,v
retrieving revision 1.152
retrieving revision 1.153
diff -u -p -d -r1.152 -r1.153
--- util.h	9 Feb 2006 05:46:48 -0000	1.152
+++ util.h	12 Feb 2006 23:58:22 -0000	1.153
@@ -168,6 +168,7 @@ int parse_addr_port(const char *addrport
 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);
+int addr_mask_get_bits(uint32_t mask);
 #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);



More information about the tor-commits mailing list