]> granicus.if.org Git - libevent/commitdiff
Filter link-local IPv4 addresses in evutil_found_ifaddr()
authorAzat Khuzhin <a3at.mail@gmail.com>
Wed, 24 Oct 2018 08:51:57 +0000 (11:51 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Wed, 24 Oct 2018 21:06:47 +0000 (00:06 +0300)
Fixes: #668
evutil.c

index 49c9014f7b7021ece394c0e2c6371215bddd319e..6fa24a7c57034dadd15a33300adba888d8013e32 100644 (file)
--- a/evutil.c
+++ b/evutil.c
@@ -599,6 +599,11 @@ static int have_checked_interfaces, had_ipv4_address, had_ipv6_address;
  */
 #define EVUTIL_V4ADDR_IS_LOCALHOST(addr) (((addr)>>24) == 127)
 
+/* Macro: True iff the IPv4 address 'addr', in host order, is link-local
+ * 169.254.0.0/16 (RFC3927)
+ */
+#define EVUTIL_V4ADDR_IS_LINKLOCAL(addr) (((addr) & 0xffff0000U) == 0xa9fe0000U)
+
 /* Macro: True iff the IPv4 address 'addr', in host order, is a class D
  * (multiclass) address.
  */
@@ -615,6 +620,7 @@ evutil_found_ifaddr(const struct sockaddr *sa)
                ev_uint32_t addr = ntohl(sin->sin_addr.s_addr);
                if (addr == 0 ||
                    EVUTIL_V4ADDR_IS_LOCALHOST(addr) ||
+                   EVUTIL_V4ADDR_IS_LINKLOCAL(addr) ||
                    EVUTIL_V4ADDR_IS_CLASSD(addr)) {
                        /* Not actually a usable external address. */
                } else {