{
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 =
/* 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
}
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
else
{
PRINT_SOCKET_ERROR ("inet_pton");
- closesocket (s);
+ if (s > 0)
+ closesocket (s);
+
*bufsize = 0;
return -1;
}
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
}
else
{
- if (multicastif && !(if_index = if_nametoindex (multicastif)))
- PRINT_SOCKET_ERROR ("if_nametoindex");
-
- if (setsockopt
- (sudp, IPPROTO_IPV6, IPV6_MULTICAST_IF, &if_index, sizeof (if_index)) < 0)
+ if (multicastif)
{
- PRINT_SOCKET_ERROR ("setsockopt");
+ 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");
+ }
}
/* Bind to receive response before sending packet */
{
const struct sockaddr *addr;
socklen_t addrlen;
+ struct sockaddr *ext_addr;
int is_mapped;
int has_discovered;
int port;
nat->port = port;
nat->addr = addr;
nat->addrlen = addrlen;
+ nat->ext_addr = NULL;
return nat;
}
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"),