[Telepathy-commits] [telepathy-gabble/master] SOCKS5: list IP6 addresses as well

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Tue Mar 10 08:42:15 PDT 2009


---
 src/bytestream-socks5.c |   35 +++++++++++++++++++++++++++++------
 1 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/src/bytestream-socks5.c b/src/bytestream-socks5.c
index 01b7c3b..1771b3c 100644
--- a/src/bytestream-socks5.c
+++ b/src/bytestream-socks5.c
@@ -1399,7 +1399,6 @@ static GList *
 get_local_interfaces_ips (gboolean include_loopback)
 {
   GList *ips = NULL;
-  struct sockaddr_in *sa;
   struct ifaddrs *ifa, *results;
   gchar *loopback = NULL;
 
@@ -1409,27 +1408,51 @@ get_local_interfaces_ips (gboolean include_loopback)
   /* Loop through the interface list and get the IP address of each IF */
   for (ifa = results; ifa; ifa = ifa->ifa_next)
     {
+      char straddr[INET6_ADDRSTRLEN];
+
       /* no ip address from interface that is down */
       if ((ifa->ifa_flags & IFF_UP) == 0)
         continue;
 
-      if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET)
+      if (ifa->ifa_addr == NULL)
         continue;
 
-      sa = (struct sockaddr_in *) ifa->ifa_addr;
+      if (ifa->ifa_addr->sa_family == AF_INET)
+        {
+          struct sockaddr_in *sa = (struct sockaddr_in *) ifa->ifa_addr;
+
+          inet_ntop (AF_INET, &sa->sin_addr, straddr, sizeof (straddr));
+        }
+      else if (ifa->ifa_addr->sa_family == AF_INET6)
+        {
+          struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) ifa->ifa_addr;
+
+          inet_ntop (AF_INET6, &sa6->sin6_addr, straddr, sizeof (straddr));
+
+          if (IN6_IS_ADDR_LINKLOCAL (&sa6->sin6_addr))
+            {
+              DEBUG ("Ignoring link-local address: %s", straddr);
+              continue;
+            }
+        }
+      else
+        {
+          continue;
+        }
+
 
       DEBUG ("Interface:  %s", ifa->ifa_name);
-      DEBUG ("IP Address: %s", inet_ntoa (sa->sin_addr));
+      DEBUG ("IP Address: %s", straddr);
       if ((ifa->ifa_flags & IFF_LOOPBACK) == IFF_LOOPBACK)
         {
           if (include_loopback)
-            loopback = g_strdup (inet_ntoa (sa->sin_addr));
+            loopback = g_strdup (straddr);
           else
             DEBUG ("Ignoring loopback interface");
         }
       else
         {
-          ips = g_list_append (ips, g_strdup (inet_ntoa (sa->sin_addr)));
+          ips = g_list_append (ips, g_strdup (straddr));
         }
     }
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list