I am trying to implement name resolution by using getaddrinfo. Below is my code. When the code is run, sendto() gives an error 10047. I have a feeling that I'm using getaddrinfo incorrectly.
cout << " Sending on port " << port_number << " - CTRL+C to exit." << endl;
struct addrinfo hints;
struct addrinfo *result;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = 0;
hints.ai_protocol = IPPROTO_UDP;
int s = getaddrinfo("localhost", "1920", &hints, &result);
if (s != 0)
{
cout << " getaddrinfo error." << endl;
}
if (INVALID_SOCKET == (udp_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)))
{
cout << " Could not allocate a new socket." << endl;
cleanup();
return 3;
}
while (!stop)
{
if (SOCKET_ERROR == (sendto(udp_socket, tx_buf, tx_buf_size, 0, (struct sockaddr*)result, sizeof(struct sockaddr))))
{
cout << WSAGetLastError() << endl;
if (!stop)
cout << " (TX ERR)" << endl;
break;
}
}
// call freeaddrinfo...