From ba0985de379dd35970fe14551d89b91cba774637 Mon Sep 17 00:00:00 2001 From: Gregor Richards Date: Fri, 2 Dec 2016 20:38:55 -0500 Subject: [PATCH] Actually report the host port as the Netplay port, not the discovery port --- network/netplay/netplay_discovery.c | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/network/netplay/netplay_discovery.c b/network/netplay/netplay_discovery.c index 89f87adef2..6ac8062d81 100644 --- a/network/netplay/netplay_discovery.c +++ b/network/netplay/netplay_discovery.c @@ -240,6 +240,22 @@ bool netplay_lan_ad_server(netplay_t *netplay) return true; } +#ifdef HAVE_SOCKET_LEGACY +/* The fact that I need to write this is deeply depressing */ +static int16_t htons_for_morons(int16_t value) +{ + union { + int32_t l; + int16_t s[2]; + } val; + val.l = htonl(value); + return val.s[2]; +} +#ifndef htons +#define htons htons_for_morons +#endif +#endif + bool netplay_lan_ad_client(void) { fd_set fds; @@ -278,6 +294,23 @@ bool netplay_lan_ad_client(void) if (ntohl(ad_packet_buffer.protocol_version) != NETPLAY_PROTOCOL_VERSION) continue; + /* And that we know how to handle it */ + if (their_addr.sa_family == AF_INET) + { + struct sockaddr_in *sin = (struct sockaddr_in *) &their_addr; + sin->sin_port = htons(ad_packet_buffer.port); + + } +#ifdef AF_INET6 + else if (their_addr.sa_family == AF_INET6) + { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &their_addr; + sin6->sin6_port = htons(ad_packet_buffer.port); + + } +#endif + else continue; + /* Allocate space for it */ if (discovered_hosts.size >= discovered_hosts_allocated) {