Winsock error code 10014

久未见 提交于 2019-12-04 08:21:54

Some people report that WS can fail with this error if got pointer inside application stack memory.

It looks like you are using VS2005 or newer where std::string has internal 16 chars long buffer - and exactly this buffer address was passed into gethostbyname().

Try to copy your string to heap before passing it to WS:

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

And let us know, if it helped :)

Error 10014 will also be returned for addresses that aren't properly aligned even when the address is valid. That means that on 32-bit systems, the addresses have to be multiples of 4, and on 64-bit systems, they must be multiples of 8.

The X86 and X64 chips normally tolerate misaligned structures with a small performance penalty, but operating system calls such as TransmitPackets often do not.

I discovered this while debugging a TransmitPackets problem that seemed quite random. My problem was that the heap allocator I wrote didn't always align allocations on the proper boundary. Fixing the heap allocator elimininated the problems.

10014 is WSAEFAULT. You will notice from the documentation that this means "The name parameter is not a valid part of the user address space." I would check what hst.c_str() is returning.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!