shithub: choc

Download patch

ref: 29a66d7a5cf87d0cfc288e15833ddc1e3f8c0e5c
parent: 0de4081d3b5689708136dd589d3554315e5ea6d1
author: Simon Howard <fraggle@soulsphere.org>
date: Fri Mar 27 21:03:48 EDT 2015

net: Include port number in address strings.

When generating string representations of network addresses, include
the UDP port number if it isn't the standard port number. This is
necessary because the string version of the address is used by the
setup tool when filling in the address field; if a non-standard port
is used then it needs to be included.

Also fix byte swapping on the address portion in the same function.

Thanks to Alexandre-Xavier for the bug report on #469.

--- a/src/net_sdl.c
+++ b/src/net_sdl.c
@@ -302,15 +302,27 @@
 void NET_SDL_AddrToString(net_addr_t *addr, char *buffer, int buffer_len)
 {
     IPaddress *ip;
+    uint32_t host;
+    uint16_t port;
 
     ip = (IPaddress *) addr->handle;
-    
-    M_snprintf(buffer, buffer_len, 
-               "%i.%i.%i.%i",
-               ip->host & 0xff,
-               (ip->host >> 8) & 0xff,
-               (ip->host >> 16) & 0xff,
-               (ip->host >> 24) & 0xff);
+    host = SDLNet_Read32(&ip->host);
+    port = SDLNet_Read16(&ip->port);
+
+    M_snprintf(buffer, buffer_len, "%i.%i.%i.%i",
+               (host >> 24) & 0xff, (host >> 16) & 0xff,
+               (host >> 8) & 0xff, host & 0xff);
+
+    // If we are using the default port we just need to show the IP address,
+    // but otherwise we need to include the port. This is important because
+    // we use the string representation in the setup tool to provided an
+    // address to connect to.
+    if (port != DEFAULT_PORT)
+    {
+        char portbuf[10];
+        M_snprintf(portbuf, sizeof(portbuf), ":%i", port);
+        M_StringConcat(buffer, portbuf, buffer_len);
+    }
 }
 
 net_addr_t *NET_SDL_ResolveAddress(char *address)
--- a/src/setup/multiplayer.c
+++ b/src/setup/multiplayer.c
@@ -957,7 +957,7 @@
                   TXT_NewScrollPane(70, 10,
                                     results_table = TXT_NewTable(3)));
 
-    TXT_SetColumnWidths(results_table, 7, 16, 46);
+    TXT_SetColumnWidths(results_table, 7, 22, 40);
     TXT_SetPeriodicCallback(QueryPeriodicCallback, results_table, 1);
 
     TXT_SignalConnect(query_window, "closed", QueryWindowClosed, NULL);