gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r15949 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r15949 - gnunet/src/transport
Date: Wed, 13 Jul 2011 18:23:42 +0200

Author: wachs
Date: 2011-07-13 18:23:41 +0200 (Wed, 13 Jul 2011)
New Revision: 15949

Modified:
   gnunet/src/transport/plugin_transport_tcp.c
   gnunet/src/transport/plugin_transport_udp.c
Log:
printer: print ip if dns timeout occurs


Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2011-07-13 15:22:24 UTC (rev 
15948)
+++ gnunet/src/transport/plugin_transport_tcp.c 2011-07-13 16:23:41 UTC (rev 
15949)
@@ -1294,6 +1294,16 @@
   void *asc_cls;
 
   /**
+   * The address
+   */
+  void * addr;
+
+  /**
+   * address length
+   */
+  size_t addr_len;
+
+  /**
    * Port to add after the IP address.
    */
   uint16_t port;
@@ -1314,7 +1324,9 @@
 
   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;
     }
@@ -1388,10 +1400,13 @@
       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->addr = &ppc[1];
+  ppc->addr_len = addrlen;
+  memcpy(ppc->addr, addr, addrlen);
   GNUNET_RESOLVER_hostname_get (sb,
                                 sbs,
                                 !numeric, timeout, &append_port, ppc);

Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2011-07-13 15:22:24 UTC (rev 
15948)
+++ gnunet/src/transport/plugin_transport_udp.c 2011-07-13 16:23:41 UTC (rev 
15949)
@@ -129,11 +129,33 @@
 
 struct PrettyPrinterContext
 {
+  /**
+   * Function to call with the result.
+   */
   GNUNET_TRANSPORT_AddressStringCallback asc;
+
+  /**
+   * Clsoure for 'asc'.
+   */
   void *asc_cls;
+
+  /**
+   * The address
+   */
+  void * addr;
+
+  /**
+   * address length
+   */
+  size_t addr_len;
+
+  /**
+   * Port to add after the IP address.
+   */
   uint16_t port;
 };
 
+
 struct MessageQueue
 {
   /**
@@ -1256,6 +1278,61 @@
 
 
 /**
+ * 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.
  */
 static void
@@ -1266,7 +1343,9 @@
 
   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;
     }
@@ -1340,10 +1419,13 @@
       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->addr = &ppc[1];
+  ppc->addr_len = addrlen;
+  memcpy(ppc->addr, addr, addrlen);
   GNUNET_RESOLVER_hostname_get (sb,
                                 sbs,
                                 !numeric, timeout, &append_port, ppc);
@@ -1351,60 +1433,6 @@
 
 
 /**
- * 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.
  *
  * @param cls closure, the 'struct LocalAddrList'




reply via email to

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