aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-12-21 14:33:14 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-12-21 14:33:14 +0000
commit67b59bad2903f7a4a5fd81977e739600dd225f38 (patch)
tree4a1d4f085b2f96c497923568c9e3b083c5f1bb4c /src/transport/plugin_transport_http.c
parent8fe3f5934e4706f599410ef9c5a5b79bb7e3c875 (diff)
downloadgnunet-67b59bad2903f7a4a5fd81977e739600dd225f38.tar.gz
gnunet-67b59bad2903f7a4a5fd81977e739600dd225f38.zip
fixed assertion in gnunet-service resolver
improved address printing for IPv6 addresses, especially if reverse lookup is not successful
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r--src/transport/plugin_transport_http.c58
1 files changed, 48 insertions, 10 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 177a71719..d993edb6b 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -94,6 +94,10 @@ struct PrettyPrinterContext
94 * Port to add after the IP address. 94 * Port to add after the IP address.
95 */ 95 */
96 uint16_t port; 96 uint16_t port;
97
98 uint32_t addrlen;
99
100 int numeric;
97}; 101};
98 102
99 103
@@ -114,7 +118,7 @@ static void
114append_port (void *cls, const char *hostname) 118append_port (void *cls, const char *hostname)
115{ 119{
116 struct PrettyPrinterContext *ppc = cls; 120 struct PrettyPrinterContext *ppc = cls;
117 char *ret; 121 static char rbuf[INET6_ADDRSTRLEN + 13];
118 122
119 if (hostname == NULL) 123 if (hostname == NULL)
120 { 124 {
@@ -122,10 +126,28 @@ append_port (void *cls, const char *hostname)
122 GNUNET_free (ppc); 126 GNUNET_free (ppc);
123 return; 127 return;
124 } 128 }
125 GNUNET_asprintf (&ret, "%s://%s:%d", ppc->plugin->protocol, hostname, 129
126 ppc->plugin->port); 130#if !BUILD_HTTPS
127 ppc->asc (ppc->asc_cls, ret); 131 const char *protocol = "http";
128 GNUNET_free (ret); 132#else
133 const char *protocol = "https";
134#endif
135 GNUNET_assert ((strlen (hostname) + 7) < (INET6_ADDRSTRLEN + 13));
136 if (ppc->addrlen == sizeof (struct IPv6HttpAddress))
137 {
138 if (ppc->numeric == GNUNET_YES)
139 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, hostname, ppc->port);
140 else
141 {
142 if (strchr(hostname, ':') != NULL)
143 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, hostname, ppc->port);
144 else
145 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, hostname, ppc->port);
146 }
147 }
148 else if (ppc->addrlen == sizeof (struct IPv4HttpAddress))
149 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, hostname, ppc->port);
150 ppc->asc (ppc->asc_cls, rbuf);
129} 151}
130 152
131 153
@@ -154,23 +176,37 @@ http_plugin_address_pretty_printer (void *cls, const char *type,
154 GNUNET_assert (cls != NULL); 176 GNUNET_assert (cls != NULL);
155 struct PrettyPrinterContext *ppc; 177 struct PrettyPrinterContext *ppc;
156 const void *sb; 178 const void *sb;
179 struct sockaddr_in s4;
180 struct sockaddr_in6 s6;
157 size_t sbs; 181 size_t sbs;
158 uint16_t port = 0; 182 uint16_t port = 0;
159 183
160 if (addrlen == sizeof (struct IPv6HttpAddress)) 184 if (addrlen == sizeof (struct IPv6HttpAddress))
161 { 185 {
162 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr; 186 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
163 187 s6.sin6_family = AF_INET6;
164 sb = &a6->ipv6_addr; 188 s6.sin6_addr = a6->ipv6_addr;
165 sbs = sizeof (struct in6_addr); 189 s6.sin6_port = a6->u6_port;
190#if HAVE_SOCKADDR_IN_SIN_LEN
191 s6.sin6_len = sizeof (struct sockaddr_in6);
192#endif
193 sb = &s6;
194 sbs = sizeof (struct sockaddr_in6);
166 port = ntohs (a6->u6_port); 195 port = ntohs (a6->u6_port);
196
167 } 197 }
168 else if (addrlen == sizeof (struct IPv4HttpAddress)) 198 else if (addrlen == sizeof (struct IPv4HttpAddress))
169 { 199 {
170 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr; 200 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
171 201
172 sb = &a4->ipv4_addr; 202 s4.sin_family = AF_INET;
173 sbs = sizeof (struct in_addr); 203 s4.sin_addr.s_addr = a4->ipv4_addr;
204 s4.sin_port = a4->u4_port;
205#if HAVE_SOCKADDR_IN_SIN_LEN
206 s4.sin_len = sizeof (struct sockaddr_in);
207#endif
208 sb = &s4;
209 sbs = sizeof (struct sockaddr_in);
174 port = ntohs (a4->u4_port); 210 port = ntohs (a4->u4_port);
175 } 211 }
176 else 212 else
@@ -185,6 +221,8 @@ http_plugin_address_pretty_printer (void *cls, const char *type,
185 ppc->asc_cls = asc_cls; 221 ppc->asc_cls = asc_cls;
186 ppc->port = port; 222 ppc->port = port;
187 ppc->plugin = cls; 223 ppc->plugin = cls;
224 ppc->addrlen = addrlen;
225 ppc->numeric = numeric;
188 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc); 226 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
189} 227}
190 228