@@ -101,24 +101,25 @@ void NetworkUDPSocketHandler::ReceivePac
struct sockaddr_in client_addr;
socklen_t client_len;
int nbytes;
Packet p(this);
int packet_len;
if (!this->IsConnected()) return;
packet_len = sizeof(p.buffer);
client_len = sizeof(client_addr);
/* Try to receive anything */
SetNonBlocking(this->sock); // Some OSes seem to loose the non-blocking status of the socket
nbytes = recvfrom(this->sock, (char*)p.buffer, packet_len, 0, (struct sockaddr *)&client_addr, &client_len);
/* We got some bytes for the base header of the packet. */
if (nbytes > 2) {
p.PrepareToRead();
/* If the size does not match the packet must be corrupted.
* Otherwise it will be marked as corrupted later on. */
if (nbytes != p.size) {
DEBUG(net, 1, "received a packet with mismatching size from %s:%d",
inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));