2 * Copyright (C) 2009, 2010 Jens Georg
3 * Copyright (C) 2009 Nokia Corporation.
4 * Copyright (C) 2006, 2007, 2008 OpenedHand Ltd.
6 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
7 * Jorn Baayen <jorn@openedhand.com>
8 * Jens Georg <mail@jensge.org>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
27 * SECTION:gupnp-windows-context-manager
28 * @short_description: Windows-specific implementation of #GUPnPContextManager.
34 #define _WIN32_WINNT 0x0502
40 #include "gupnp-windows-context-manager.h"
41 #include "gupnp-context.h"
43 G_DEFINE_TYPE (GUPnPWindowsContextManager,
44 gupnp_windows_context_manager,
45 GUPNP_TYPE_SIMPLE_CONTEXT_MANAGER);
48 * Create a context for all network interfaces that are up.
51 gupnp_windows_context_manager_get_interfaces
52 (GUPnPSimpleContextManager *manager)
54 GList *interfaces = NULL;
55 ULONG flags = GAA_FLAG_INCLUDE_PREFIX |
56 GAA_FLAG_SKIP_DNS_SERVER |
57 GAA_FLAG_SKIP_MULTICAST;
58 /* use 15k buffer initially as documented in MSDN */
61 PIP_ADAPTER_ADDRESSES adapters_addresses;
62 PIP_ADAPTER_ADDRESSES adapter;
65 adapters_addresses = (PIP_ADAPTER_ADDRESSES) g_malloc0 (size);
66 ret = GetAdaptersAddresses (AF_UNSPEC,
71 if (ret == ERROR_BUFFER_OVERFLOW) {
72 g_free (adapters_addresses);
74 } while (ret == ERROR_BUFFER_OVERFLOW);
76 if (ret != ERROR_SUCCESS)
79 for (adapter = adapters_addresses;
81 adapter = adapter->Next) {
82 if (adapter->FirstUnicastAddress == NULL)
84 if (adapter->OperStatus != IfOperStatusUp)
86 interfaces = g_list_append (interfaces,
87 g_strdup (adapter->AdapterName));
94 gupnp_windows_context_manager_init (GUPnPWindowsContextManager *manager)
99 gupnp_windows_context_manager_class_init (GUPnPWindowsContextManagerClass *klass)
101 GUPnPSimpleContextManagerClass *parent_class;
103 parent_class = GUPNP_SIMPLE_CONTEXT_MANAGER_CLASS (klass);
104 parent_class->get_interfaces =
105 gupnp_windows_context_manager_get_interfaces;