2 * Copyright (C) 2009 Nokia Corporation.
3 * Copyright (C) 2006, 2007, 2008 OpenedHand Ltd.
5 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
6 * Jorn Baayen <jorn@openedhand.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 * SECTION:gupnp-unix-context-manager
26 * @short_description: Unix-specific implementation of #GUPnPContextManager.
37 #include <sys/utsname.h>
38 #include <sys/ioctl.h>
39 #include <sys/socket.h>
40 #include <sys/types.h>
42 #include <arpa/inet.h>
45 #include <libsoup/soup-address.h>
46 #include <glib/gstdio.h>
47 #include <libgssdp/gssdp-error.h>
49 #include "gupnp-unix-context-manager.h"
50 #include "gupnp-context.h"
52 G_DEFINE_TYPE (GUPnPUnixContextManager,
53 gupnp_unix_context_manager,
54 GUPNP_TYPE_SIMPLE_CONTEXT_MANAGER);
57 * Create a context for all network interfaces that are up.
60 gupnp_unix_context_manager_get_interfaces (GUPnPSimpleContextManager *manager)
62 struct ifaddrs *ifa_list, *ifa;
65 g_return_val_if_fail (GUPNP_IS_UNIX_CONTEXT_MANAGER (manager), NULL);
67 if (getifaddrs (&ifa_list) != 0) {
68 g_warning ("Failed to retrieve list of network interfaces:%s\n",
76 /* Create contexts for each up interface */
77 for (ifa = ifa_list; ifa != NULL; ifa = ifa->ifa_next) {
78 if (g_list_find_custom (processed,
80 (GCompareFunc) strcmp) != NULL)
83 if (ifa->ifa_flags & IFF_POINTOPOINT)
86 if (ifa->ifa_flags & IFF_UP)
87 processed = g_list_append (processed,
88 g_strdup (ifa->ifa_name));
91 freeifaddrs (ifa_list);
97 gupnp_unix_context_manager_init (G_GNUC_UNUSED GUPnPUnixContextManager *manager)
102 gupnp_unix_context_manager_class_init (GUPnPUnixContextManagerClass *klass)
104 GUPnPSimpleContextManagerClass *parent_class;
106 parent_class = GUPNP_SIMPLE_CONTEXT_MANAGER_CLASS (klass);
107 parent_class->get_interfaces =
108 gupnp_unix_context_manager_get_interfaces;