gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r11154 - gnunet/src/transport
Date: Mon, 3 May 2010 08:59:13 +0200

Author: grothoff
Date: 2010-05-03 08:59:13 +0200 (Mon, 03 May 2010)
New Revision: 11154

Modified:
   gnunet/src/transport/plugin_transport_tcp.c
   gnunet/src/transport/plugin_transport_udp.c
Log:
inet_ntop

Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2010-05-02 23:22:21 UTC (rev 
11153)
+++ gnunet/src/transport/plugin_transport_tcp.c 2010-05-03 06:59:13 UTC (rev 
11154)
@@ -316,39 +316,41 @@
                       const void *addr,
                       size_t addrlen)
 {
-  static char buf[INET6_ADDRSTRLEN];
+  static char rbuf[INET6_ADDRSTRLEN + 10];
+  char buf[INET6_ADDRSTRLEN];
   const void *sb;
-  struct sockaddr_in a4;
-  struct sockaddr_in6 a6;
+  struct in_addr a4;
+  struct in6_addr a6;
   const struct IPv4TcpAddress *t4;
   const struct IPv6TcpAddress *t6;
   int af;
+  uint16_t port;
 
   if (addrlen == sizeof (struct IPv6TcpAddress))
     {
       t6 = addr;
       af = AF_INET6;
-      memset (&a6, 0, sizeof (a6));
-      a6.sin6_family = AF_INET6;
-      a6.sin6_port = t6->t6_port;
-      memcpy (a6.sin6_addr.s6_addr,
-             t6->ipv6_addr,
-             16);      
+      port = ntohs (t6->t6_port);
+      memcpy (&a6, t6->ipv6_addr, sizeof (a6));
       sb = &a6;
     }
   else if (addrlen == sizeof (struct IPv4TcpAddress))
     {
       t4 = addr;
       af = AF_INET;
-      memset (&a4, 0, sizeof (a4));
-      a4.sin_family = AF_INET;
-      a4.sin_port = t4->t_port;
-      a4.sin_addr.s_addr = t4->ipv4_addr;
+      port = ntohs (t4->t_port);
+      memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
       sb = &a4;
     }
   else
     return NULL;
-  return inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
+  inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
+  GNUNET_snprintf (rbuf,
+                  sizeof (rbuf),
+                  "%s:%u",
+                  buf,
+                  port);
+  return rbuf;
 }
 
 

Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2010-05-02 23:22:21 UTC (rev 
11153)
+++ gnunet/src/transport/plugin_transport_udp.c 2010-05-03 06:59:13 UTC (rev 
11154)
@@ -846,40 +846,41 @@
                       const void *addr,
                       size_t addrlen)
 {
-  static char buf[INET6_ADDRSTRLEN];
+  static char rbuf[INET6_ADDRSTRLEN + 10];
+  char buf[INET6_ADDRSTRLEN];
   const void *sb;
-  struct sockaddr_in a4;
-  struct sockaddr_in6 a6;
+  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;
-      memset (&a6, 0, sizeof (a6));
-      a6.sin6_family = AF_INET6;
-      a6.sin6_port = t6->u6_port;
-      memcpy (a6.sin6_addr.s6_addr,
-             t6->ipv6_addr,
-             16);      
+      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;
-      memset (&a4, 0, sizeof (a4));
-      a4.sin_family = AF_INET;
-      a4.sin_port = t4->u_port;
-      a4.sin_addr.s_addr = t4->ipv4_addr;
+      port = ntohs (t4->u_port);
+      memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
       sb = &a4;
     }
   else
     return NULL;
-  
-  return inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
+  inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
+  GNUNET_snprintf (rbuf,
+                  sizeof (rbuf),
+                  "%s:%u",
+                  buf,
+                  port);
+  return rbuf;
 }
 
 





reply via email to

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