From 6c58caacad860a06c0e9a86c9ba1471290195e3e Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 20 Feb 2003 09:17:42 +0000 Subject: [PATCH] some minor cleanup of PartialIPAddress (and some comments about how stupid it is) and a comment about hostname coming from network address being stupid, and some whitespace git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2769 d7cf8633-e32d-0410-b094-e92efae38249 --- net_udp.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/net_udp.c b/net_udp.c index bd4a5de6..480901f4 100644 --- a/net_udp.c +++ b/net_udp.c @@ -69,6 +69,7 @@ int UDP_Init (void) else myAddr = *(int *)local->h_addr_list[0]; + // LordHavoc FIXME: get rid of this someday, just leave machines unnamed // if the quake hostname isn't set, set it to the machine name if (strcmp(hostname.string, "UNNAMED") == 0) { @@ -170,8 +171,10 @@ this lets you type only as much of the net address as required, using the local network components to fill in the rest ============ */ +// LordHavoc FIXME: this whole function is stupid static int PartialIPAddress (const char *in, struct qsockaddr *hostaddr) { + // LordHavoc FIXME: buff is stupid, it just ensures the address begins with a . for the parser char buff[256]; char *b; int addr; @@ -179,7 +182,7 @@ static int PartialIPAddress (const char *in, struct qsockaddr *hostaddr) int mask; int run; int port; - + buff[0] = '.'; b = buff; strcpy(buff+1, in); @@ -193,29 +196,27 @@ static int PartialIPAddress (const char *in, struct qsockaddr *hostaddr) b++; num = 0; run = 0; - while (!( *b < '0' || *b > '9')) + while (*b >= '0' && *b <= '9') { - num = num*10 + *b++ - '0'; - if (++run > 3) - return -1; + num = num*10 + *b++ - '0'; + if (num > 255) + return -1; } - if ((*b < '0' || *b > '9') && *b != '.' && *b != ':' && *b != 0) - return -1; - if (num < 0 || num > 255) + if (*b != '.' && *b != ':' && *b != 0) return -1; mask<<=8; addr = (addr<<8) + num; } - + if (*b++ == ':') port = atoi(b); else port = net_hostport; hostaddr->sa_family = AF_INET; - ((struct sockaddr_in *)hostaddr)->sin_port = htons((short)port); + ((struct sockaddr_in *)hostaddr)->sin_port = htons((short)port); ((struct sockaddr_in *)hostaddr)->sin_addr.s_addr = (myAddr & htonl(mask)) | htonl(addr); - + return 0; } //============================================================================= @@ -389,13 +390,13 @@ int UDP_GetAddrFromName(const char *name, struct qsockaddr *addr) if (name[0] >= '0' && name[0] <= '9') return PartialIPAddress (name, addr); - + hostentry = gethostbyname (name); if (!hostentry) return -1; addr->sa_family = AF_INET; - ((struct sockaddr_in *)addr)->sin_port = htons(net_hostport); + ((struct sockaddr_in *)addr)->sin_port = htons(net_hostport); ((struct sockaddr_in *)addr)->sin_addr.s_addr = *(int *)hostentry->h_addr_list[0]; return 0; -- 2.39.2