[vinagre] Make code is compatible with diffrent ifaddrs structures



commit 394feb632bb59e8d87bb03acf32add311806ba23
Author: Halton Huo <halton huo sun com>
Date:   Mon Jun 7 10:31:08 2010 -0300

    Make code is compatible with diffrent ifaddrs structures
    
    OpenSolaris (after b137) uses "struct sockaddr_storage", not "struct sockaddr"
    for ifa_addr member of "struct ifaddrs". This is followed RFC2553. Before
    BSD and Linux systems move to follow RFC2553, the codes need to be compiled
    under both cases.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=617862

 configure.ac                              |   17 ++++++++++++++++-
 plugins/vnc/vinagre-vnc-listener-dialog.c |    8 +++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f7e8631..3267e2a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -226,8 +226,23 @@ dnl *** Checks for ifaddrs.h ***
 dnl ****************************
 AC_CHECK_HEADER(ifaddrs.h)
 AM_CONDITIONAL(SELF_IFADDRS, test "x$ac_cv_header_ifaddrs_h" != "xyes")
+
+dnl RFC2553 introduce sockaddr_storage as ifa_addr member in ifaddrs structure
+dnl Not all distros follow this.
 if test "x$ac_cv_header_ifaddrs_h" = "xyes"; then
-  AC_DEFINE(HAVE_IFADDRS_H, [1], [Define if we have system ifaddrs.h])
+        AC_DEFINE(HAVE_IFADDRS_H, [1], [Define if we have system ifaddrs.h])
+        AC_TRY_COMPILE([
+          #include <ifaddrs.h>
+          #include <net/if.h>
+          ],[
+          struct ifaddrs *myaddrs;
+          getifaddrs (&myaddrs);
+          if (myaddrs->ifa_addr->ss_family == AF_INET) {
+          }
+        ], have_sockaddr_storage=yes, have_sockaddr_storage=no)
+        if test "x$have_sockaddr_storage" = "xyes"; then
+           AC_DEFINE(RFC2553, [], [Define to if follow RFC2553 ])
+        fi
 fi
 
 
diff --git a/plugins/vnc/vinagre-vnc-listener-dialog.c b/plugins/vnc/vinagre-vnc-listener-dialog.c
index 6da6902..46fff70 100644
--- a/plugins/vnc/vinagre-vnc-listener-dialog.c
+++ b/plugins/vnc/vinagre-vnc-listener-dialog.c
@@ -30,6 +30,12 @@
 #include "if/ifaddrs.h"
 #endif
 
+#ifdef RFC2553
+#define ADDR_FAMILY_MEMBER ss_family
+#else
+#define ADDR_FAMILY_MEMBER sa_family
+#endif
+
 #include <string.h>
 #include <glib/gi18n.h>
 
@@ -69,7 +75,7 @@ setup_ip_buffer (VncListenDialog *dialog)
       if (ifa->ifa_addr == NULL || ifa->ifa_name == NULL || (ifa->ifa_flags & IFF_UP) == 0 || strncmp (ifa->ifa_name, "lo", 2) == 0)
 	continue;
 
-      switch (ifa->ifa_addr->sa_family)
+      switch (ifa->ifa_addr->ADDR_FAMILY_MEMBER)
 	{
 	  case AF_INET:
 	    sin = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;



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