mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
virSocketAddrGetIpPrefix 0.0.0.0 and :: special cases
If 0.0.0.0 or :: address is provided, then the returned prefix should be 0, for the default address.
This commit is contained in:
parent
a117652917
commit
3993c2f91c
@ -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;
|
||||
@ -844,6 +850,8 @@ virSocketAddrGetIpPrefix(const virSocketAddr *address,
|
||||
}
|
||||
return -1;
|
||||
} else if (VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET6)) {
|
||||
if (address->data.inet6.sin6_addr.s6_addr == 0)
|
||||
return 0;
|
||||
return 64;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user