[libvirt] [PATCHv2 5/7] virSocketAddrGetIpPrefix 0.0.0.0 special case

Cédric Bosdonnat cbosdonnat at suse.com
Thu Jan 15 09:25:45 UTC 2015


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;
-- 
2.1.2




More information about the libvir-list mailing list