2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00

ensure that WSAStartup is called before getservbyname

This commit is contained in:
Mark Andrews
2019-01-15 14:19:59 +11:00
parent 47346110b1
commit ac01359871

View File

@@ -126,6 +126,12 @@
#include <string.h>
#include <errno.h>
#ifdef _WIN32
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
#include <isc/app.h>
#include <isc/buffer.h>
#include <isc/lib.h>
@@ -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.