I'm looking for a way to translate hostnames to IPs (or sockaddr_in structs), while being threadsafe. gethostbyname() doesn't meet this, as it returns pointers to static data. So, while looking for an alternative, I found getaddrinfo(). My original code compiled fine on both Windows and Linux, suceeded in Linux, but fails in Windows with:
"The <executable name> file is linked to missing export ws2_32.dll:freeaddrinfo."
...and my program never executes, period, AFAIK. The following example also fails with the same error.
MSDN seems to claim this function is compatible back to Win95, and should be in ws2_32.dll. Looking at ws2_32.dll, there does not appear to be a freeaddrinfo or getaddrinfo.
What am I doing wrong, or is there some other (better?) way of connecting to say "google.com"?
Using MinGW v3.4.2 on Win98.
Example found on web, exhibits above error:
char *hostname = "localhost";
struct addrinfo hints, *res;
struct in_addr addr;
memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = AF_INET;
if((err = getaddrinfo(hostname, NULL, &hints, &res)) != 0)
printf("error %d\n", err);
addr.S_un = ((struct sockaddr_in *)(res->ai_addr))->sin_addr.S_un;
printf("ip address : %s\n", inet_ntoa(addr));