2 This file is part of GNUnet.
3 (C) 2006 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file upnp/test_upnp.c
22 * @brief Testcase for UPnP
23 * @author Christian Grothoff
26 #include "gnunet_util.h"
27 #include "gnunet_upnp_service.h"
28 #include "gnunet_core.h"
34 main (int argc, const char *argv[])
36 static GNUNET_CoreAPIForPlugins capi;
37 struct GNUNET_GE_Context *ectx;
38 struct GNUNET_GC_Configuration *cfg;
41 GNUNET_UPnP_ServiceAPI *upnp;
42 struct GNUNET_PluginHandle *plug;
43 GNUNET_ServicePluginInitializationMethod init;
44 GNUNET_ServicePluginShutdownMethod done;
45 char ntop_buf[INET_ADDRSTRLEN];
47 ectx = GNUNET_GE_create_context_stderr (GNUNET_NO,
48 GNUNET_GE_WARNING | GNUNET_GE_ERROR
49 | GNUNET_GE_FATAL | GNUNET_GE_USER |
54 GNUNET_GE_setDefaultContext (ectx);
55 cfg = GNUNET_GC_create ();
56 GNUNET_GE_ASSERT (ectx, cfg != NULL);
57 GNUNET_os_init (ectx);
60 plug = GNUNET_plugin_load (ectx, "libgnunet", "module_upnp");
64 GNUNET_GE_free_context (ectx);
67 init = GNUNET_plugin_resolve_function (plug, "provide_", GNUNET_YES);
70 GNUNET_plugin_unload (plug);
72 GNUNET_GE_free_context (ectx);
78 GNUNET_plugin_unload (plug);
80 GNUNET_GE_free_context (ectx);
83 for (i = 0; i < 10; i++)
85 if (GNUNET_shutdown_test () != GNUNET_NO)
87 if (GNUNET_OK == upnp->get_ip (2086, "TCP", &addr))
89 printf ("UPnP returned external IP %s\n",
90 inet_ntop (AF_INET, &addr, ntop_buf, INET_ADDRSTRLEN));
94 /* we cannot be sure that there is a UPnP-capable
95 NAT-box out there, so test should not fail
96 just because of this! */
97 printf ("No UPnP response (yet).\n");
99 GNUNET_thread_sleep (2 * GNUNET_CRON_SECONDS);
101 done = GNUNET_plugin_resolve_function (plug, "release_", GNUNET_YES);
104 GNUNET_plugin_unload (plug);
105 GNUNET_GC_free (cfg);
106 GNUNET_GE_free_context (ectx);
110 /* end of upnptest.c */