#include #include "gateway-bindings.h" static GMainLoop *main_loop; static void service_proxy_available_cb (GUPnPControlPoint *cp, GUPnPServiceProxy *proxy) { GError *error = NULL; char *ip = NULL; if (GetExternalIPAddress (proxy, &ip, &error)) { g_print ("External IP address is %s\n", ip); g_free (ip); } else { g_printerr ("Error: %s\n", error->message); g_error_free (error); } g_main_loop_quit (main_loop); } static gboolean timeout_cb (gpointer data) { g_print ("Timed out searching for a router\n"); g_main_loop_quit (main_loop); return FALSE; } 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); g_timeout_add (1000, timeout_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; }