I'm writing a bit of code that can listen for UDP messages via Winsock. The port bind works on local loopback (127.0.0.1) but when I try to change to any other IP the bind fails.
Is there something I'm missing?
int socket_ = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
sockaddr_in receive_port;
memset(&receive_port, 0, sizeof(receive_port));
std::string ip_addr = "192.168.1.11";
receive_port.sin_addr.s_addr = inet_addr(ip_addr.c_str());
receive_port.sin_family = AF_INET;
receive_port.sin_port = htons(4000);
const char optval = 1;
int result = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int));
int bind_result = bind(socket_, (const struct sockaddr*)&receive_port, sizeof(receive_port));
192.168.1.11the address of your computer? Does the port need permissions from the default Windows firewall? What is the error code you get?"the bind fails"isn't a very useful problem description. What is the error? Is192.168.1.11a valid local address?...s_addr = inet_addr(ip_addr.c_str());with...s_addr = INADDR_ANY;?