views:

63

answers:

0

I have a C++ program written with Winsock that has multiple blocking sockets operating in multiple threads. They are all waiting at recvfrom(), and when I send a packet to one of them, they all get the packet. Here is how they are declared:

_sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);

if (_sock == INVALID_SOCKET) {
    _error = WSAGetLastError();
    Msg("Socket error: invalid socket (Winsock error %i)\n", _error);
    return _error;
}

sockaddr_in sin;
sin.sin_family = AF_INET;
    // listenport is an unsigned short declared elsewhere
sin.sin_port = htons(listenport);
sin.sin_addr.s_addr = INADDR_ANY;

int val = 1;
setsockopt(_sock, IPPROTO_IP, IP_HDRINCL, (const char*)&val, sizeof(val));

_error = bind(_sock, (SOCKADDR*)&sin, sizeof(sin));

All the sockets are made that way, so is there any reason why they're all receiving the packet instead of just the one with sin.sin_port set to the port the packet is sent to?