----- Original Message -----
This new function returns true if the given address is in the range
of
any "private" or "local" networks as defined in RFC1918 (IPv4) or
RFC3484/RFC4193 (IPv6), otherwise they return false.
These ranges are:
192.168.0.0/16
172.16.0.0/16
10.0.0.0/24
FC00::/7
FEC0::/10
---
src/libvirt_private.syms | 1 +
src/util/virsocketaddr.c | 34 +++++++++++++++++++++++++++++++++-
src/util/virsocketaddr.h | 3 ++-
3 files changed, 36 insertions(+), 2 deletions(-)
/*
+ * virSocketAddrIsPrivate:
+ * @s: the location of the IP address
+ *
+ * Return true if this address is in its family's defined
+ * "private/local" address space. For IPv4, private addresses are in
+ * the range of 192.168.0.0/16, 172.16.0.0/16, or 10.0.0.0/8. For
+ * IPv6, local addresses are in the range of FC00::/7.
+ *
+ * See RFC1918 and RFC4193 for details.
Did you intend to update this comment to match the commit message
regarding FEC0::/10?
+ */
+bool
+virSocketAddrIsPrivate(const virSocketAddrPtr addr)
+{
+ unsigned long val;
+
+ switch (addr->data.stor.ss_family) {
+ case AF_INET:
+ val = ntohl(addr->data.inet4.sin_addr.s_addr);
+
+ return ((val & 0xFFFF0000) == ((192L << 24) + (168 << 16)) ||
+ (val & 0xFFFF0000) == ((172L << 24) + (16 << 16)) ||
+ (val & 0xFF000000) == ((10L << 24)));
+
+ case AF_INET6:
+ return ((addr->data.inet6.sin6_addr.s6_addr[0] & 0xFC) ==
0xFC ||
Isn't this FC00::/6? You should be using '& 0xFE' for /7.
ACK with those fixes.