diff options
-rw-r--r-- | src/nat/libnatpmp/natpmp.c | 10 | ||||
-rw-r--r-- | src/nat/libnatpmp/natpmp.h | 3 | ||||
-rw-r--r-- | src/nat/miniupnp/miniupnpc.c | 29 | ||||
-rw-r--r-- | src/nat/miniupnp/upnpcommands.c | 3 | ||||
-rw-r--r-- | src/nat/nat.c | 3 | ||||
-rw-r--r-- | src/nat/natpmp.c | 28 | ||||
-rw-r--r-- | src/nat/upnp.c | 2 |
7 files changed, 58 insertions, 20 deletions
diff --git a/src/nat/libnatpmp/natpmp.c b/src/nat/libnatpmp/natpmp.c index 171911979..12526df8e 100644 --- a/src/nat/libnatpmp/natpmp.c +++ b/src/nat/libnatpmp/natpmp.c | |||
@@ -267,9 +267,13 @@ readnatpmpresponse (natpmp_t * p, natpmpresp_t * response) | |||
267 | { | 267 | { |
268 | response->type = buf[1] & 0x7f; | 268 | response->type = buf[1] & 0x7f; |
269 | if (buf[1] == 128) | 269 | if (buf[1] == 128) |
270 | //response->publicaddress.addr = *((uint32_t *)(buf + 8)); | 270 | { |
271 | response->pnu.publicaddress.addr.s_addr = | 271 | response->pnu.publicaddress.family = AF_INET; |
272 | *((uint32_t *) (buf + 8)); | 272 | memset (&response->pnu.publicaddress.addr6.s6_addr, 0, sizeof (struct in6_addr)); |
273 | response->pnu.publicaddress.addr.s_addr = | ||
274 | *((uint32_t *) (buf + 8)); | ||
275 | /* FIXME: support IPv6 address */ | ||
276 | } | ||
273 | else | 277 | else |
274 | { | 278 | { |
275 | response->pnu.newportmapping.privateport = | 279 | response->pnu.newportmapping.privateport = |
diff --git a/src/nat/libnatpmp/natpmp.h b/src/nat/libnatpmp/natpmp.h index d8b23a74d..976bad06f 100644 --- a/src/nat/libnatpmp/natpmp.h +++ b/src/nat/libnatpmp/natpmp.h | |||
@@ -56,8 +56,9 @@ typedef struct | |||
56 | { | 56 | { |
57 | struct | 57 | struct |
58 | { | 58 | { |
59 | //in_addr_t addr; | 59 | int family; |
60 | struct in_addr addr; | 60 | struct in_addr addr; |
61 | struct in6_addr addr6; | ||
61 | } publicaddress; | 62 | } publicaddress; |
62 | struct | 63 | struct |
63 | { | 64 | { |
diff --git a/src/nat/miniupnp/miniupnpc.c b/src/nat/miniupnp/miniupnpc.c index 412c8ec25..34bae0ad8 100644 --- a/src/nat/miniupnp/miniupnpc.c +++ b/src/nat/miniupnp/miniupnpc.c | |||
@@ -238,6 +238,7 @@ simpleUPnPcommand (int s, const char *url, const char *service, | |||
238 | /* Test IPv4 address, else use IPv6 */ | 238 | /* Test IPv4 address, else use IPv6 */ |
239 | if (inet_pton (AF_INET, hostname, &dest.sin_addr) == 1) | 239 | if (inet_pton (AF_INET, hostname, &dest.sin_addr) == 1) |
240 | { | 240 | { |
241 | memset (&dest, 0, sizeof (dest)); | ||
241 | dest.sin_family = AF_INET; | 242 | dest.sin_family = AF_INET; |
242 | dest.sin_port = htons (port); | 243 | dest.sin_port = htons (port); |
243 | #ifdef HAVE_SOCKADDR_IN_SIN_LEN | 244 | #ifdef HAVE_SOCKADDR_IN_SIN_LEN |
@@ -253,9 +254,9 @@ simpleUPnPcommand (int s, const char *url, const char *service, | |||
253 | } | 254 | } |
254 | else if (inet_pton (AF_INET6, hostname, &dest6.sin6_addr) == 1) | 255 | else if (inet_pton (AF_INET6, hostname, &dest6.sin6_addr) == 1) |
255 | { | 256 | { |
257 | memset (&dest6, 0, sizeof (dest6)); | ||
256 | dest6.sin6_family = AF_INET6; | 258 | dest6.sin6_family = AF_INET6; |
257 | dest6.sin6_port = htons (port); | 259 | dest6.sin6_port = htons (port); |
258 | dest6.sin6_flowinfo = 0; | ||
259 | #ifdef HAVE_SOCKADDR_IN_SIN_LEN | 260 | #ifdef HAVE_SOCKADDR_IN_SIN_LEN |
260 | dest6.sin6_len = sizeof (dest6); | 261 | dest6.sin6_len = sizeof (dest6); |
261 | #endif | 262 | #endif |
@@ -270,7 +271,9 @@ simpleUPnPcommand (int s, const char *url, const char *service, | |||
270 | else | 271 | else |
271 | { | 272 | { |
272 | PRINT_SOCKET_ERROR ("inet_pton"); | 273 | PRINT_SOCKET_ERROR ("inet_pton"); |
273 | closesocket (s); | 274 | if (s > 0) |
275 | closesocket (s); | ||
276 | |||
274 | *bufsize = 0; | 277 | *bufsize = 0; |
275 | return -1; | 278 | return -1; |
276 | } | 279 | } |
@@ -495,7 +498,11 @@ upnpDiscover (int delay, const char *multicastif, | |||
495 | memset (&sockudp6_w, 0, sizeof (struct sockaddr_in6)); | 498 | memset (&sockudp6_w, 0, sizeof (struct sockaddr_in6)); |
496 | sockudp6_w.sin6_family = AF_INET6; | 499 | sockudp6_w.sin6_family = AF_INET6; |
497 | sockudp6_w.sin6_port = htons (PORT); | 500 | sockudp6_w.sin6_port = htons (PORT); |
498 | inet_pton (AF_INET6, UPNP_MCAST_ADDR6, &sockudp6_w.sin6_addr); | 501 | if (inet_pton (AF_INET6, UPNP_MCAST_ADDR6, &sockudp6_w.sin6_addr) != 1) |
502 | { | ||
503 | PRINT_SOCKET_ERROR ("inet_pton"); | ||
504 | return NULL; | ||
505 | } | ||
499 | #ifdef HAVE_SOCKADDR_IN_SIN_LEN | 506 | #ifdef HAVE_SOCKADDR_IN_SIN_LEN |
500 | sockudp6_w.sin6_len = sizeof (struct sockaddr_in6); | 507 | sockudp6_w.sin6_len = sizeof (struct sockaddr_in6); |
501 | #endif | 508 | #endif |
@@ -535,13 +542,17 @@ upnpDiscover (int delay, const char *multicastif, | |||
535 | } | 542 | } |
536 | else | 543 | else |
537 | { | 544 | { |
538 | if (multicastif && !(if_index = if_nametoindex (multicastif))) | 545 | if (multicastif) |
539 | PRINT_SOCKET_ERROR ("if_nametoindex"); | ||
540 | |||
541 | if (setsockopt | ||
542 | (sudp, IPPROTO_IPV6, IPV6_MULTICAST_IF, &if_index, sizeof (if_index)) < 0) | ||
543 | { | 546 | { |
544 | PRINT_SOCKET_ERROR ("setsockopt"); | 547 | if_index = if_nametoindex (multicastif); |
548 | if (!if_index) | ||
549 | PRINT_SOCKET_ERROR ("if_nametoindex"); | ||
550 | |||
551 | if (setsockopt | ||
552 | (sudp, IPPROTO_IPV6, IPV6_MULTICAST_IF, &if_index, sizeof (if_index)) < 0) | ||
553 | { | ||
554 | PRINT_SOCKET_ERROR ("setsockopt"); | ||
555 | } | ||
545 | } | 556 | } |
546 | 557 | ||
547 | /* Bind to receive response before sending packet */ | 558 | /* Bind to receive response before sending packet */ |
diff --git a/src/nat/miniupnp/upnpcommands.c b/src/nat/miniupnp/upnpcommands.c index 7a342540a..8b59bc7cc 100644 --- a/src/nat/miniupnp/upnpcommands.c +++ b/src/nat/miniupnp/upnpcommands.c | |||
@@ -435,8 +435,7 @@ UPNP_GetGenericPortMappingEntry (const char *controlURL, | |||
435 | int r = UPNPCOMMAND_UNKNOWN_ERROR; | 435 | int r = UPNPCOMMAND_UNKNOWN_ERROR; |
436 | if (!index) | 436 | if (!index) |
437 | return UPNPCOMMAND_INVALID_ARGS; | 437 | return UPNPCOMMAND_INVALID_ARGS; |
438 | intClient[0] = '\0'; | 438 | |
439 | intPort[0] = '\0'; | ||
440 | GetPortMappingArgs = calloc (2, sizeof (struct UPNParg)); | 439 | GetPortMappingArgs = calloc (2, sizeof (struct UPNParg)); |
441 | GetPortMappingArgs[0].elt = "NewPortMappingIndex"; | 440 | GetPortMappingArgs[0].elt = "NewPortMappingIndex"; |
442 | GetPortMappingArgs[0].val = index; | 441 | GetPortMappingArgs[0].val = index; |
diff --git a/src/nat/nat.c b/src/nat/nat.c index e725220ab..2a93d31a7 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c | |||
@@ -359,6 +359,9 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *nat) | |||
359 | 359 | ||
360 | GNUNET_NAT_NATPMP_close (nat->natpmp); | 360 | GNUNET_NAT_NATPMP_close (nat->natpmp); |
361 | GNUNET_NAT_UPNP_close (nat->upnp); | 361 | GNUNET_NAT_UPNP_close (nat->upnp); |
362 | |||
363 | if (nat->local_addr) | ||
364 | GNUNET_free (nat->local_addr); | ||
362 | if (nat->ext_addr) | 365 | if (nat->ext_addr) |
363 | GNUNET_free (nat->ext_addr); | 366 | GNUNET_free (nat->ext_addr); |
364 | GNUNET_free (nat); | 367 | GNUNET_free (nat); |
diff --git a/src/nat/natpmp.c b/src/nat/natpmp.c index 16d68c702..2a9187295 100644 --- a/src/nat/natpmp.c +++ b/src/nat/natpmp.c | |||
@@ -65,6 +65,7 @@ struct GNUNET_NAT_NATPMP_Handle | |||
65 | { | 65 | { |
66 | const struct sockaddr *addr; | 66 | const struct sockaddr *addr; |
67 | socklen_t addrlen; | 67 | socklen_t addrlen; |
68 | struct sockaddr *ext_addr; | ||
68 | int is_mapped; | 69 | int is_mapped; |
69 | int has_discovered; | 70 | int has_discovered; |
70 | int port; | 71 | int port; |
@@ -107,6 +108,7 @@ GNUNET_NAT_NATPMP_init (const struct sockaddr *addr, socklen_t addrlen, | |||
107 | nat->port = port; | 108 | nat->port = port; |
108 | nat->addr = addr; | 109 | nat->addr = addr; |
109 | nat->addrlen = addrlen; | 110 | nat->addrlen = addrlen; |
111 | nat->ext_addr = NULL; | ||
110 | return nat; | 112 | return nat; |
111 | } | 113 | } |
112 | 114 | ||
@@ -160,10 +162,28 @@ GNUNET_NAT_NATPMP_pulse (struct GNUNET_NAT_NATPMP_Handle *nat, int is_enabled, | |||
160 | log_val ("readnatpmpresponseorretry", val); | 162 | log_val ("readnatpmpresponseorretry", val); |
161 | if (val >= 0) | 163 | if (val >= 0) |
162 | { | 164 | { |
163 | *ext_addr = | 165 | if (nat->ext_addr) |
164 | GNUNET_malloc (sizeof (response.pnu.publicaddress.addr)); | 166 | { |
165 | memcpy (*ext_addr, &response.pnu.publicaddress.addr, | 167 | GNUNET_free (nat->ext_addr); |
166 | (sizeof (response.pnu.publicaddress.addr))); | 168 | nat->ext_addr = NULL; |
169 | } | ||
170 | |||
171 | if (response.pnu.publicaddress.family == AF_INET) | ||
172 | { | ||
173 | nat->ext_addr = | ||
174 | GNUNET_malloc (sizeof (struct in_addr)); | ||
175 | memcpy (nat->ext_addr, &response.pnu.publicaddress.addr, | ||
176 | sizeof (struct in_addr)); | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | nat->ext_addr = | ||
181 | GNUNET_malloc (sizeof (struct in6_addr)); | ||
182 | memcpy (nat->ext_addr, &response.pnu.publicaddress.addr6, | ||
183 | (sizeof (struct in6_addr))); | ||
184 | } | ||
185 | |||
186 | *ext_addr = nat->ext_addr; | ||
167 | #ifdef DEBUG | 187 | #ifdef DEBUG |
168 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, COMP_NAT_NATPMP, | 188 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, COMP_NAT_NATPMP, |
169 | _("Found public IP address %s\n"), | 189 | _("Found public IP address %s\n"), |
diff --git a/src/nat/upnp.c b/src/nat/upnp.c index 62ecd7ff9..e8a5f1afc 100644 --- a/src/nat/upnp.c +++ b/src/nat/upnp.c | |||
@@ -223,7 +223,7 @@ GNUNET_NAT_UPNP_pulse (GNUNET_NAT_UPNP_Handle * handle, int is_enabled, | |||
223 | int err = -1; | 223 | int err = -1; |
224 | errno = 0; | 224 | errno = 0; |
225 | 225 | ||
226 | if (!handle->urls.controlURL || !handle->data.servicetype) | 226 | if (!handle->urls.controlURL) |
227 | handle->is_mapped = 0; | 227 | handle->is_mapped = 0; |
228 | else | 228 | else |
229 | { | 229 | { |