gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated: fix calls to test_address,


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: fix calls to test_address, expects a struct sockaddr, not an in_addr
Date: Sat, 07 Jan 2017 17:58:43 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new c3b77fe  fix calls to test_address, expects a struct sockaddr, not an 
in_addr
c3b77fe is described below

commit c3b77fea0f652b7d8f0641696f3a3418864ab135
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat Jan 7 17:58:36 2017 +0100

    fix calls to test_address, expects a struct sockaddr, not an in_addr
---
 src/nat/nat_api.c                    |  2 +-
 src/transport/plugin_transport_tcp.c | 55 ++++++++++++++++--------------------
 src/transport/plugin_transport_udp.c | 35 +++++++++++++++++------
 3 files changed, 51 insertions(+), 41 deletions(-)

diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c
index 261b901..826dbd5 100644
--- a/src/nat/nat_api.c
+++ b/src/nat/nat_api.c
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2007-2016 GNUnet e.V.
+     Copyright (C) 2007-2017 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
diff --git a/src/transport/plugin_transport_tcp.c 
b/src/transport/plugin_transport_tcp.c
index 605579c..eca62a8 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -2413,27 +2413,6 @@ tcp_plugin_address_pretty_printer (void *cls,
 
 
 /**
- * Check if the given port is plausible (must be either our listen
- * port or our advertised port), or any port if we are behind NAT
- * and do not have a port open.  If it is neither, we return
- * #GNUNET_SYSERR.
- *
- * @param plugin global variables
- * @param in_port port number to check
- * @return #GNUNET_OK if port is either open_port or adv_port
- */
-static int
-check_port (struct Plugin *plugin,
-           uint16_t in_port)
-{
-  if ( (in_port == plugin->adv_port) ||
-       (in_port == plugin->open_port) )
-    return GNUNET_OK;
-  return GNUNET_SYSERR;
-}
-
-
-/**
  * Function that will be called to check if a binary address for this
  * plugin is well-formed and corresponds to an address for THIS peer
  * (as per our configuration).  Naturally, if absolutely necessary,
@@ -2466,6 +2445,8 @@ tcp_plugin_check_address (void *cls,
 
   if (addrlen == sizeof(struct IPv4TcpAddress))
   {
+    struct sockaddr_in s4;
+    
     v4 = (const struct IPv4TcpAddress *) addr;
     if (0 != memcmp (&v4->options,
                      &plugin->myoptions,
@@ -2474,17 +2455,24 @@ tcp_plugin_check_address (void *cls,
       GNUNET_break (0);
       return GNUNET_SYSERR;
     }
-    if (GNUNET_OK != check_port (plugin,
-                                ntohs (v4->t4_port)))
-      return GNUNET_SYSERR;
+    memset (&s4, 0, sizeof (s4));
+    s4.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+    s4.sin_len = sizeof (s4);
+#endif
+    s4.sin_port = v4->t4_port;
+    s4.sin_addr.s_addr = v4->ipv4_addr;
+    
     if (GNUNET_OK !=
        GNUNET_NAT_test_address (plugin->nat,
-                                &v4->ipv4_addr,
-                                sizeof (struct in_addr)))
+                                &s4,
+                                sizeof (struct sockaddr_in)))
       return GNUNET_SYSERR;
   }
   else
   {
+    struct sockaddr_in6 s6;
+    
     v6 = (const struct IPv6TcpAddress *) addr;
     if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
     {
@@ -2498,13 +2486,18 @@ tcp_plugin_check_address (void *cls,
       GNUNET_break (0);
       return GNUNET_SYSERR;
     }
-    if (GNUNET_OK != check_port (plugin,
-                                ntohs (v6->t6_port)))
-      return GNUNET_SYSERR;
+    memset (&s6, 0, sizeof (s6));
+    s6.sin6_family = AF_INET6;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+    s6.sin6_len = sizeof (s6);
+#endif
+    s6.sin6_port = v6->t6_port;
+    s6.sin6_addr = v6->ipv6_addr;
+
     if (GNUNET_OK !=
        GNUNET_NAT_test_address (plugin->nat,
-                                &v6->ipv6_addr,
-                                sizeof(struct in6_addr)))
+                                &s6,
+                                sizeof(struct sockaddr_in6)))
       return GNUNET_SYSERR;
   }
   return GNUNET_OK;
diff --git a/src/transport/plugin_transport_udp.c 
b/src/transport/plugin_transport_udp.c
index c9fb754..8281e48 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -1245,31 +1245,48 @@ udp_plugin_check_address (void *cls,
 
   if (sizeof(struct IPv4UdpAddress) == addrlen)
   {
+    struct sockaddr_in s4;
+    
     v4 = (const struct IPv4UdpAddress *) addr;
     if (GNUNET_OK != check_port (plugin,
                                  ntohs (v4->u4_port)))
       return GNUNET_SYSERR;
+    memset (&s4, 0, sizeof (s4));
+    s4.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+    s4.sin_len = sizeof (s4);
+#endif
+    s4.sin_port = v4->u4_port;
+    s4.sin_addr.s_addr = v4->ipv4_addr;
+    
     if (GNUNET_OK !=
-        GNUNET_NAT_test_address (plugin->nat,
-                                 &v4->ipv4_addr,
-                                 sizeof (struct in_addr)))
+       GNUNET_NAT_test_address (plugin->nat,
+                                &s4,
+                                sizeof (struct sockaddr_in)))
       return GNUNET_SYSERR;
   }
   else if (sizeof(struct IPv6UdpAddress) == addrlen)
   {
+    struct sockaddr_in6 s6;
+
     v6 = (const struct IPv6UdpAddress *) addr;
     if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
     {
       GNUNET_break_op (0);
       return GNUNET_SYSERR;
     }
-    if (GNUNET_OK != check_port (plugin,
-                                 ntohs (v6->u6_port)))
-      return GNUNET_SYSERR;
+    memset (&s6, 0, sizeof (s6));
+    s6.sin6_family = AF_INET6;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+    s6.sin6_len = sizeof (s6);
+#endif
+    s6.sin6_port = v6->u6_port;
+    s6.sin6_addr = v6->ipv6_addr;
+
     if (GNUNET_OK !=
-        GNUNET_NAT_test_address (plugin->nat,
-                                 &v6->ipv6_addr,
-                                 sizeof (struct in6_addr)))
+       GNUNET_NAT_test_address (plugin->nat,
+                                &s6,
+                                sizeof(struct sockaddr_in6)))
       return GNUNET_SYSERR;
   }
   else

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]