[gssdp] net: Add list_devices() function



commit 2a4e3b8bc26d3e40bc7429da3f95c4738752d6a5
Author: Jens Georg <mail jensge org>
Date:   Tue Jan 15 10:29:11 2019 +0100

    net: Add list_devices() function

 libgssdp/gssdp-net-bionic.c |  6 ++++++
 libgssdp/gssdp-net-posix.c  | 28 ++++++++++++++++++++++++++++
 libgssdp/gssdp-net-win32.c  |  6 ++++++
 libgssdp/gssdp-net.h        |  3 +++
 4 files changed, 43 insertions(+)
---
diff --git a/libgssdp/gssdp-net-bionic.c b/libgssdp/gssdp-net-bionic.c
index a24aa7f..62edeb3 100644
--- a/libgssdp/gssdp-net-bionic.c
+++ b/libgssdp/gssdp-net-bionic.c
@@ -318,3 +318,9 @@ success:
         close (sock);
         return TRUE;
 }
+
+GList *
+gssdp_net_list_devices (void)
+{
+        return NULL;
+}
diff --git a/libgssdp/gssdp-net-posix.c b/libgssdp/gssdp-net-posix.c
index e5a1dc2..e6e4f20 100644
--- a/libgssdp/gssdp-net-posix.c
+++ b/libgssdp/gssdp-net-posix.c
@@ -551,3 +551,31 @@ gssdp_net_get_host_ip (GSSDPNetworkDevice *device)
 
         return TRUE;
 }
+
+GList *
+gssdp_net_list_devices (void)
+{
+        struct ifaddrs *ifa_list, *ifa;
+        GList *result = NULL;
+
+        if (getifaddrs (&ifa_list) != 0) {
+                g_warning ("Failed to retrieve list of network interfaces: %s",
+                           strerror (errno));
+
+                return result;
+        }
+
+        for (ifa = ifa_list; ifa != NULL; ifa = ifa->ifa_next) {
+                /* Filter for network devices - don't care for addresses */
+                if (ifa->ifa_addr->sa_family != AF_PACKET) {
+                        continue;
+                }
+
+                result = g_list_prepend (result, g_strdup (ifa->ifa_name));
+        }
+
+
+        freeifaddrs (ifa_list);
+
+        return g_list_reverse (result);
+}
diff --git a/libgssdp/gssdp-net-win32.c b/libgssdp/gssdp-net-win32.c
index e0c2071..83495c2 100644
--- a/libgssdp/gssdp-net-win32.c
+++ b/libgssdp/gssdp-net-win32.c
@@ -230,3 +230,9 @@ gssdp_net_get_host_ip (GSSDPNetworkDevice *device)
 
         return TRUE;
 }
+
+GList *
+gssdp_net_list_devices (void)
+{
+        return NULL;
+}
diff --git a/libgssdp/gssdp-net.h b/libgssdp/gssdp-net.h
index 59e87c0..b88d032 100644
--- a/libgssdp/gssdp-net.h
+++ b/libgssdp/gssdp-net.h
@@ -63,4 +63,7 @@ G_GNUC_INTERNAL char*
 gssdp_net_mac_lookup            (GSSDPNetworkDevice *device,
                                  const char *ip_address);
 
+G_GNUC_INTERNAL GList*
+gssdp_net_list_devices          (void);
+
 #endif /* GSSDP_NET_H */


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