[farsight2/master] Add test for port mapping

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:24:46 PST 2008


---
 fs-upnp-simple-igd.c |    1 +
 test.c               |   42 +++++++++++++++++++++++++++++++++++++-----
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/fs-upnp-simple-igd.c b/fs-upnp-simple-igd.c
index 50d24c1..e76d1ea 100644
--- a/fs-upnp-simple-igd.c
+++ b/fs-upnp-simple-igd.c
@@ -525,6 +525,7 @@ fs_upnp_simple_igd_add_proxy_mapping (FsUpnpSimpleIgd *self, struct Proxy *prox,
   pm->action = gupnp_service_proxy_begin_action (prox->proxy,
       "AddPortMapping",
       _service_proxy_added_port_mapping, pm,
+      "NewRemoteHost", G_TYPE_STRING, "",
       "NewExternalPort", G_TYPE_UINT, mapping->external_port,
       "NewProtocol", G_TYPE_STRING, mapping->protocol,
       "NewInternalPort", G_TYPE_UINT, mapping->local_port,
diff --git a/test.c b/test.c
index f1df947..c92fe15 100644
--- a/test.c
+++ b/test.c
@@ -1,16 +1,34 @@
 
+#include <stdlib.h>
+
 #include <glib.h>
 
 #include "fs-upnp-simple-igd.h"
 
 GMainLoop *loop = NULL;
+  FsUpnpSimpleIgd *igd = NULL;
+  guint external_port, internal_port;
+
+static gboolean
+_remove_port (gpointer user_data)
+{
+  g_debug ("removing port");
+  fs_upnp_simple_igd_remove_port (igd, "TCP", external_port);
+
+  return FALSE;
+}
 
 static void
-_new_external_ip (FsUpnpSimpleIgd *igd, gchar *ip, gpointer user_data)
+_mapped_external_port (FsUpnpSimpleIgd *igd, gchar *proto,
+    gchar *external_ip, gchar *replaces_external_ip, guint external_port,
+    gchar *local_ip, guint local_port,
+    gchar *description, gpointer user_data)
 {
-  g_debug ("ip: %s", ip);
+  g_debug ("proto:%s ex:%s oldex:%s exp:%u local:%s localp:%u desc:%s",
+      proto, external_ip, replaces_external_ip, external_port, local_ip,
+      local_port, description);
 
-  g_main_loop_quit (loop);
+  g_timeout_add (3000, _remove_port, user_data);
 }
 
 
@@ -22,7 +40,17 @@ _error (FsUpnpSimpleIgd *igd, GError *error, gpointer user_data)
 int
 main (int argc, char **argv)
 {
-  FsUpnpSimpleIgd *igd = NULL;
+
+  if (argc != 5)
+  {
+    g_print ("Usage: %s <external port> <local ip> <local port> <description>\n",
+        argv[0]);
+    return 0;
+  }
+
+  external_port = atoi (argv[1]);
+  internal_port = atoi (argv[3]);
+  g_return_val_if_fail (external_port && internal_port, 1);
 
   g_type_init ();
   g_thread_init (NULL);
@@ -31,11 +59,15 @@ main (int argc, char **argv)
 
   igd = fs_upnp_simple_igd_new (NULL);
 
-  g_signal_connect (igd, "new-external-ip", G_CALLBACK (_new_external_ip),
+  g_signal_connect (igd, "mapped-external-port",
+      G_CALLBACK (_mapped_external_port),
       NULL);
   g_signal_connect (igd, "error", G_CALLBACK (_error),
       NULL);
 
+  fs_upnp_simple_igd_add_port (igd, "TCP", external_port, argv[2],
+      internal_port, 600, argv[4]);
+
   g_main_loop_run (loop);
 
   g_main_loop_unref (loop);
-- 
1.5.6.5




More information about the farsight-commits mailing list