
On 01/15/2015 04:25 AM, Cédric Bosdonnat wrote:
If 0.0.0.0 address is provided, then the returned prefix should be 0, rather than 8. --- src/util/virsocketaddr.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index c5584af..e7870bf 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -832,6 +832,12 @@ virSocketAddrGetIpPrefix(const virSocketAddr *address, */ unsigned char octet = ntohl(address->data.inet4.sin_addr.s_addr) >> 24; + + /* If address is 0.0.0.0, we surely want to have 0 prefix for + * the default route. */ + if (address->data.inet4.sin_addr.s_addr == 0) + return 0; + if ((octet & 0x80) == 0) { /* Class A network */ return 8;
So it seems after Laine's comments on this you added: + if (address->data.inet6.sin6_addr.s6_addr == 0) + return 0; which Coverity flags as: 852 } else if (VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET6)) { (1) Event array_null: Comparing an array to null is not useful: "address->data.inet6.sin6_addr.__in6_u.__u6_addr8 == NULL". 853 if (address->data.inet6.sin6_addr.s6_addr == 0) Since s6_addr is a pointer - is this supposed to be a NULL comparison or perhaps are you looking for a specific character [0] or all characters being 0? John