#include #include "gateway-bindings.h" static GMainLoop *main_loop; static void on_num_entries (GUPnPServiceProxy *proxy, const char *variable, GValue *value, gpointer user_data) { GError *error = NULL; unsigned int i, count; char *remote_host, *internal_client, *proto, *desc; unsigned int external_port, internal_port, lease; gboolean enabled; count = g_value_get_uint (value); for (i = 0; i < count; i++) { if (GetGenericPortMappingEntry (proxy, i, &remote_host, &external_port, &proto, &internal_port, &internal_client, &enabled, &desc, &lease, &error)) { g_print ("[%d] Mapping %s\n" "External %s:%d\n" "Internal %s:%d\n" "Protocol %s\n" "%s\n\n", i, enabled ? "enabled" : "disabled", remote_host[0] != '\0' ? remote_host : "*", external_port, internal_client, internal_port, proto, desc); g_free (remote_host); g_free (internal_client); g_free (proto); g_free (desc); } else { g_printerr ("Error: %s\n", error->message); g_error_free (error); break; } } g_main_loop_quit (main_loop); } static void service_proxy_available_cb (GUPnPControlPoint *cp, GUPnPServiceProxy *proxy) { g_print ("Found gateway device at %s\n\n", gupnp_service_info_get_location (GUPNP_SERVICE_INFO (proxy))); gupnp_service_proxy_add_notify (proxy, "PortMappingNumberOfEntries", G_TYPE_UINT, on_num_entries, NULL); gupnp_service_proxy_set_subscribed (proxy, TRUE); } int main (int argc, char **argv) { GError *error = NULL; GUPnPContext *context; GUPnPControlPoint *cp; g_thread_init (NULL); g_type_init (); context = gupnp_context_new (NULL, NULL, 0, &error); if (error) { g_error (error->message); g_error_free (error); return 1; } cp = gupnp_control_point_new (context, "urn:schemas-upnp-org:service:WANIPConnection:1"); g_signal_connect (cp, "service-proxy-available", G_CALLBACK (service_proxy_available_cb), NULL); gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE); main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); g_main_loop_unref (main_loop); g_object_unref (cp); g_object_unref (context); return 0; }