aboutsummaryrefslogtreecommitdiff
path: root/src/nat/upnp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nat/upnp.c')
-rw-r--r--src/nat/upnp.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/nat/upnp.c b/src/nat/upnp.c
index 8fc5f7e04..84abe339d 100644
--- a/src/nat/upnp.c
+++ b/src/nat/upnp.c
@@ -46,15 +46,14 @@
46/* Component name for logging */ 46/* Component name for logging */
47#define COMP_NAT_UPNP _("NAT (UPnP)") 47#define COMP_NAT_UPNP _("NAT (UPnP)")
48 48
49typedef enum 49enum UPNP_State
50{ 50{
51 UPNP_IDLE, 51 UPNP_IDLE,
52 UPNP_ERR, 52 UPNP_ERR,
53 UPNP_DISCOVER, 53 UPNP_DISCOVER,
54 UPNP_MAP, 54 UPNP_MAP,
55 UPNP_UNMAP 55 UPNP_UNMAP
56} 56};
57UPNP_state;
58 57
59struct GNUNET_NAT_UPNP_Handle 58struct GNUNET_NAT_UPNP_Handle
60{ 59{
@@ -65,7 +64,7 @@ struct GNUNET_NAT_UPNP_Handle
65 const struct sockaddr *addr; 64 const struct sockaddr *addr;
66 socklen_t addrlen; 65 socklen_t addrlen;
67 unsigned int is_mapped; 66 unsigned int is_mapped;
68 UPNP_state state; 67 enum UPNP_State state;
69 struct sockaddr *ext_addr; 68 struct sockaddr *ext_addr;
70 const char *iface; 69 const char *iface;
71}; 70};
@@ -81,35 +80,37 @@ process_if (void *cls,
81 80
82 if (addr && GNUNET_NAT_cmp_addr (upnp->addr, addr) == 0) 81 if (addr && GNUNET_NAT_cmp_addr (upnp->addr, addr) == 0)
83 { 82 {
84 upnp->iface = name; 83 upnp->iface = name; // BADNESS!
85 return GNUNET_SYSERR; 84 return GNUNET_SYSERR;
86 } 85 }
87 86
88 return GNUNET_OK; 87 return GNUNET_OK;
89} 88}
90 89
90
91GNUNET_NAT_UPNP_Handle * 91GNUNET_NAT_UPNP_Handle *
92GNUNET_NAT_UPNP_init (const struct sockaddr *addr, socklen_t addrlen, 92GNUNET_NAT_UPNP_init (const struct sockaddr *addr,
93 socklen_t addrlen,
93 u_short port) 94 u_short port)
94{ 95{
95 GNUNET_NAT_UPNP_Handle *upnp = 96 GNUNET_NAT_UPNP_Handle *upnp;
96 GNUNET_malloc (sizeof (GNUNET_NAT_UPNP_Handle));
97 97
98 upnp = GNUNET_malloc (sizeof (GNUNET_NAT_UPNP_Handle));
98 upnp->state = UPNP_DISCOVER; 99 upnp->state = UPNP_DISCOVER;
99 upnp->addr = addr; 100 upnp->addr = addr;
100 upnp->addrlen = addrlen; 101 upnp->addrlen = addrlen;
101 upnp->port = port; 102 upnp->port = port;
102
103 /* Find the interface corresponding to the address, 103 /* Find the interface corresponding to the address,
104 * on which we should broadcast call for routers */ 104 * on which we should broadcast call for routers */
105 upnp->iface = NULL; 105 GNUNET_OS_network_interfaces_list (&process_if, upnp);
106 GNUNET_OS_network_interfaces_list (process_if, upnp);
107 if (!upnp->iface) 106 if (!upnp->iface)
108 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, COMP_NAT_UPNP, "Could not find an interface matching the wanted address.\n"); 107 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
109 108 COMP_NAT_UPNP,
109 "Could not find an interface matching the wanted address.\n");
110 return upnp; 110 return upnp;
111} 111}
112 112
113
113void 114void
114GNUNET_NAT_UPNP_close (GNUNET_NAT_UPNP_Handle * handle) 115GNUNET_NAT_UPNP_close (GNUNET_NAT_UPNP_Handle * handle)
115{ 116{