diff -r e7a09ceb4505 -r 3874575d924d sources/network/udpsocket.cpp --- a/sources/network/udpsocket.cpp Thu Dec 11 16:17:35 2014 +0200 +++ b/sources/network/udpsocket.cpp Fri Dec 12 00:55:51 2014 +0200 @@ -42,7 +42,7 @@ // ----------------------------------------------------------------------------- // UDPSocket::UDPSocket() : - m_socket (socket (AF_INET, SOCK_DGRAM, 0)) {} + m_socket (socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) {} // ----------------------------------------------------------------------------- // @@ -54,7 +54,7 @@ UDPSocket::set_blocking (bool a) -> bool { int flags = fcntl (m_socket, F_GETFL, 0); - int newflags = (a ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK)); + int newflags = a ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK); if (flags < 0 || fcntl (m_socket, F_SETFL, newflags) != 0) { @@ -92,24 +92,23 @@ { sockaddr_in claddr; socklen_t socklen = sizeof claddr; - static unsigned char packet[MAX_DATAGRAM_LENGTH]; - int length = ::recvfrom (m_socket, g_huffmanBuffer, sizeof packet, 0, + int length = ::recvfrom (m_socket, g_huffmanBuffer, sizeof g_huffmanBuffer, 0, reinterpret_cast (&claddr), &socklen); if (length == -1) { - // We got an error, though EWOULDBLOCK is silent as it means no packets recieved. if (errno != EWOULDBLOCK) - m_error.sprintf ("recvfrom error: %s", strerror (errno));; + m_error.sprintf ("recvfrom error: %s", strerror (errno)); return false; } - int decodedlength = sizeof g_huffmanBuffer; - HUFFMAN_Decode (g_huffmanBuffer, packet, length, &decodedlength); + unsigned char decodedPacket[MAX_DATAGRAM_LENGTH]; + int decodedLength = sizeof decodedPacket; + HUFFMAN_Decode (g_huffmanBuffer, decodedPacket, length, &decodedLength); datagram.from.host = ntohl (claddr.sin_addr.s_addr); datagram.from.port = ntohs (claddr.sin_port); - datagram.data = Bytestream (packet, decodedlength); + datagram.data = Bytestream (decodedPacket, decodedLength); return true; } @@ -120,9 +119,9 @@ { int encodedlength = sizeof g_huffmanBuffer; HUFFMAN_Encode (data.data(), g_huffmanBuffer, data.written_length(), &encodedlength); - struct sockaddr_in claddr = address.to_sockaddr_in(); + sockaddr_in claddr = address.to_sockaddr_in(); int res = ::sendto (m_socket, g_huffmanBuffer, encodedlength, 0, - reinterpret_cast (&claddr), sizeof claddr); + reinterpret_cast (&claddr), sizeof claddr); if (res == -1) {