[gupnp] linux-cm: Fix address filtering by scope



commit 476df77c82b612fb1573b8f8f967314b9c46d20a
Author: Jens Georg <mail jensge org>
Date:   Tue Nov 20 23:32:54 2018 +0100

    linux-cm: Fix address filtering by scope
    
    Apparently the scope id is only global, link or host, but never site
    even with ULAs

 libgupnp/gupnp-linux-context-manager.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
---
diff --git a/libgupnp/gupnp-linux-context-manager.c b/libgupnp/gupnp-linux-context-manager.c
index 68198b4..563c0c9 100644
--- a/libgupnp/gupnp-linux-context-manager.c
+++ b/libgupnp/gupnp-linux-context-manager.c
@@ -442,16 +442,20 @@ extract_info (struct nlmsghdr *header,
                         *label = g_strdup ((char *) RTA_DATA (rt_attr));
                 } else if (rt_attr->rta_type == IFA_ADDRESS) {
                         if (address != NULL) {
-                                const char *result = NULL;
-                                result = inet_ntop (family,
-                                           RTA_DATA (rt_attr),
-                                           buf,
-                                           sizeof (buf));
-                                if (result == NULL) {
-                                    g_critical ("Failed ntop: %m");
+                                GInetAddress *addr;
+
+                                *address = NULL;
+                                addr = g_inet_address_new_from_bytes (RTA_DATA (rt_attr), family);
+                                if (family == AF_INET) {
+                                        *address = g_inet_address_to_string (addr);
                                 } else {
-                                    *address = g_strdup (result);
+                                        if (g_inet_address_get_is_link_local (addr) ||
+                                            g_inet_address_get_is_loopback (addr) ||
+                                            g_inet_address_get_is_site_local (addr)) {
+                                                *address = g_inet_address_to_string (addr);
+                                        }
                                 }
+                                g_object_unref (addr);
                         }
 
                         if (mask != NULL) {
@@ -824,11 +828,6 @@ receive_netlink_message (GUPnPLinuxContextManager *self, GError **error)
 
                                 g_debug ("Received RTM_NEWADDR");
                                 ifa = NLMSG_DATA (header);
-                                if (ifa->ifa_family == AF_INET6 &&
-                                        (ifa->ifa_scope != RT_SCOPE_SITE &&
-                                         ifa->ifa_scope != RT_SCOPE_LINK &&
-                                         ifa->ifa_scope != RT_SCOPE_HOST))
-                                        break;
 
                                 extract_info (header,
                                               priv->dump_netlink_packets,


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