[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r9348 - in gnunet/src/nat: . libnatpmp miniupnp
From: |
gnunet |
Subject: |
[GNUnet-SVN] r9348 - in gnunet/src/nat: . libnatpmp miniupnp |
Date: |
Fri, 30 Oct 2009 10:18:34 -0600 |
Author: moon
Date: 2009-10-30 10:18:34 -0600 (Fri, 30 Oct 2009)
New Revision: 9348
Modified:
gnunet/src/nat/libnatpmp/natpmp.c
gnunet/src/nat/libnatpmp/natpmp.h
gnunet/src/nat/miniupnp/miniupnpc.c
gnunet/src/nat/miniupnp/upnpcommands.c
gnunet/src/nat/nat.c
gnunet/src/nat/natpmp.c
gnunet/src/nat/upnp.c
Log:
bunch of fixes to bugs found by grothoff
Modified: gnunet/src/nat/libnatpmp/natpmp.c
===================================================================
--- gnunet/src/nat/libnatpmp/natpmp.c 2009-10-30 07:21:10 UTC (rev 9347)
+++ gnunet/src/nat/libnatpmp/natpmp.c 2009-10-30 16:18:34 UTC (rev 9348)
@@ -267,9 +267,13 @@
{
response->type = buf[1] & 0x7f;
if (buf[1] == 128)
- //response->publicaddress.addr = *((uint32_t *)(buf + 8));
- response->pnu.publicaddress.addr.s_addr =
- *((uint32_t *) (buf + 8));
+ {
+ response->pnu.publicaddress.family = AF_INET;
+ memset (&response->pnu.publicaddress.addr6.s6_addr, 0, sizeof
(struct in6_addr));
+ response->pnu.publicaddress.addr.s_addr =
+ *((uint32_t *) (buf + 8));
+ /* FIXME: support IPv6 address */
+ }
else
{
response->pnu.newportmapping.privateport =
Modified: gnunet/src/nat/libnatpmp/natpmp.h
===================================================================
--- gnunet/src/nat/libnatpmp/natpmp.h 2009-10-30 07:21:10 UTC (rev 9347)
+++ gnunet/src/nat/libnatpmp/natpmp.h 2009-10-30 16:18:34 UTC (rev 9348)
@@ -56,8 +56,9 @@
{
struct
{
- //in_addr_t addr;
+ int family;
struct in_addr addr;
+ struct in6_addr addr6;
} publicaddress;
struct
{
Modified: gnunet/src/nat/miniupnp/miniupnpc.c
===================================================================
--- gnunet/src/nat/miniupnp/miniupnpc.c 2009-10-30 07:21:10 UTC (rev 9347)
+++ gnunet/src/nat/miniupnp/miniupnpc.c 2009-10-30 16:18:34 UTC (rev 9348)
@@ -238,6 +238,7 @@
/* Test IPv4 address, else use IPv6 */
if (inet_pton (AF_INET, hostname, &dest.sin_addr) == 1)
{
+ memset (&dest, 0, sizeof (dest));
dest.sin_family = AF_INET;
dest.sin_port = htons (port);
#ifdef HAVE_SOCKADDR_IN_SIN_LEN
@@ -253,9 +254,9 @@
}
else if (inet_pton (AF_INET6, hostname, &dest6.sin6_addr) == 1)
{
+ memset (&dest6, 0, sizeof (dest6));
dest6.sin6_family = AF_INET6;
dest6.sin6_port = htons (port);
- dest6.sin6_flowinfo = 0;
#ifdef HAVE_SOCKADDR_IN_SIN_LEN
dest6.sin6_len = sizeof (dest6);
#endif
@@ -270,7 +271,9 @@
else
{
PRINT_SOCKET_ERROR ("inet_pton");
- closesocket (s);
+ if (s > 0)
+ closesocket (s);
+
*bufsize = 0;
return -1;
}
@@ -495,7 +498,11 @@
memset (&sockudp6_w, 0, sizeof (struct sockaddr_in6));
sockudp6_w.sin6_family = AF_INET6;
sockudp6_w.sin6_port = htons (PORT);
- inet_pton (AF_INET6, UPNP_MCAST_ADDR6, &sockudp6_w.sin6_addr);
+ if (inet_pton (AF_INET6, UPNP_MCAST_ADDR6, &sockudp6_w.sin6_addr) != 1)
+ {
+ PRINT_SOCKET_ERROR ("inet_pton");
+ return NULL;
+ }
#ifdef HAVE_SOCKADDR_IN_SIN_LEN
sockudp6_w.sin6_len = sizeof (struct sockaddr_in6);
#endif
@@ -535,13 +542,17 @@
}
else
{
- if (multicastif && !(if_index = if_nametoindex (multicastif)))
- PRINT_SOCKET_ERROR ("if_nametoindex");
+ if (multicastif)
+ {
+ if_index = if_nametoindex (multicastif);
+ if (!if_index)
+ PRINT_SOCKET_ERROR ("if_nametoindex");
- if (setsockopt
- (sudp, IPPROTO_IPV6, IPV6_MULTICAST_IF, &if_index, sizeof
(if_index)) < 0)
- {
- PRINT_SOCKET_ERROR ("setsockopt");
+ if (setsockopt
+ (sudp, IPPROTO_IPV6, IPV6_MULTICAST_IF, &if_index, sizeof
(if_index)) < 0)
+ {
+ PRINT_SOCKET_ERROR ("setsockopt");
+ }
}
/* Bind to receive response before sending packet */
Modified: gnunet/src/nat/miniupnp/upnpcommands.c
===================================================================
--- gnunet/src/nat/miniupnp/upnpcommands.c 2009-10-30 07:21:10 UTC (rev
9347)
+++ gnunet/src/nat/miniupnp/upnpcommands.c 2009-10-30 16:18:34 UTC (rev
9348)
@@ -435,8 +435,7 @@
int r = UPNPCOMMAND_UNKNOWN_ERROR;
if (!index)
return UPNPCOMMAND_INVALID_ARGS;
- intClient[0] = '\0';
- intPort[0] = '\0';
+
GetPortMappingArgs = calloc (2, sizeof (struct UPNParg));
GetPortMappingArgs[0].elt = "NewPortMappingIndex";
GetPortMappingArgs[0].val = index;
Modified: gnunet/src/nat/nat.c
===================================================================
--- gnunet/src/nat/nat.c 2009-10-30 07:21:10 UTC (rev 9347)
+++ gnunet/src/nat/nat.c 2009-10-30 16:18:34 UTC (rev 9348)
@@ -359,6 +359,9 @@
GNUNET_NAT_NATPMP_close (nat->natpmp);
GNUNET_NAT_UPNP_close (nat->upnp);
+
+ if (nat->local_addr)
+ GNUNET_free (nat->local_addr);
if (nat->ext_addr)
GNUNET_free (nat->ext_addr);
GNUNET_free (nat);
Modified: gnunet/src/nat/natpmp.c
===================================================================
--- gnunet/src/nat/natpmp.c 2009-10-30 07:21:10 UTC (rev 9347)
+++ gnunet/src/nat/natpmp.c 2009-10-30 16:18:34 UTC (rev 9348)
@@ -65,6 +65,7 @@
{
const struct sockaddr *addr;
socklen_t addrlen;
+ struct sockaddr *ext_addr;
int is_mapped;
int has_discovered;
int port;
@@ -107,6 +108,7 @@
nat->port = port;
nat->addr = addr;
nat->addrlen = addrlen;
+ nat->ext_addr = NULL;
return nat;
}
@@ -160,10 +162,28 @@
log_val ("readnatpmpresponseorretry", val);
if (val >= 0)
{
- *ext_addr =
- GNUNET_malloc (sizeof (response.pnu.publicaddress.addr));
- memcpy (*ext_addr, &response.pnu.publicaddress.addr,
- (sizeof (response.pnu.publicaddress.addr)));
+ if (nat->ext_addr)
+ {
+ GNUNET_free (nat->ext_addr);
+ nat->ext_addr = NULL;
+ }
+
+ if (response.pnu.publicaddress.family == AF_INET)
+ {
+ nat->ext_addr =
+ GNUNET_malloc (sizeof (struct in_addr));
+ memcpy (nat->ext_addr, &response.pnu.publicaddress.addr,
+ sizeof (struct in_addr));
+ }
+ else
+ {
+ nat->ext_addr =
+ GNUNET_malloc (sizeof (struct in6_addr));
+ memcpy (nat->ext_addr, &response.pnu.publicaddress.addr6,
+ (sizeof (struct in6_addr)));
+ }
+
+ *ext_addr = nat->ext_addr;
#ifdef DEBUG
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, COMP_NAT_NATPMP,
_("Found public IP address %s\n"),
Modified: gnunet/src/nat/upnp.c
===================================================================
--- gnunet/src/nat/upnp.c 2009-10-30 07:21:10 UTC (rev 9347)
+++ gnunet/src/nat/upnp.c 2009-10-30 16:18:34 UTC (rev 9348)
@@ -223,7 +223,7 @@
int err = -1;
errno = 0;
- if (!handle->urls.controlURL || !handle->data.servicetype)
+ if (!handle->urls.controlURL)
handle->is_mapped = 0;
else
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r9348 - in gnunet/src/nat: . libnatpmp miniupnp,
gnunet <=