From 9ad5f5189ca73ea0797020eb7771e5af1aa2e890 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 23 May 2025 16:43:02 +0200 Subject: [PATCH] split portnum retrieval into own function --- src/d_net.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/d_net.c b/src/d_net.c index 0e64205ea..9a5c65121 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -1220,6 +1220,18 @@ static void Internal_FreeNodenum(INT32 nodenum) (void)nodenum; } +static char *I_NetSplitAddress(char *host, char **port) +{ + boolean v4 = (host[0] != '['); + + host = strtok(host, v4 ? ":" : "[]"); + + if (port) + *port = strtok(NULL, ":"); + + return host; +} + SINT8 I_NetMakeNode(const char *hostname) { SINT8 newnode = -1; @@ -1227,20 +1239,14 @@ SINT8 I_NetMakeNode(const char *hostname) if (I_NetMakeNodewPort) { char *localhostname = strdup(hostname); - char *t = localhostname; - const char *port; + char *port; if (!localhostname) return newnode; + // retrieve portnum from address! - strtok(localhostname, ":"); - port = strtok(NULL, ":"); + hostname = I_NetSplitAddress(localhostname, &port); - // remove the port in the hostname as we've it already - while ((*t != ':') && (*t != '\0')) - t++; - *t = '\0'; - - newnode = I_NetMakeNodewPort(localhostname, port); + newnode = I_NetMakeNodewPort(hostname, port); free(localhostname); } return newnode;