printer: print ip if dns timeout occurs
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 13 Jul 2011 16:23:41 +0000 (16:23 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 13 Jul 2011 16:23:41 +0000 (16:23 +0000)
src/transport/plugin_transport_tcp.c
src/transport/plugin_transport_udp.c

index 168a2b344920fc6ae6c96fb62c63a383266bb057..2a5cfaa8d82054e452f5af5fcb08dd1963784470 100644 (file)
@@ -1293,6 +1293,16 @@ struct PrettyPrinterContext
    */
   void *asc_cls;
 
    */
   void *asc_cls;
 
+  /**
+   * The address
+   */
+  void * addr;
+
+  /**
+   * address length
+   */
+  size_t addr_len;
+
   /**
    * Port to add after the IP address.
    */
   /**
    * Port to add after the IP address.
    */
@@ -1314,7 +1324,9 @@ append_port (void *cls, const char *hostname)
 
   if (hostname == NULL)
     {
 
   if (hostname == NULL)
     {
-      ppc->asc (ppc->asc_cls, NULL);
+      ret = strdup(tcp_address_to_string(NULL, ppc->addr, ppc->addr_len));
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error in name resolution: `%s'\n",ret);
+      ppc->asc (ppc->asc_cls, ret);
       GNUNET_free (ppc);
       return;
     }
       GNUNET_free (ppc);
       return;
     }
@@ -1388,10 +1400,13 @@ tcp_plugin_address_pretty_printer (void *cls,
       asc (asc_cls, NULL);
       return;
     }
       asc (asc_cls, NULL);
       return;
     }
-  ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
+  ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext) + addrlen);
   ppc->asc = asc;
   ppc->asc_cls = asc_cls;
   ppc->port = port;
   ppc->asc = asc;
   ppc->asc_cls = asc_cls;
   ppc->port = port;
+  ppc->addr = &ppc[1];
+  ppc->addr_len = addrlen;
+  memcpy(ppc->addr, addr, addrlen);
   GNUNET_RESOLVER_hostname_get (sb,
                                 sbs,
                                 !numeric, timeout, &append_port, ppc);
   GNUNET_RESOLVER_hostname_get (sb,
                                 sbs,
                                 !numeric, timeout, &append_port, ppc);
index e5e741df399b54be1f40a4faf9be8d9812bb78c8..b3a64b28631b75df4d57d50fad6550709ec309b8 100644 (file)
@@ -129,11 +129,33 @@ struct Plugin;
 
 struct PrettyPrinterContext
 {
 
 struct PrettyPrinterContext
 {
+  /**
+   * Function to call with the result.
+   */
   GNUNET_TRANSPORT_AddressStringCallback asc;
   GNUNET_TRANSPORT_AddressStringCallback asc;
+
+  /**
+   * Clsoure for 'asc'.
+   */
   void *asc_cls;
   void *asc_cls;
+
+  /**
+   * The address
+   */
+  void * addr;
+
+  /**
+   * address length
+   */
+  size_t addr_len;
+
+  /**
+   * Port to add after the IP address.
+   */
   uint16_t port;
 };
 
   uint16_t port;
 };
 
+
 struct MessageQueue
 {
   /**
 struct MessageQueue
 {
   /**
@@ -1255,6 +1277,61 @@ udp_plugin_check_address (void *cls,
 }
 
 
 }
 
 
+/**
+ * Function called for a quick conversion of the binary address to
+ * a numeric address.  Note that the caller must not free the
+ * address and that the next call to this function is allowed
+ * to override the address again.
+ *
+ * @param cls closure
+ * @param addr binary address
+ * @param addrlen length of the address
+ * @return string representing the same address
+ */
+static const char*
+udp_address_to_string (void *cls,
+                       const void *addr,
+                       size_t addrlen)
+{
+  static char rbuf[INET6_ADDRSTRLEN + 10];
+  char buf[INET6_ADDRSTRLEN];
+  const void *sb;
+  struct in_addr a4;
+  struct in6_addr a6;
+  const struct IPv4UdpAddress *t4;
+  const struct IPv6UdpAddress *t6;
+  int af;
+  uint16_t port;
+
+  if (addrlen == sizeof (struct IPv6UdpAddress))
+    {
+      t6 = addr;
+      af = AF_INET6;
+      port = ntohs (t6->u6_port);
+      memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
+      sb = &a6;
+    }
+  else if (addrlen == sizeof (struct IPv4UdpAddress))
+    {
+      t4 = addr;
+      af = AF_INET;
+      port = ntohs (t4->u4_port);
+      memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
+      sb = &a4;
+    }
+  else
+    return NULL;
+  inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
+  GNUNET_snprintf (rbuf,
+                   sizeof (rbuf),
+                   "%s:%u",
+                   buf,
+                   port);
+  return rbuf;
+}
+
+
+
 /**
  * Append our port and forward the result.
  */
 /**
  * Append our port and forward the result.
  */
@@ -1266,7 +1343,9 @@ append_port (void *cls, const char *hostname)
 
   if (hostname == NULL)
     {
 
   if (hostname == NULL)
     {
-      ppc->asc (ppc->asc_cls, NULL);
+      ret = strdup(udp_address_to_string(NULL, ppc->addr, ppc->addr_len));
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error in name resolution: `%s'\n",ret);
+      ppc->asc (ppc->asc_cls, ret);
       GNUNET_free (ppc);
       return;
     }
       GNUNET_free (ppc);
       return;
     }
@@ -1340,70 +1419,19 @@ udp_plugin_address_pretty_printer (void *cls,
       asc (asc_cls, NULL);
       return;
     }
       asc (asc_cls, NULL);
       return;
     }
-  ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
+  ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext) + addrlen);
   ppc->asc = asc;
   ppc->asc_cls = asc_cls;
   ppc->port = port;
   ppc->asc = asc;
   ppc->asc_cls = asc_cls;
   ppc->port = port;
+  ppc->addr = &ppc[1];
+  ppc->addr_len = addrlen;
+  memcpy(ppc->addr, addr, addrlen);
   GNUNET_RESOLVER_hostname_get (sb,
                                 sbs,
                                 !numeric, timeout, &append_port, ppc);
 }
 
 
   GNUNET_RESOLVER_hostname_get (sb,
                                 sbs,
                                 !numeric, timeout, &append_port, ppc);
 }
 
 
-/**
- * Function called for a quick conversion of the binary address to
- * a numeric address.  Note that the caller must not free the
- * address and that the next call to this function is allowed
- * to override the address again.
- *
- * @param cls closure
- * @param addr binary address
- * @param addrlen length of the address
- * @return string representing the same address
- */
-static const char*
-udp_address_to_string (void *cls,
-                       const void *addr,
-                       size_t addrlen)
-{
-  static char rbuf[INET6_ADDRSTRLEN + 10];
-  char buf[INET6_ADDRSTRLEN];
-  const void *sb;
-  struct in_addr a4;
-  struct in6_addr a6;
-  const struct IPv4UdpAddress *t4;
-  const struct IPv6UdpAddress *t6;
-  int af;
-  uint16_t port;
-
-  if (addrlen == sizeof (struct IPv6UdpAddress))
-    {
-      t6 = addr;
-      af = AF_INET6;
-      port = ntohs (t6->u6_port);
-      memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
-      sb = &a6;
-    }
-  else if (addrlen == sizeof (struct IPv4UdpAddress))
-    {
-      t4 = addr;
-      af = AF_INET;
-      port = ntohs (t4->u4_port);
-      memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
-      sb = &a4;
-    }
-  else
-    return NULL;
-  inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
-  GNUNET_snprintf (rbuf,
-                   sizeof (rbuf),
-                   "%s:%u",
-                   buf,
-                   port);
-  return rbuf;
-}
-
-
 /**
  * Our external IP address/port mapping has changed.
  *
 /**
  * Our external IP address/port mapping has changed.
  *