indent
[oweals/gnunet.git] / src / transport / plugin_transport_udp.c
index 7067dc196d99427675e917ea6e28149ec11a4593..582d083dcf1c3f1892af975af822f4688caebbb1 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -99,12 +99,12 @@ struct IPv4UdpAddress
   /**
    * IPv4 address, in network byte order.
    */
-  uint32_t ipv4_addr;
+  uint32_t ipv4_addr GNUNET_PACKED;
 
   /**
    * Port number, in network byte order.
    */
-  uint16_t u_port;
+  uint16_t u_port GNUNET_PACKED;
 };
 
 
@@ -116,12 +116,12 @@ struct IPv6UdpAddress
   /**
    * IPv6 address.
    */
-  struct in6_addr ipv6_addr;
+  struct in6_addr ipv6_addr GNUNET_PACKED;
 
   /**
    * Port number, in network byte order.
    */
-  uint16_t u6_port;
+  uint16_t u6_port GNUNET_PACKED;
 };
 
 /* Forward definition */
@@ -1406,7 +1406,7 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
     default:
 #if DEBUG_UDP
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                       _("Sending message type %d to transport\n!"), ntohs(currhdr->type));
+                       _("Sending message type %d to transport!\n"), ntohs(currhdr->type));
 #endif
       plugin->env->receive (plugin->env->cls, sender, currhdr, UDP_DIRECT_DISTANCE, 
                            NULL, sender_addr, fromlen);
@@ -1616,9 +1616,10 @@ udp_transport_server_start (void *cls)
           {
             serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
 #if DEBUG_UDP
-        GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
-                        "udp",
-                        "Binding failed, trying new port %d\n", ntohs(serverAddrv4.sin_port));
+           GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+                            "udp",
+                            "Binding failed, trying new port %d\n", 
+                            ntohs(serverAddrv4.sin_port));
 #endif
           }
         udp_sock.port = ntohs(serverAddrv4.sin_port);
@@ -1680,8 +1681,7 @@ check_port (struct Plugin *plugin, uint16_t in_port)
   if ( (plugin->behind_nat == GNUNET_YES) && (in_port == 0) )
     return GNUNET_OK;
   if ( (plugin->only_nat_addresses == GNUNET_YES) &&
-       (plugin->behind_nat == GNUNET_YES) &&
-       (in_port != 0) )
+       (plugin->behind_nat == GNUNET_YES) )
     return GNUNET_SYSERR; /* odd case... */
   if (in_port == plugin->port) 
     return GNUNET_OK;
@@ -1711,6 +1711,12 @@ udp_check_address (void *cls,
                   size_t addrlen)
 {
   struct Plugin *plugin = cls;
+  char buf[INET6_ADDRSTRLEN];
+  const void *sb;
+  struct in_addr a4;
+  struct in6_addr a6;
+  int af;
+  uint16_t port;
   struct IPv4UdpAddress *v4;
   struct IPv6UdpAddress *v6;
 
@@ -1720,6 +1726,7 @@ udp_check_address (void *cls,
       GNUNET_break_op (0);
       return GNUNET_SYSERR;
     }
+
   if (addrlen == sizeof (struct IPv4UdpAddress))
     {
       v4 = (struct IPv4UdpAddress *) addr;
@@ -1729,6 +1736,11 @@ udp_check_address (void *cls,
       if (GNUNET_OK !=
          check_local_addr (plugin, &v4->ipv4_addr, sizeof (uint32_t)))
        return GNUNET_SYSERR;
+
+      af = AF_INET;
+      port = ntohs (v4->u_port);
+      memcpy (&a4, &v4->ipv4_addr, sizeof (a4));
+      sb = &a4;
     }
   else
     {
@@ -1744,12 +1756,21 @@ udp_check_address (void *cls,
       if (GNUNET_OK !=
          check_local_addr (plugin, &v6->ipv6_addr, sizeof (struct in6_addr)))
        return GNUNET_SYSERR;
+
+      af = AF_INET6;
+      port = ntohs (v6->u6_port);
+      memcpy (&a6, &v6->ipv6_addr, sizeof (a6));
+      sb = &a6;
     }
+
+  inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
+
 #if DEBUG_UDP
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
                    "udp",
-                   "Informing transport service about my address `%s'.\n",
-                   GNUNET_a2s (addr, addrlen));
+                   "Informing transport service about my address `%s:%u'\n",
+                   buf,
+                   port);
 #endif
   return GNUNET_OK;
 }