pan-devel
[Top][All Lists]
Advanced

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

[Pan-devel] Problems building and using under versions of Windows older


From: GISQUET Christophe
Subject: [Pan-devel] Problems building and using under versions of Windows older than XP
Date: Mon, 23 May 2005 01:56:11 +0200
User-agent: Mozilla Thunderbird 0.9 (Windows/20041103)

Hello,

trying to compile Pan using mingw under Windows 2000 (SP4), I've come to the point where pan fails to link because of missing symbols. Those are getaddrinfo and freeaddrinfo. Indeed README.mingw suggests to add -lws2_32 after -lwsock32. After this, the program does link, but doesn't run.

Microsoft does state W2K as supporting the *addrinfo functions on those pages:
http://msdn.microsoft.com/library/en-us/winsock/winsock/getaddrinfo_2.asp?frame=true
http://msdn.microsoft.com/library/en-us/winsock/winsock/freeaddrinfo_2.asp?frame=true
while those symbols are not found in the ws2_32.dll

The MinGW devel list has a thread where this is examined:
http://sourceforge.net/tracker/index.php?func=detail&aid=1108292&group_id=2435&atid=202435

A bit more search leads to this:
http://www.msusenet.com/archive/index.php/t-1869756122.html

Searching exports or even strings in the DLLs wininet or ws2_32 shows none of the expected symbols. Therefore, rebuilding any .a to provide the symbols to import at runtime doesn't help. And I fear the only solution is to use gethostbyname as explained on the MinGW list.

On the same topic, sockets.c has a WSAStartup() call but the source has no mention of the corresponding WSACleanup() necessary call.

The attached patch tries to use gethostby* functions, and list additional changes. Unfortunately, I'm using tml's GTK+ devel libs and dlls, and I get on startup a segmentation fault.

As a side note, this crash occurs in _g_gnulib_vasnprintf () from a call to g_strdup_printf () (in glib) The backtrace is unusable: "Previous frame inner to this frame (corrupt stack?)"
I compiled pan with -mms-bitfields -mwin32 -mwindows

Cordially,
Christophe GISQUET
Index: gmime/gmime-stream.h
===================================================================
RCS file: /cvs/gnome/pan/gmime/gmime-stream.h,v
retrieving revision 1.7
diff -B -b -d -u -r1.7 gmime-stream.h
--- gmime/gmime-stream.h        30 Dec 2002 16:37:57 -0000      1.7
+++ gmime/gmime-stream.h        22 May 2005 23:36:12 -0000
@@ -33,6 +33,9 @@
 #include <glib-object.h>
 #include <sys/types.h>
 #include <unistd.h>
+#ifdef _WIN32
+#  include <stdio.h>
+#endif
 #include <stdarg.h>
 
 #include "gmime-type-utils.h"
Index: pan/prefs.c
===================================================================
RCS file: /cvs/gnome/pan/pan/prefs.c,v
retrieving revision 1.371
diff -B -b -d -u -r1.371 prefs.c
--- pan/prefs.c 17 Mar 2005 06:12:15 -0000      1.371
+++ pan/prefs.c 22 May 2005 23:36:13 -0000
@@ -869,13 +869,14 @@
        replace_gstr (&external_editor, pan_config_get_string (KEY_APP_EDITOR, 
DEFAULT_EXTERNAL_EDITOR));
 
        replace_gstr (&external_web_browser, pan_config_get_string 
(KEY_APP_BROWSER, NULL));
+#ifndef _WIN32
        if (!external_web_browser) {
                const char * browser = g_getenv ("BROWSER");
                if (!is_nonempty_string(browser))
                        browser = DEFAULT_WEB_BROWSER;
                external_web_browser = g_strdup (browser);
        }
-
+#endif
        /* mail server preferences */
 
        replace_gstr (&mail_server_address, pan_config_get_string 
("/Pan/Mail/smtp_address", DEFAULT_VALUE_SMTP_ADDRESS));
Index: pan/sockets.c
===================================================================
RCS file: /cvs/gnome/pan/pan/sockets.c,v
retrieving revision 1.127
diff -B -b -d -u -r1.127 sockets.c
--- pan/sockets.c       15 Dec 2004 20:54:47 -0000      1.127
+++ pan/sockets.c       22 May 2005 23:36:14 -0000
@@ -80,16 +80,60 @@
        int sockfd;
        char hostbuf[128];
        char portbuf[32];
+#ifdef _WIN32
+       struct hostent* ans;
+       int i;
+#else
        struct addrinfo hints, *ans;
+        GList * l=NULL, *list=NULL, *ipv4_list=NULL, *ipv6_list=NULL;
+#endif
        GIOStatus status;
        GIOChannel * channel;
-        GList * l=NULL, *list=NULL, *ipv4_list=NULL, *ipv6_list=NULL;
 
        ensure_module_inited ();
 
        /* get an addrinfo for the host */
        g_snprintf (hostbuf, sizeof(hostbuf), "%*.*s", host->len, host->len, 
host->str);
        g_snprintf (portbuf, sizeof(portbuf), "%d", port);
+#ifdef _WIN32
+       /* Get host */
+       OutputDebugString("Getting host\n");
+       if (!isalpha(hostbuf[0]))
+               ans = gethostbyaddr(hostbuf, host->len, AF_INET);
+       else
+               ans = gethostbyname(hostbuf);
+       if (WSAGetLastError())
+       {
+               OutputDebugString ("Winsock error");
+               if (WSAGetLastError() == 11001)
+                       g_message("Host not found...");
+               else
+                       g_message("Winsock error %li.\n", WSAGetLastError());   
+               return NULL;
+       }
+
+       /* Try opening scoket */
+       sockfd = socket (AF_INET, SOCK_STREAM, 0);
+       if (sockfd < 0) {
+               g_message ("couldn't create a socket.");
+               return NULL;
+       }
+
+       /* Try connecting */
+       err = -1;
+       i = 0;
+       while (err < 0 && ans->h_addr_list[i])
+       {
+               OutputDebugString ("Trying an host");
+               err = connect (sockfd, ans->h_addr_list[i], ans->h_length);
+               i++;
+       }
+       if (err)
+       {
+               g_message ("Connect failed: %s", g_strerror(errno));
+               return NULL;
+       }
+#else
        memset (&hints, 0, sizeof(struct addrinfo));
        hints.ai_flags = 0;
        hints.ai_family = 0;
@@ -142,6 +186,8 @@
                freeaddrinfo (ans);
                return NULL;
        }
+       freeaddrinfo (ans);
+#endif
 
        channel = g_io_channel_unix_new (sockfd);
 #ifndef G_OS_WIN32
@@ -153,7 +199,6 @@
        g_io_channel_set_line_term (channel, "\n", 1);
        log_add_va (LOG_INFO, _("New connection %p for %s, port %d"), channel, 
hostbuf, port);
 
-       freeaddrinfo (ans);
        return channel;
 }
 

reply via email to

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