| 1 |
|
| 2 |
#ifdef HAVE_CONFIG_H |
| 3 |
# include "config.h" |
| 4 |
#endif |
| 5 |
|
| 6 |
#include <stdlib.h> |
| 7 |
#include <unistd.h> |
| 8 |
|
| 9 |
#include <glib.h> |
| 10 |
|
| 11 |
#include <libgupnp-igd/gupnp-simple-igd-thread.h> |
| 12 |
|
| 13 |
static void |
| 14 |
_mapped_external_port (GUPnPSimpleIgd *igd, gchar *proto, |
| 15 |
gchar *external_ip, gchar *replaces_external_ip, guint external_port, |
| 16 |
gchar *local_ip, guint local_port, |
| 17 |
gchar *description, gpointer user_data) |
| 18 |
{ |
| 19 |
g_debug ("proto:%s ex:%s oldex:%s exp:%u local:%s localp:%u desc:%s", |
| 20 |
proto, external_ip, replaces_external_ip, external_port, local_ip, |
| 21 |
local_port, description); |
| 22 |
|
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
static void |
| 28 |
_error_mapping_external_port (GUPnPSimpleIgd *igd, GError *error, |
| 29 |
gchar *proto, guint external_port, |
| 30 |
gchar *description, gpointer user_data) |
| 31 |
{ |
| 32 |
g_error ("proto:%s port:%u desc:%s error: %s:%d %s", proto, external_port, |
| 33 |
description, g_quark_to_string (error->domain), error->code, error->message); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
int |
| 38 |
main (int argc, char **argv) |
| 39 |
{ |
| 40 |
GUPnPSimpleIgdThread *igd = NULL; |
| 41 |
guint external_port, internal_port; |
| 42 |
|
| 43 |
|
| 44 |
if (argc != 5) |
| 45 |
{ |
| 46 |
g_print ("Usage: %s <external port> <local ip> <local port> <description>\n", |
| 47 |
argv[0]); |
| 48 |
return 0; |
| 49 |
} |
| 50 |
|
| 51 |
external_port = atoi (argv[1]); |
| 52 |
internal_port = atoi (argv[3]); |
| 53 |
g_return_val_if_fail (external_port && internal_port, 1); |
| 54 |
|
| 55 |
igd = gupnp_simple_igd_thread_new (); |
| 56 |
|
| 57 |
g_signal_connect (igd, "mapped-external-port", |
| 58 |
G_CALLBACK (_mapped_external_port), |
| 59 |
NULL); |
| 60 |
g_signal_connect (igd, "error-mapping-port", |
| 61 |
G_CALLBACK (_error_mapping_external_port), |
| 62 |
NULL); |
| 63 |
|
| 64 |
gupnp_simple_igd_add_port (GUPNP_SIMPLE_IGD (igd), |
| 65 |
"TCP", external_port, argv[2], |
| 66 |
internal_port, 20, argv[4]); |
| 67 |
|
| 68 |
sleep (30); |
| 69 |
|
| 70 |
gupnp_simple_igd_remove_port (GUPNP_SIMPLE_IGD (igd), "TCP", |
| 71 |
external_port); |
| 72 |
|
| 73 |
sleep (5); |
| 74 |
|
| 75 |
g_object_unref (igd); |
| 76 |
|
| 77 |
return 0; |
| 78 |
} |