diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-05-03 06:59:13 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-05-03 06:59:13 +0000 |
commit | a894ddc0a376fa59850b410b43d3c9331c847677 (patch) | |
tree | 125ad36b7b7b7b888b4aba2f773493cb67c807f6 /src/transport/plugin_transport_tcp.c | |
parent | 2c8eb2f20999f03d781045d7d5bdadf748fe3cfc (diff) | |
download | gnunet-a894ddc0a376fa59850b410b43d3c9331c847677.tar.gz gnunet-a894ddc0a376fa59850b410b43d3c9331c847677.zip |
inet_ntop
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index fad999fa4..d4212631a 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -316,39 +316,41 @@ tcp_address_to_string (void *cls, | |||
316 | const void *addr, | 316 | const void *addr, |
317 | size_t addrlen) | 317 | size_t addrlen) |
318 | { | 318 | { |
319 | static char buf[INET6_ADDRSTRLEN]; | 319 | static char rbuf[INET6_ADDRSTRLEN + 10]; |
320 | char buf[INET6_ADDRSTRLEN]; | ||
320 | const void *sb; | 321 | const void *sb; |
321 | struct sockaddr_in a4; | 322 | struct in_addr a4; |
322 | struct sockaddr_in6 a6; | 323 | struct in6_addr a6; |
323 | const struct IPv4TcpAddress *t4; | 324 | const struct IPv4TcpAddress *t4; |
324 | const struct IPv6TcpAddress *t6; | 325 | const struct IPv6TcpAddress *t6; |
325 | int af; | 326 | int af; |
327 | uint16_t port; | ||
326 | 328 | ||
327 | if (addrlen == sizeof (struct IPv6TcpAddress)) | 329 | if (addrlen == sizeof (struct IPv6TcpAddress)) |
328 | { | 330 | { |
329 | t6 = addr; | 331 | t6 = addr; |
330 | af = AF_INET6; | 332 | af = AF_INET6; |
331 | memset (&a6, 0, sizeof (a6)); | 333 | port = ntohs (t6->t6_port); |
332 | a6.sin6_family = AF_INET6; | 334 | memcpy (&a6, t6->ipv6_addr, sizeof (a6)); |
333 | a6.sin6_port = t6->t6_port; | ||
334 | memcpy (a6.sin6_addr.s6_addr, | ||
335 | t6->ipv6_addr, | ||
336 | 16); | ||
337 | sb = &a6; | 335 | sb = &a6; |
338 | } | 336 | } |
339 | else if (addrlen == sizeof (struct IPv4TcpAddress)) | 337 | else if (addrlen == sizeof (struct IPv4TcpAddress)) |
340 | { | 338 | { |
341 | t4 = addr; | 339 | t4 = addr; |
342 | af = AF_INET; | 340 | af = AF_INET; |
343 | memset (&a4, 0, sizeof (a4)); | 341 | port = ntohs (t4->t_port); |
344 | a4.sin_family = AF_INET; | 342 | memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); |
345 | a4.sin_port = t4->t_port; | ||
346 | a4.sin_addr.s_addr = t4->ipv4_addr; | ||
347 | sb = &a4; | 343 | sb = &a4; |
348 | } | 344 | } |
349 | else | 345 | else |
350 | return NULL; | 346 | return NULL; |
351 | return inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); | 347 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); |
348 | GNUNET_snprintf (rbuf, | ||
349 | sizeof (rbuf), | ||
350 | "%s:%u", | ||
351 | buf, | ||
352 | port); | ||
353 | return rbuf; | ||
352 | } | 354 | } |
353 | 355 | ||
354 | 356 | ||