18719N/Acommit 010fe3b486610f3105d8756fb82aa315f7e54c40
18719N/AAuthor: Halton Huo <halton.huo@sun.com>
18719N/ADate: Thu May 6 15:29:02 2010 +0800
18719N/A
18719N/A Make code is compatible with diffrent ifaddrs strcucture
18719N/A
18719N/A OpenSolaris (after b137) uses "struct sockaddr_storage", not "struct sockaddr"
18719N/A for ifa_addr member of "struct ifaddrs". This is followed RFC2553. Before
18719N/A BSD and Linux systems move to follow RFC2553, the codes need to be compiled
18719N/A under both cases.
18719N/A
18719N/A Fixes https://bugzilla.gnome.org/show_bug.cgi?id=617848
18719N/A
18719N/Adiff --git a/configure.in b/configure.in
18719N/Aindex 7f56569..ba7d19a 100644
18719N/A--- a/configure.in
18719N/A+++ b/configure.in
18719N/A@@ -331,13 +331,24 @@ AC_CHECK_FUNCS([gettimeofday])
18719N/A AC_CHECK_LIB(resolv, herror)
18719N/A
18719N/A dnl Check for getifaddrs
18719N/A-AC_TRY_COMPILE([
18719N/A- #include <ifaddrs.h>
18719N/A- ],[
18719N/A- struct ifaddrs *myaddrs;
18719N/A- getifaddrs (&myaddrs);
18719N/A- ], have_getifaddrs=yes, have_getifaddrs=no)
18719N/A-AM_CONDITIONAL(HAVE_GETIFADDRS, [test "$have_getifaddrs" = "yes"])
18719N/A+AM_CONDITIONAL(SELF_IFADDRS, test "x$ac_cv_header_ifaddrs_h" != "xyes")
18719N/A+
18719N/A+dnl RFC2553 introduce sockaddr_storage as ifa_addr member in ifaddrs structure
18719N/A+dnl Not all distros follow this.
18719N/A+if test "x$ac_cv_header_ifaddrs_h" = "xyes"; then
18719N/A+ AC_TRY_COMPILE([
18719N/A+ #include <ifaddrs.h>
18719N/A+ #include <net/if.h>
18719N/A+ ],[
18719N/A+ struct ifaddrs *myaddrs;
18719N/A+ getifaddrs (&myaddrs);
18719N/A+ if (myaddrs->ifa_addr->ss_family == AF_INET) {
18719N/A+ }
18719N/A+ ], have_sockaddr_storage=yes, have_sockaddr_storage=no)
18719N/A+ if test "x$have_sockaddr_storage" = "xyes"; then
18719N/A+ AC_DEFINE(RFC2553, [], [Define to if follow RFC2553 ])
18719N/A+ fi
18719N/A+fi
18719N/A
18719N/A dnl
18719N/A dnl End of libvncserver stuff
18719N/Adiff --git a/server/libvncserver/Makefile.am b/server/libvncserver/Makefile.am
18719N/Aindex 315081f..6a8072d 100644
18719N/A--- a/server/libvncserver/Makefile.am
18719N/A+++ b/server/libvncserver/Makefile.am
18719N/A@@ -37,7 +37,7 @@ libvncserver_la_LIBADD = \
18719N/A $(LIBGCRYPT_LIBS) \
18719N/A $(NULL)
18719N/A
18719N/A-if !HAVE_GETIFADDRS
18719N/A+if SELF_IFADDRS
18719N/A libvncserver_la_LIBADD += ifaddr/libifaddrs.la
18719N/A endif
18719N/A
18719N/Adiff --git a/server/libvncserver/ifaddr/Makefile.am b/server/libvncserver/ifaddr/Makefile.am
18719N/Aindex 466340f..b292ba8 100644
18719N/A--- a/server/libvncserver/ifaddr/Makefile.am
18719N/A+++ b/server/libvncserver/ifaddr/Makefile.am
18719N/A@@ -1,4 +1,4 @@
18719N/A-if !HAVE_GETIFADDRS
18719N/A+if SELF_IFADDRS
18719N/A noinst_LTLIBRARIES = libifaddrs.la
18719N/A libifaddrs_la_SOURCES = \
18719N/A getifaddrs.c \
18719N/Adiff --git a/server/libvncserver/sockets.c b/server/libvncserver/sockets.c
18719N/Aindex 74a639c..c4275b0 100644
18719N/A--- a/server/libvncserver/sockets.c
18719N/A+++ b/server/libvncserver/sockets.c
18719N/A@@ -78,6 +78,11 @@
18719N/A #include "ifaddr/ifaddrs.h"
18719N/A #endif
18719N/A
18719N/A+#ifdef RFC2553
18719N/A+#define ADDR_FAMILY_MEMBER ss_family
18719N/A+#else
18719N/A+#define ADDR_FAMILY_MEMBER sa_family
18719N/A+#endif
18719N/A
18719N/A #if defined(__linux__) && defined(NEED_TIMEVAL)
18719N/A struct timeval
18719N/A@@ -621,7 +626,7 @@ ListenOnTCPPort(rfbScreenInfoPtr rfbScreen, int port, const char *netIface)
18719N/A if (ifa->ifa_addr == NULL || (ifa->ifa_flags & IFF_UP) == 0)
18719N/A continue;
18719N/A
18719N/A- if (ifa->ifa_addr->sa_family == AF_INET) {
18719N/A+ if (ifa->ifa_addr->ADDR_FAMILY_MEMBER == AF_INET) {
18719N/A struct sockaddr_in *s4 = (struct sockaddr_in*)ifa->ifa_addr;
18719N/A s4->sin_port = htons(port);
18719N/A
18719N/A@@ -635,11 +640,11 @@ ListenOnTCPPort(rfbScreenInfoPtr rfbScreen, int port, const char *netIface)
18719N/A }
18719N/A }
18719N/A #ifdef ENABLE_IPV6
18719N/A- if (ifa->ifa_addr->sa_family == AF_INET6) {
18719N/A+ if (ifa->ifa_addr->ADDR_FAMILY_MEMBER == AF_INET6) {
18719N/A struct sockaddr_in6 *s6 = (struct sockaddr_in6*)ifa->ifa_addr;
18719N/A s6->sin6_port = htons(port);
18719N/A
18719N/A- if (inet_ntop(ifa->ifa_addr->sa_family, (struct sockaddr*)&s6->sin6_addr, buf, sizeof(buf)) == NULL) {
18719N/A+ if (inet_ntop(ifa->ifa_addr->ADDR_FAMILY_MEMBER, (struct sockaddr*)&s6->sin6_addr, buf, sizeof(buf)) == NULL) {
18719N/A rfbLog("%s: inet_ntop failed!\n", ifa->ifa_name);
18719N/A continue;
18719N/A }
18719N/Adiff --git a/server/vino-dbus-listener.c b/server/vino-dbus-listener.c
18719N/Aindex 6caf5b1..774ec9f 100644
18719N/A--- a/server/vino-dbus-listener.c
18719N/A+++ b/server/vino-dbus-listener.c
18719N/A@@ -62,6 +62,12 @@
18719N/A #include "libvncserver/ifaddr/ifaddrs.h"
18719N/A #endif
18719N/A
18719N/A+#ifdef RFC2553
18719N/A+#define ADDR_FAMILY_MEMBER ss_family
18719N/A+#else
18719N/A+#define ADDR_FAMILY_MEMBER sa_family
18719N/A+#endif
18719N/A+
18719N/A #define VINO_DBUS_BUS_NAME "org.gnome.Vino"
18719N/A
18719N/A G_DEFINE_TYPE (VinoDBusListener, vino_dbus_listener, G_TYPE_OBJECT)
18719N/A@@ -126,7 +132,7 @@ get_local_hostname (VinoDBusListener *listener)
18719N/A if (ifa->ifa_addr == NULL || ifa->ifa_name == NULL || (ifa->ifa_flags & IFF_UP) == 0)
18719N/A continue;
18719N/A
18719N/A- switch (ifa->ifa_addr->sa_family)
18719N/A+ switch (ifa->ifa_addr->ADDR_FAMILY_MEMBER)
18719N/A {
18719N/A case AF_INET:
18719N/A sin = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;