-fix NPE
[oweals/gnunet.git] / src / transport / plugin_transport_tcp.c
index bc80dd1bf7af631ff71950c8845821a54f6d37d8..330b24f61aedb5ee4153a4d6623b512a11ca73a2 100644 (file)
@@ -14,8 +14,8 @@
 
   You should have received a copy of the GNU General Public License
   along with GNUnet; see the file COPYING.  If not, write to the
-  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-  Boston, MA 02111-1307, USA.
+  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+  Boston, MA 02110-1301, USA.
  */
 /**
  * @file transport/plugin_transport_tcp.c
@@ -154,7 +154,7 @@ struct IPv4TcpAddress
    * Optional options and flags for this address,
    * see `enum TcpAddressOptions`
    */
-  uint32_t options;
+  uint32_t options GNUNET_PACKED;
 
   /**
    * IPv4 address, in network byte order.
@@ -177,7 +177,7 @@ struct IPv6TcpAddress
    * Optional flags for this address
    * see `enum TcpAddressOptions`
    */
-  uint32_t options;
+  uint32_t options GNUNET_PACKED;
 
   /**
    * IPv6 address.
@@ -1887,6 +1887,9 @@ append_port (void *cls,
   struct Plugin *plugin = ppc->plugin;
   char *ret;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "append_port called with hostname `%s'\n",
+              hostname);
   if (NULL == hostname)
   {
     /* Final call, done */
@@ -1982,6 +1985,9 @@ tcp_plugin_address_pretty_printer (void *cls,
   else
   {
     /* invalid address */
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         _("Unexpected address length: %u bytes\n"),
+         (unsigned int) addrlen);
     asc (asc_cls, NULL, GNUNET_SYSERR);
     asc (asc_cls, NULL, GNUNET_OK);
     return;
@@ -1996,6 +2002,8 @@ tcp_plugin_address_pretty_printer (void *cls,
   ppc->asc_cls = asc_cls;
   ppc->port = port;
   ppc->options = options;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Starting DNS reverse lookup\n");
   ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb,
                                                        sbs,
                                                        ! numeric,
@@ -2545,6 +2553,8 @@ connect_notify (void *cls,
 {
   struct Plugin *plugin = cls;
 
+  if (NULL == client)
+    return;
   plugin->cur_connections++;
   GNUNET_STATISTICS_set (plugin->env->stats,
                          gettext_noop ("# TCP server connections active"),
@@ -2583,7 +2593,10 @@ disconnect_notify (void *cls,
 
   if (NULL == client)
     return;
-  session = lookup_session_by_client (plugin, client);
+  GNUNET_assert (plugin->cur_connections >= 1);
+  plugin->cur_connections--;
+  session = lookup_session_by_client (plugin,
+                                      client);
   if (NULL == session)
     return; /* unknown, nothing to do */
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2601,8 +2614,6 @@ disconnect_notify (void *cls,
                               GNUNET_NO);
     GNUNET_SERVER_resume (plugin->server); /* Resume server  */
   }
-  GNUNET_assert (plugin->cur_connections >= 1);
-  plugin->cur_connections--;
   GNUNET_STATISTICS_set (plugin->env->stats,
                          gettext_noop ("# TCP server connections active"),
                          plugin->cur_connections,
@@ -2949,7 +2960,7 @@ libgnunet_plugin_transport_tcp_init (void *cls)
                              (const struct sockaddr **) addrs, addrlens,
                              &tcp_nat_port_map_callback,
                              &try_connection_reversal,
-                             plugin);
+                             plugin, NULL);
     for (ret = ret_s -1; ret >= 0; ret--)
       GNUNET_free (addrs[ret]);
     GNUNET_free_non_null (addrs);
@@ -2965,7 +2976,8 @@ libgnunet_plugin_transport_tcp_init (void *cls)
                                        NULL,
                                        NULL,
                                        &try_connection_reversal,
-                                       plugin);
+                                       plugin,
+                                       NULL);
   }
   api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
   api->cls = plugin;
@@ -3102,7 +3114,7 @@ libgnunet_plugin_transport_tcp_done (void *cls)
     GNUNET_SERVICE_stop (plugin->service);
   else
     GNUNET_SERVER_destroy (plugin->server);
-  GNUNET_free(plugin->handlers);
+  GNUNET_free (plugin->handlers);
   if (NULL != plugin->nat)
     GNUNET_NAT_unregister (plugin->nat);
   while (NULL != (tcp_probe = plugin->probe_head))
@@ -3111,7 +3123,7 @@ libgnunet_plugin_transport_tcp_done (void *cls)
                                  plugin->probe_tail,
                                  tcp_probe);
     GNUNET_CONNECTION_destroy (tcp_probe->sock);
-    GNUNET_free(tcp_probe);
+    GNUNET_free (tcp_probe);
   }
   GNUNET_CONTAINER_multipeermap_destroy (plugin->nat_wait_conns);
   GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap);