From 25e29972a9df712cb51fc66e553b34f3dc441e51 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Wed, 26 Oct 2016 18:27:01 +0200 Subject: [PATCH] Fix PacketPeerUDP get_packet_port() Properly convert port field from network to system ordering on incoming packets. --- drivers/unix/packet_peer_udp_posix.cpp | 4 ++-- platform/windows/packet_peer_udp_winsock.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index d6fc697c6d9..0b172b6a51a 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -168,7 +168,7 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) { rb.write(&type, 1); struct sockaddr_in* sin_from = (struct sockaddr_in*)&from; rb.write((uint8_t*)&sin_from->sin_addr, 4); - port = sin_from->sin_port; + port = ntohs(sin_from->sin_port); } else if (from.ss_family == AF_INET6) { @@ -178,7 +178,7 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) { struct sockaddr_in6* s6_from = (struct sockaddr_in6*)&from; rb.write((uint8_t*)&s6_from->sin6_addr, 16); - port = s6_from->sin6_port; + port = ntohs(s6_from->sin6_port); } else { // WARN_PRINT("Ignoring packet with unknown address family"); diff --git a/platform/windows/packet_peer_udp_winsock.cpp b/platform/windows/packet_peer_udp_winsock.cpp index 0408a303f50..b4cd60979c7 100644 --- a/platform/windows/packet_peer_udp_winsock.cpp +++ b/platform/windows/packet_peer_udp_winsock.cpp @@ -166,7 +166,7 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) { rb.write(&type, 1); struct sockaddr_in* sin_from = (struct sockaddr_in*)&from; rb.write((uint8_t*)&sin_from->sin_addr, 4); - port = sin_from->sin_port; + port = ntohs(sin_from->sin_port); } else if (from.ss_family == AF_INET6) { @@ -176,7 +176,7 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) { struct sockaddr_in6* s6_from = (struct sockaddr_in6*)&from; rb.write((uint8_t*)&s6_from->sin6_addr, 16); - port = s6_from->sin6_port; + port = ntohs(s6_from->sin6_port); } else { // WARN_PRINT("Ignoring packet with unknown address family");