diff --git a/lib/irs/getaddrinfo.c b/lib/irs/getaddrinfo.c index 2ff54c2c66..f5f23fbe9f 100644 --- a/lib/irs/getaddrinfo.c +++ b/lib/irs/getaddrinfo.c @@ -126,6 +126,12 @@ #include #include +#ifdef _WIN32 +#include +#include +#include +#endif + #include #include #include @@ -339,25 +345,45 @@ getaddrinfo(const char *hostname, const char *servname, port = strtol(servname, &e, 10); if (*e == '\0') { - if (socktype == 0) + if (socktype == 0) { return (EAI_SOCKTYPE); - if (port < 0 || port > 65535) + } + if (port < 0 || port > 65535) { return (EAI_SERVICE); + } port = htons((unsigned short) port); } else { +#ifdef _WIN32 + WORD wVersionRequested; + WSADATA wsaData; + + wVersionRequested = MAKEWORD(2, 0); + + err = WSAStartup(wVersionRequested, &wsaData ); + if (err != 0) { + return (EAI_FAIL); + } +#endif sp = getservbyname(servname, proto); - if (sp == NULL) + if (sp != NULL) + port = sp->s_port; +#ifdef _WIN32 + WSACleanup(); +#endif + if (sp == NULL) { return (EAI_SERVICE); - port = sp->s_port; + } if (socktype == 0) { - if (strcmp(sp->s_proto, "tcp") == 0) + if (strcmp(sp->s_proto, "tcp") == 0) { socktype = SOCK_STREAM; - else if (strcmp(sp->s_proto, "udp") == 0) + } else if (strcmp(sp->s_proto, "udp") == 0) { socktype = SOCK_DGRAM; + } } } - } else + } else { port = 0; + } /* * Next, deal with just a service name, and no hostname.