[PATCHv2 5/7] virSocketAddrGetIpPrefix 0.0.0.0 special case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]