On Thu, Jun 06, 2013 at 05:27:46PM +0200, Jiri Denemark wrote:
On Thu, Jun 06, 2013 at 16:10:29 +0200, Michal Privoznik wrote:
> This internal API checks, if passed address is ANYCAST address.
> ---
> src/libvirt_private.syms | 1 +
> src/util/virsocketaddr.c | 22 ++++++++++++++++++++++
> src/util/virsocketaddr.h | 1 +
> tests/sockettest.c | 38 ++++++++++++++++++++++++++++++++++++++
> 4 files changed, 62 insertions(+)
>
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index b93629f..0b2ce42 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -1780,6 +1780,7 @@ virSocketAddrFormatFull;
> virSocketAddrGetIpPrefix;
> virSocketAddrGetPort;
> virSocketAddrGetRange;
> +virSocketAddrIsAny;
> virSocketAddrIsNetmask;
> virSocketAddrIsPrivate;
> virSocketAddrMask;
> diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
> index 1071b00..4bfc86d 100644
> --- a/src/util/virsocketaddr.c
> +++ b/src/util/virsocketaddr.c
> @@ -227,6 +227,28 @@ virSocketAddrIsPrivate(const virSocketAddrPtr addr)
> }
>
> /*
> + * virSocketAddrIsAny:
> + * @addr: address to check
> + *
> + * Check if passed address is a variant of ANYCAST address.
> + */
> +bool
> +virSocketAddrIsAny(const virSocketAddrPtr addr)
> +{
> + unsigned long tmp;
> + switch (addr->data.stor.ss_family) {
> + case AF_INET:
> + tmp = INADDR_ANY;
> + return memcmp(&addr->data.inet4.sin_addr.s_addr, &tmp,
> + sizeof(addr->data.inet4.sin_addr.s_addr)) == 0;
> + case AF_INET6:
> + return memcmp(addr->data.inet6.sin6_addr.s6_addr, &in6addr_any,
> + sizeof(addr->data.inet6.sin6_addr.s6_addr)) == 0;
> + }
> + return false;
Or just use 'inaddr_any
Shouldn't we use in_addr_t (or uint32_t at least) for tmp rather
than
unsigned long and
Yep, 'struct in_addr' is preferrable.
IN6_IS_ADDR_UNSPECIFIED(&addr->data.inet6.sin6_addr.s6_addr)
instead of the second memcmp? However, I'm not sure how portable that
would be... in.h(0P) man page says both of them shall be defined in
netinet/in.h
It seems to be present in mingw64 headers, so that's a good sign
of portability.
> diff --git a/tests/sockettest.c b/tests/sockettest.c
> index 5b36a6c..e4a998b 100644
> --- a/tests/sockettest.c
> +++ b/tests/sockettest.c
> @@ -157,6 +157,28 @@ static int testNetmaskHelper(const void *opaque)
> return testNetmask(data->addr1, data->addr2, data->netmask,
data->pass);
> }
>
> +static int testAnycast(const char *addrstr,
> + bool pass)
I'd probably use a different name since "anycast" has different meaning
in IPv6 world but I don't mind that much as I can't think of a better
name :-)
Use 'Wildcard' instead of 'Anycast'
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|