From bcd4b40e67010378892ce56f551d9e45958f07fa Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 26 Jan 2006 09:39:01 +0000 Subject: supported IPv6 on Win32. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@932 ee746299-78ed-0310-b773-934348b2243d --- ChangeLog | 5 +++++ ChangeLog.ja | 5 +++++ configure.in | 25 ++++++++++++++++++------- libsylph/socket.c | 30 +++++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2a1b232..25eed9ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-01-26 + + * libsylph/socket.c + configure.in: supported IPv6 on Win32. + 2006-01-26 * src/textview.c diff --git a/ChangeLog.ja b/ChangeLog.ja index 1f6a6276..0ed34210 100644 --- a/ChangeLog.ja +++ b/ChangeLog.ja @@ -1,3 +1,8 @@ +2006-01-26 + + * libsylph/socket.c + configure.in: Win32 で IPv6 に対応。 + 2006-01-26 * src/textview.c diff --git a/configure.in b/configure.in index 55e2db79..116de230 100644 --- a/configure.in +++ b/configure.in @@ -300,13 +300,24 @@ AC_MSG_CHECKING([whether to use IPv6]) if test x"$ac_cv_enable_ipv6" = xyes; then AC_MSG_RESULT(yes) AC_MSG_CHECKING([for IPv6 support]) - AC_CACHE_VAL(ac_cv_ipv6,[ - AC_TRY_COMPILE([#define INET6 - #include - #include ], - [int x = IPPROTO_IPV6; struct in6_addr a;], - ac_cv_ipv6=yes, ac_cv_ipv6=no) - ]) + if test "$native_win32" = yes; then + AC_CACHE_VAL(ac_cv_ipv6,[ + AC_TRY_COMPILE([#define INET6 + #include + #include + #include ], + [int x = IPPROTO_IPV6; struct in6_addr a;], + ac_cv_ipv6=yes, ac_cv_ipv6=no) + ]) + else + AC_CACHE_VAL(ac_cv_ipv6,[ + AC_TRY_COMPILE([#define INET6 + #include + #include ], + [int x = IPPROTO_IPV6; struct in6_addr a;], + ac_cv_ipv6=yes, ac_cv_ipv6=no) + ]) + fi AC_MSG_RESULT($ac_cv_ipv6) if test $ac_cv_ipv6 = yes; then AC_DEFINE(INET6, 1, Define if you want IPv6 support.) diff --git a/libsylph/socket.c b/libsylph/socket.c index e0ca1fa5..834f760b 100644 --- a/libsylph/socket.c +++ b/libsylph/socket.c @@ -26,6 +26,7 @@ #include #ifdef G_OS_WIN32 # include +# include #else # if HAVE_SYS_WAIT_H # include @@ -635,9 +636,27 @@ static gint sock_connect_by_hostname(gint sock, const gchar *hostname, } #else /* INET6 */ + +#ifdef G_OS_WIN32 +/* MinGW defines gai_strerror() in ws2tcpip.h, but it is not implemented. */ +#undef gai_strerror +const gchar *gai_strerror(gint errcode) +{ + static gchar str[32]; + + g_snprintf(str, sizeof(str), "gai errcode: (%d)", errcode); + return str; +} +#endif + static gint sock_connect_by_getaddrinfo(const gchar *hostname, gushort port) { - gint sock = -1, gai_error; +#ifdef G_OS_WIN32 + SOCKET sock = INVALID_SOCKET; +#else + gint sock = -1; +#endif + gint gai_error; struct addrinfo hints, *res, *ai; gchar port_str[6]; @@ -658,7 +677,11 @@ static gint sock_connect_by_getaddrinfo(const gchar *hostname, gushort port) for (ai = res; ai != NULL; ai = ai->ai_next) { sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); +#ifdef G_OS_WIN32 + if (sock == INVALID_SOCKET) +#else if (sock < 0) +#endif continue; if (sock_connect_with_timeout @@ -688,7 +711,12 @@ SockInfo *sock_connect(const gchar *hostname, gushort port) SockInfo *sockinfo; #ifdef INET6 +#ifdef G_OS_WIN32 + if ((sock = sock_connect_by_getaddrinfo(hostname, port)) + == INVALID_SOCKET) +#else if ((sock = sock_connect_by_getaddrinfo(hostname, port)) < 0) +#endif /* G_OS_WIN32 */ return NULL; #else #ifdef G_OS_WIN32 -- cgit v1.2.3