summaryrefslogtreecommitdiff
path: root/src/or/router.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-02-12 23:58:22 +0000
committerNick Mathewson <nickm@torproject.org>2006-02-12 23:58:22 +0000
commitdba155ecfff1739bc263398a38eb92c10aa643ec (patch)
tree06d66f0f8dcbb12ceb1b6accb82028777732144a /src/or/router.c
parentb99f903e34b1d2b4548937480d2345ab4753454f (diff)
downloadtor-dba155ecfff1739bc263398a38eb92c10aa643ec.tar.gz
tor-dba155ecfff1739bc263398a38eb92c10aa643ec.zip
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.
svn:r5991
Diffstat (limited to 'src/or/router.c')
-rw-r--r--src/or/router.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/or/router.c b/src/or/router.c
index bf8a36ab93..1ec3e16329 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -1111,13 +1111,18 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
return -1;
written += result;
if (tmpe->msk != 0xFFFFFFFFu && tmpe->msk != 0) {
- /* Write "/255.255.0.0" */
- in.s_addr = htonl(tmpe->msk);
- tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf));
- result = tor_snprintf(s+written, maxlen-written, "/%s", addrbuf);
- if (result<0)
- return -1;
- written += result;
+ int n_bits = addr_mask_get_bits(tmpe->msk);
+ if (n_bits >= 0) {
+ if (tor_snprintf(s+written, maxlen-written, "/%d", n_bits)<0)
+ return -1;
+ } else {
+ /* Write "/255.255.0.0" */
+ in.s_addr = htonl(tmpe->msk);
+ tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf));
+ if (tor_snprintf(s+written, maxlen-written, "/%s", addrbuf)<0)
+ return -1;
+ }
+ written += strlen(s+written);
}
if (tmpe->prt_min <= 1 && tmpe->prt_max == 65535) {
/* There is no port set; write ":*" */