I am trying to create a UDP client on a Windows machine using C++ (see code below).
The problem is the project I am saddled with also links to the <functional>
library, which overrides the bind
function with a couple of template functions, and VS doesn't know which version of bind()
I want to use.
How do I tell the compiler that I want to use the Winsock version of the bind()
function?
SOCKET s = INVALID_SOCKET;
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET)
{
WSACleanup();
return;
}
sockaddr_in addr_recv;
memset((char *)&addr_recv, 0, sizeof(addr_recv));
addr_recv.sin_family = AF_INET;
addr_recv.sin_port = htons(0);
addr_recv.sin_addr.s_addr = htonl(INADDR_ANY);
int server_addr_len = sizeof(addr_recv);
// compiler doesn't know which bind I mean.
int iResult = bind(s, (SOCKADDR *)&addr_recv, server_addr_len);
if (iResult == SOCKET_ERROR)
{
closesocket(s);
WSACleanup();
return;
}