- fix ipv6 address format for tcp pretty printer
authorMatthias Wachs <wachs@net.in.tum.de>
Mon, 2 Apr 2012 13:55:53 +0000 (13:55 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Mon, 2 Apr 2012 13:55:53 +0000 (13:55 +0000)
src/transport/gnunet-service-transport_clients.c
src/transport/plugin_transport_tcp.c

index d6ff55449bee13bdcf93a03832c113c5d50ae02b..227f4f093c782393d54a8393f7e0bb34f28a7609 100644 (file)
@@ -788,6 +788,10 @@ clients_handle_address_to_string (void *cls,
     return;
   }
   GNUNET_SERVER_disable_receive_done_warning (client);
+  if ((NULL == address) || (0 == address_len))
+  {
+    GNUNET_break_op (0);
+  }
   papi->address_pretty_printer (papi->cls, plugin_name, address, address_len,
                                 numeric, rtimeout, &transmit_address_to_client,
                                 tc);
index 95041d89929737f5f066d1b1ae4174fd7a146c30..2fa96b464949d4e2cc0796d6e81ec6d77940bcb4 100644 (file)
@@ -1369,6 +1369,8 @@ struct PrettyPrinterContext
    * Port to add after the IP address.
    */
   uint16_t port;
+
+  int ipv6;
 };
 
 
@@ -1390,7 +1392,10 @@ append_port (void *cls, const char *hostname)
     GNUNET_free (ppc);
     return;
   }
-  GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
+  if (GNUNET_YES == ppc->ipv6)
+    GNUNET_asprintf (&ret, "[%s]:%d", hostname, ppc->port);
+  else
+    GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
   ppc->asc (ppc->asc_cls, ret);
   GNUNET_free (ret);
 }
@@ -1452,11 +1457,17 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type,
   else
   {
     /* invalid address */
+    GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp",
+        "Invalid address to string request: plugin `%s', address length: %u bytes\n");
     GNUNET_break_op (0);
     asc (asc_cls, NULL);
     return;
   }
   ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
+  if (addrlen == sizeof (struct IPv6TcpAddress))
+    ppc->ipv6 = GNUNET_YES;
+  else
+    ppc->ipv6 = GNUNET_NO;
   ppc->asc = asc;
   ppc->asc_cls = asc_cls;
   ppc->port = port;