| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#define G_LOG_DOMAIN "gupnp-unix-context-manager" |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <config.h> |
| 21 |
#include <errno.h> |
| 22 |
#include <string.h> |
| 23 |
#include <unistd.h> |
| 24 |
#include <fcntl.h> |
| 25 |
#include <stdlib.h> |
| 26 |
#include <stdio.h> |
| 27 |
#include <sys/utsname.h> |
| 28 |
#include <sys/ioctl.h> |
| 29 |
#include <sys/socket.h> |
| 30 |
#include <sys/types.h> |
| 31 |
#include <sys/stat.h> |
| 32 |
#include <arpa/inet.h> |
| 33 |
#include <net/if.h> |
| 34 |
#include <ifaddrs.h> |
| 35 |
#include <glib/gstdio.h> |
| 36 |
#include <libgssdp/gssdp-error.h> |
| 37 |
|
| 38 |
#include "gupnp-unix-context-manager.h" |
| 39 |
#include "gupnp-context.h" |
| 40 |
|
| 41 |
struct _GUPnPUnixContextManager { |
| 42 |
GUPnPSimpleContextManager parent; |
| 43 |
}; |
| 44 |
|
| 45 |
G_DEFINE_TYPE (GUPnPUnixContextManager, |
| 46 |
gupnp_unix_context_manager, |
| 47 |
GUPNP_TYPE_SIMPLE_CONTEXT_MANAGER) |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
static GList * |
| 53 |
gupnp_unix_context_manager_get_interfaces (GUPnPSimpleContextManager *manager) |
| 54 |
{ |
| 55 |
struct ifaddrs *ifa_list, *ifa; |
| 56 |
GList *processed; |
| 57 |
|
| 58 |
g_return_val_if_fail (GUPNP_IS_UNIX_CONTEXT_MANAGER (manager), NULL); |
| 59 |
|
| 60 |
if (getifaddrs (&ifa_list) != 0) { |
| 61 |
g_warning ("Failed to retrieve list of network interfaces:%s\n", |
| 62 |
strerror (errno)); |
| 63 |
|
| 64 |
return FALSE; |
| 65 |
} |
| 66 |
|
| 67 |
processed = NULL; |
| 68 |
|
| 69 |
|
| 70 |
for (ifa = ifa_list; ifa != NULL; ifa = ifa->ifa_next) { |
| 71 |
if (g_list_find_custom (processed, |
| 72 |
ifa->ifa_name, |
| 73 |
(GCompareFunc) strcmp) != NULL) |
| 74 |
continue; |
| 75 |
|
| 76 |
if (ifa->ifa_flags & IFF_POINTOPOINT) |
| 77 |
continue; |
| 78 |
|
| 79 |
if (ifa->ifa_flags & IFF_UP) |
| 80 |
processed = g_list_append (processed, |
| 81 |
g_strdup (ifa->ifa_name)); |
| 82 |
} |
| 83 |
|
| 84 |
freeifaddrs (ifa_list); |
| 85 |
|
| 86 |
return processed; |
| 87 |
} |
| 88 |
|
| 89 |
static void |
| 90 |
gupnp_unix_context_manager_init (G_GNUC_UNUSED GUPnPUnixContextManager *manager) |
| 91 |
{ |
| 92 |
} |
| 93 |
|
| 94 |
static void |
| 95 |
gupnp_unix_context_manager_class_init (GUPnPUnixContextManagerClass *klass) |
| 96 |
{ |
| 97 |
GUPnPSimpleContextManagerClass *parent_class; |
| 98 |
|
| 99 |
parent_class = GUPNP_SIMPLE_CONTEXT_MANAGER_CLASS (klass); |
| 100 |
parent_class->get_interfaces = |
| 101 |
gupnp_unix_context_manager_get_interfaces; |
| 102 |
} |
| 103 |
|