owipcalc: fix output formatting quirks

SVN-Revision: 32786
lede-17.01
Jo-Philipp Wich 2012-07-20 15:05:30 +00:00
parent 585ebed25f
commit b2c4924bb4
1 changed files with 35 additions and 14 deletions

View File

@ -224,14 +224,17 @@ static bool cidr_contains4(struct cidr *a, struct cidr *b)
uint32_t net1 = a->addr.v4.s_addr & htonl(~((1 << (32 - a->prefix)) - 1)); uint32_t net1 = a->addr.v4.s_addr & htonl(~((1 << (32 - a->prefix)) - 1));
uint32_t net2 = b->addr.v4.s_addr & htonl(~((1 << (32 - a->prefix)) - 1)); uint32_t net2 = b->addr.v4.s_addr & htonl(~((1 << (32 - a->prefix)) - 1));
if (printed)
qprintf(" ");
if ((b->prefix >= a->prefix) && (net1 == net2)) if ((b->prefix >= a->prefix) && (net1 == net2))
{ {
qprintf("1\n"); qprintf("1");
return true; return true;
} }
else else
{ {
qprintf("0\n"); qprintf("0");
return false; return false;
} }
} }
@ -250,16 +253,19 @@ static bool cidr_private4(struct cidr *a)
{ {
uint32_t x = ntohl(a->addr.v4.s_addr); uint32_t x = ntohl(a->addr.v4.s_addr);
if (printed)
qprintf(" ");
if (((x >= 0x0A000000) && (x <= 0x0AFFFFFF)) || if (((x >= 0x0A000000) && (x <= 0x0AFFFFFF)) ||
((x >= 0xAC100000) && (x <= 0xAC1FFFFF)) || ((x >= 0xAC100000) && (x <= 0xAC1FFFFF)) ||
((x >= 0xC0A80000) && (x <= 0xC0A8FFFF))) ((x >= 0xC0A80000) && (x <= 0xC0A8FFFF)))
{ {
qprintf("1\n"); qprintf("1");
return true; return true;
} }
else else
{ {
qprintf("0\n"); qprintf("0");
return false; return false;
} }
} }
@ -268,14 +274,17 @@ static bool cidr_linklocal4(struct cidr *a)
{ {
uint32_t x = ntohl(a->addr.v4.s_addr); uint32_t x = ntohl(a->addr.v4.s_addr);
if (printed)
qprintf(" ");
if ((x >= 0xA9FE0000) && (x <= 0xA9FEFFFF)) if ((x >= 0xA9FE0000) && (x <= 0xA9FEFFFF))
{ {
qprintf("1\n"); qprintf("1");
return true; return true;
} }
else else
{ {
qprintf("0\n"); qprintf("0");
return false; return false;
} }
} }
@ -526,46 +535,55 @@ static bool cidr_contains6(struct cidr *a, struct cidr *b)
uint8_t net1 = x->s6_addr[15-i] & m; uint8_t net1 = x->s6_addr[15-i] & m;
uint8_t net2 = y->s6_addr[15-i] & m; uint8_t net2 = y->s6_addr[15-i] & m;
if (printed)
qprintf(" ");
if ((b->prefix >= n->prefix) && (net1 == net2) && if ((b->prefix >= n->prefix) && (net1 == net2) &&
((i == 15) || !memcmp(&x->s6_addr, &y->s6_addr, 15-i))) ((i == 15) || !memcmp(&x->s6_addr, &y->s6_addr, 15-i)))
{ {
qprintf("1\n"); qprintf("1");
return true; return true;
} }
else else
{ {
qprintf("0\n"); qprintf("0");
return false; return false;
} }
} }
static bool cidr_linklocal6(struct cidr *a) static bool cidr_linklocal6(struct cidr *a)
{ {
if (printed)
qprintf(" ");
if ((a->addr.v6.s6_addr[0] == 0xFE) && if ((a->addr.v6.s6_addr[0] == 0xFE) &&
(a->addr.v6.s6_addr[1] >= 0x80) && (a->addr.v6.s6_addr[1] >= 0x80) &&
(a->addr.v6.s6_addr[1] <= 0xBF)) (a->addr.v6.s6_addr[1] <= 0xBF))
{ {
qprintf("1\n"); qprintf("1");
return true; return true;
} }
else else
{ {
qprintf("0\n"); qprintf("0");
return false; return false;
} }
} }
static bool cidr_ula6(struct cidr *a) static bool cidr_ula6(struct cidr *a)
{ {
if (printed)
qprintf(" ");
if ((a->addr.v6.s6_addr[0] >= 0xFC) && if ((a->addr.v6.s6_addr[0] >= 0xFC) &&
(a->addr.v6.s6_addr[0] <= 0xFD)) (a->addr.v6.s6_addr[0] <= 0xFD))
{ {
qprintf("1\n"); qprintf("1");
return true; return true;
} }
else else
{ {
qprintf("0\n"); qprintf("0");
return false; return false;
} }
} }
@ -652,10 +670,13 @@ static struct cidr * cidr_parse(const char *op, const char *s, int af_hint)
static bool cidr_howmany(struct cidr *a, struct cidr *b) static bool cidr_howmany(struct cidr *a, struct cidr *b)
{ {
if (printed)
qprintf(" ");
if (b->prefix < a->prefix) if (b->prefix < a->prefix)
qprintf("0\n"); qprintf("0");
else else
qprintf("%u\n", 1 << (b->prefix - a->prefix)); qprintf("%u", 1 << (b->prefix - a->prefix));
return true; return true;
} }