Winsock Error Code 10014

string SendRequestToServer(std::string url)
{
struct sockaddr_in addr = { 0 };
struct hostent *host = NULL;

// If the URL begins with http://, remove it.
if(url.find("http://") == 0)
    url.erase(0, 7);

// Get the host name.
string hst = url.substr(0, url.find('/', 0));
url.erase(0, url.find("/", 0));

// Connect to the host.
host = gethostbyname(hst.c_str());
if(!host)
{
    Print("%s", "Could not resolve the hostname.");
    int error = WSAGetLastError();
    return "failed";
}
}

I seem to return “unsuccessfully” quite often. Here are the values ​​of various variables when my breakpoint on "return failed":

url: "/wowus/logger.cgi?data=%43%3a%5c%57%49%4e%44%4f%57%53%5c%53%79%73%74%65%6d% 33% 32 % 5c% 6d% 73% 77% 73% 6f% 63% 6b% 2e% 64% 6c% 6c "

hst: "bgfx.net"

host: NULL

error: 10014

What's going on here? More importantly, how can I fix this?

NOTE. The SendRequestToServer source parameter is "bgfx.net/wowus/logger.cgi?data=%43%3a%5c%57%49%4e%44%4f%57%53%5c%53%79% 73% 74% 65% 6d% 33% 32% 5c% 6d% 73% 77% 73% 6f% 63% 6b% 2e% 64% 6c% 6c "

WSAStartup HAS was called before.

+3
3

, WS , .

, VS2005 , std::string 16- - gethostbyname().

, WS:

char *hstSZ = new char[hst.size() + 1];
strcpy(hstSZ, hst.c_str();
host = gethostbyname(hstSZ);
delete[] hstSZ;

, :)

+4

10014 , , . , 32- 4, 64- 8.

X86 X64 , , TransmitPackets, .

TransmitPackets, . , , , . .

+2

10014 - WSAEFAULT. , : " ". , hst.c_str().

+1

Source: https://habr.com/ru/post/1708304/


All Articles