Skip to content

Commit 556388e

Browse files
committed
ipv6-range: Only calculate number of /56s when appropriate
Commit e61762e ("ipv6-range: Display number of /56's where appropriate" started displaying the number of /56 networks a given network provides, however this broke when given a prefixlen of > 56, e.g ./ipv6-range 2001:db8:abc:cc00::/60 Network : 2001:db8:abc:cc00::/60 (268435456 /56 networks, 16 /64 networks) Start : 2001:0db8:0abc:cc00:0000:0000:0000:0000 End : 2001:0db8:0abc:cccf:ffff:ffff:ffff:ffff So only display the number of /56s when the prefixlen is < 56, e.g ./ipv6-range 2001:db8:abc:cc00::/60 Network : 2001:db8:abc:cc00::/60 (16 /64 networks) Start : 2001:0db8:0abc:cc00:0000:0000:0000:0000 End : 2001:0db8:0abc:cc0f:ffff:ffff:ffff:ffff ./ipv6-range 2001:db8:abc::/48 Network : 2001:db8:abc::/48 (256 /56 networks, 65536 /64 networks) Start : 2001:0db8:0abc:0000:0000:0000:0000:0000 End : 2001:0db8:0abc:ffff:ffff:ffff:ffff:ffff Signed-off-by: Andrew Clayton <[email protected]>
1 parent 27f0d1f commit 556388e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

ipv6-range.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,19 @@ static void ipv6_range(const char *network, unsigned short prefixlen)
4343
}
4444

4545
/*
46-
* For a prefix length of < 64, calculate the number of /64 networks
47-
* the given network provides. E.g a /48 provides 65536 /64's
46+
* For a prefix length of < 56, calculate the number of /56 and
47+
* /64 networks the given network provides. E.g a /48 provides
48+
* 256 /56 and 65536 /64 networks.
49+
*
50+
* For a prefix length of < 64, just display the nubmer of /64s.
4851
*/
49-
if (prefixlen < 64)
52+
if (prefixlen < 56)
5053
snprintf(net_s, sizeof(net_s), "(%u /56 networks, "
5154
"%zu /64 networks)", 1 << (56 - prefixlen),
5255
(networks >> prefixlen) + 1);
56+
else if (prefixlen < 64)
57+
snprintf(net_s, sizeof(net_s), "(%zu /64 networks)",
58+
(networks >> prefixlen) + 1);
5359

5460
printf("Network : %s/%u %s\n", network, prefixlen, net_s);
5561
printf("Start : ");

0 commit comments

Comments
 (0)