[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18742 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18742 - gnunet/src/transport |
Date: |
Wed, 21 Dec 2011 15:33:14 +0100 |
Author: wachs
Date: 2011-12-21 15:33:14 +0100 (Wed, 21 Dec 2011)
New Revision: 18742
Modified:
gnunet/src/transport/plugin_transport_http.c
Log:
fixed assertion in gnunet-service resolver
improved address printing for IPv6 addresses, especially if reverse lookup is
not successful
Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c 2011-12-21 14:26:50 UTC
(rev 18741)
+++ gnunet/src/transport/plugin_transport_http.c 2011-12-21 14:33:14 UTC
(rev 18742)
@@ -94,6 +94,10 @@
* Port to add after the IP address.
*/
uint16_t port;
+
+ uint32_t addrlen;
+
+ int numeric;
};
@@ -114,7 +118,7 @@
append_port (void *cls, const char *hostname)
{
struct PrettyPrinterContext *ppc = cls;
- char *ret;
+ static char rbuf[INET6_ADDRSTRLEN + 13];
if (hostname == NULL)
{
@@ -122,10 +126,28 @@
GNUNET_free (ppc);
return;
}
- GNUNET_asprintf (&ret, "%s://%s:%d", ppc->plugin->protocol, hostname,
- ppc->plugin->port);
- ppc->asc (ppc->asc_cls, ret);
- GNUNET_free (ret);
+
+#if !BUILD_HTTPS
+ const char *protocol = "http";
+#else
+ const char *protocol = "https";
+#endif
+ GNUNET_assert ((strlen (hostname) + 7) < (INET6_ADDRSTRLEN + 13));
+ if (ppc->addrlen == sizeof (struct IPv6HttpAddress))
+ {
+ if (ppc->numeric == GNUNET_YES)
+ GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol,
hostname, ppc->port);
+ else
+ {
+ if (strchr(hostname, ':') != NULL)
+ GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol,
hostname, ppc->port);
+ else
+ GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol,
hostname, ppc->port);
+ }
+ }
+ else if (ppc->addrlen == sizeof (struct IPv4HttpAddress))
+ GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, hostname,
ppc->port);
+ ppc->asc (ppc->asc_cls, rbuf);
}
@@ -154,23 +176,37 @@
GNUNET_assert (cls != NULL);
struct PrettyPrinterContext *ppc;
const void *sb;
+ struct sockaddr_in s4;
+ struct sockaddr_in6 s6;
size_t sbs;
uint16_t port = 0;
if (addrlen == sizeof (struct IPv6HttpAddress))
{
struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
+ s6.sin6_family = AF_INET6;
+ s6.sin6_addr = a6->ipv6_addr;
+ s6.sin6_port = a6->u6_port;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ s6.sin6_len = sizeof (struct sockaddr_in6);
+#endif
+ sb = &s6;
+ sbs = sizeof (struct sockaddr_in6);
+ port = ntohs (a6->u6_port);
- sb = &a6->ipv6_addr;
- sbs = sizeof (struct in6_addr);
- port = ntohs (a6->u6_port);
}
else if (addrlen == sizeof (struct IPv4HttpAddress))
{
struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
- sb = &a4->ipv4_addr;
- sbs = sizeof (struct in_addr);
+ s4.sin_family = AF_INET;
+ s4.sin_addr.s_addr = a4->ipv4_addr;
+ s4.sin_port = a4->u4_port;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ s4.sin_len = sizeof (struct sockaddr_in);
+#endif
+ sb = &s4;
+ sbs = sizeof (struct sockaddr_in);
port = ntohs (a4->u4_port);
}
else
@@ -185,6 +221,8 @@
ppc->asc_cls = asc_cls;
ppc->port = port;
ppc->plugin = cls;
+ ppc->addrlen = addrlen;
+ ppc->numeric = numeric;
GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18742 - gnunet/src/transport,
gnunet <=