From af340a38251abfb48380b667a94afbdf46f9951b Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 29 Jun 2022 15:20:51 +0800 Subject: [PATCH] os: fix gethostname error --- source/os/src/osSocket.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index b0e07ff010..f0dd5b974d 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -925,10 +925,24 @@ uint32_t taosGetIpv4FromFqdn(const char *fqdn) { } int32_t taosGetFqdn(char *fqdn) { +#ifdef WINDOWS + // Initialize Winsock + WSADATA wsaData; + int iResult; + iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); + if (iResult != 0) { + // printf("WSAStartup failed: %d\n", iResult); + return 1; + } +#endif char hostname[1024]; hostname[1023] = '\0'; if (gethostname(hostname, 1023) == -1) { - // printf("failed to get hostname, reason:%s", strerror(errno)); +#ifdef WINDOWS + printf("failed to get hostname, reason:%s", strerror(WSAGetLastError())); +#else + printf("failed to get hostname, reason:%s", strerror(errno)); +#endif assert(0); return -1; }