FYI, I've traccked down my problems with running 32bit executables compiled using mongw-w32-20090307 und Windows Xp x64 (SysWOW64 mode) to a bug in gethostbyname() in SysWOW64, which is tracked by the forum entry:
http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/521a5524-5a5b-4de1-aec3-e12b93e25dbb/ The attached executable compiled using i686-pc-mingw32-gcc gethostbynamesample.c -O2 -l ws2_32 -o bin32/gethostbynamesample.exe runs under WinXP x86, but crashes under WinXP x64/Server 2003 x64. The bug has been fixed for Vista x64. If compiled as a 64bit excutable everything works fine, just as expected ;-) My question is: Is it possible to put write a workaround for this bug either by modifying the atrtached test code or by adapting the gcc mingw-w32 toolchain? TIA, Wolfgang
#include <winsock2.h> #include <ws2tcpip.h> #include <stdio.h> int main(int argc, char **argv) { //----------------------------------------- // Declare and initialize variables WSADATA wsaData; int iResult; DWORD dwError; int i = 0; struct hostent *remoteHost; char *host_name; struct in_addr addr; char **pAlias; // Validate the parameters if (argc != 2) { printf("usage: %s ipv4address\n", argv[0]); printf(" or\n"); printf(" %s hostname\n", argv[0]); printf(" to return the host\n"); printf(" %s 127.0.0.1\n", argv[0]); printf(" to return the IP addresses for a host\n"); printf(" %s www.contoso.com\n", argv[0]); return 1; } // Initialize Winsock iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iResult != 0) { printf("WSAStartup failed: %d\n", iResult); return 1; } host_name = argv[1]; // If the user input is an alpha name for the host, use gethostbyname() // If not, get host by addr (assume IPv4) if (isalpha(host_name[0])) { /* host address is a name */ printf("Calling gethostbyname with %s\n", host_name); remoteHost = gethostbyname(host_name); } else { printf("Calling gethostbyaddr with %s\n", host_name); addr.s_addr = inet_addr(host_name); if (addr.s_addr == INADDR_NONE) { printf("The IPv4 address entered must be a legal address\n"); return 1; } else remoteHost = gethostbyaddr((char *) &addr, 4, AF_INET); } if (remoteHost == NULL) { dwError = WSAGetLastError(); if (dwError != 0) { if (dwError == WSAHOST_NOT_FOUND) { printf("Host not found\n"); return 1; } else if (dwError == WSANO_DATA) { printf("No data record found\n"); return 1; } else { printf("Function failed with error: %ld\n", dwError); return 1; } } } else { printf("Function returned:\n"); printf("\tOfficial name: %s\n", remoteHost->h_name); for (pAlias = remoteHost->h_aliases; *pAlias != 0; pAlias++) { printf("\tAlternate name #%d: %s\n", ++i, *pAlias); } printf("\tAddress type: "); switch (remoteHost->h_addrtype) { case AF_INET: printf("AF_INET\n"); break; case AF_INET6: printf("AF_INET6\n"); break; case AF_NETBIOS: printf("AF_NETBIOS\n"); break; default: printf(" %d\n", remoteHost->h_addrtype); break; } printf("\tAddress length: %d\n", remoteHost->h_length); i = 0; while (remoteHost->h_addr_list[i] != 0) { addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++]; printf("\tIP Address #%d: %s\n", i, inet_ntoa(addr)); } } return 0; }
------------------------------------------------------------------------------
_______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public