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_udp.c | |
parent | 2c8eb2f20999f03d781045d7d5bdadf748fe3cfc (diff) | |
download | gnunet-a894ddc0a376fa59850b410b43d3c9331c847677.tar.gz gnunet-a894ddc0a376fa59850b410b43d3c9331c847677.zip |
inet_ntop
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 0e7f4d126..689d75b74 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -846,40 +846,41 @@ udp_address_to_string (void *cls, | |||
846 | const void *addr, | 846 | const void *addr, |
847 | size_t addrlen) | 847 | size_t addrlen) |
848 | { | 848 | { |
849 | static char buf[INET6_ADDRSTRLEN]; | 849 | static char rbuf[INET6_ADDRSTRLEN + 10]; |
850 | char buf[INET6_ADDRSTRLEN]; | ||
850 | const void *sb; | 851 | const void *sb; |
851 | struct sockaddr_in a4; | 852 | struct in_addr a4; |
852 | struct sockaddr_in6 a6; | 853 | struct in6_addr a6; |
853 | const struct IPv4UdpAddress *t4; | 854 | const struct IPv4UdpAddress *t4; |
854 | const struct IPv6UdpAddress *t6; | 855 | const struct IPv6UdpAddress *t6; |
855 | int af; | 856 | int af; |
857 | uint16_t port; | ||
856 | 858 | ||
857 | if (addrlen == sizeof (struct IPv6UdpAddress)) | 859 | if (addrlen == sizeof (struct IPv6UdpAddress)) |
858 | { | 860 | { |
859 | t6 = addr; | 861 | t6 = addr; |
860 | af = AF_INET6; | 862 | af = AF_INET6; |
861 | memset (&a6, 0, sizeof (a6)); | 863 | port = ntohs (t6->u6_port); |
862 | a6.sin6_family = AF_INET6; | 864 | memcpy (&a6, t6->ipv6_addr, sizeof (a6)); |
863 | a6.sin6_port = t6->u6_port; | ||
864 | memcpy (a6.sin6_addr.s6_addr, | ||
865 | t6->ipv6_addr, | ||
866 | 16); | ||
867 | sb = &a6; | 865 | sb = &a6; |
868 | } | 866 | } |
869 | else if (addrlen == sizeof (struct IPv4UdpAddress)) | 867 | else if (addrlen == sizeof (struct IPv4UdpAddress)) |
870 | { | 868 | { |
871 | t4 = addr; | 869 | t4 = addr; |
872 | af = AF_INET; | 870 | af = AF_INET; |
873 | memset (&a4, 0, sizeof (a4)); | 871 | port = ntohs (t4->u_port); |
874 | a4.sin_family = AF_INET; | 872 | memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); |
875 | a4.sin_port = t4->u_port; | ||
876 | a4.sin_addr.s_addr = t4->ipv4_addr; | ||
877 | sb = &a4; | 873 | sb = &a4; |
878 | } | 874 | } |
879 | else | 875 | else |
880 | return NULL; | 876 | return NULL; |
881 | 877 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); | |
882 | return inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); | 878 | GNUNET_snprintf (rbuf, |
879 | sizeof (rbuf), | ||
880 | "%s:%u", | ||
881 | buf, | ||
882 | port); | ||
883 | return rbuf; | ||
883 | } | 884 | } |
884 | 885 | ||
885 | 886 | ||