[quake3-commits] r1579 - trunk/code/qcommon
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Fri Jun 26 14:11:45 EDT 2009
Author: thilo
Date: 2009-06-26 14:11:45 -0400 (Fri, 26 Jun 2009)
New Revision: 1579
Modified:
trunk/code/qcommon/net_ip.c
Log:
- Add error handling for Opensolaris f***ing up a numeric getnameinfo() call.
- Fix memory leak in getaddrinfo() call
Many thanks to Ben Millwood for reporting this.
Modified: trunk/code/qcommon/net_ip.c
===================================================================
--- trunk/code/qcommon/net_ip.c 2009-06-23 00:59:47 UTC (rev 1578)
+++ trunk/code/qcommon/net_ip.c 2009-06-26 18:11:45 UTC (rev 1579)
@@ -341,7 +341,8 @@
else
inputlen = sizeof(struct sockaddr_in);
- getnameinfo(input, inputlen, dest, destlen, NULL, 0, NI_NUMERICHOST);
+ if(getnameinfo(input, inputlen, dest, destlen, NULL, 0, NI_NUMERICHOST) && destlen > 0)
+ *dest = '\0';
}
/*
@@ -1319,9 +1320,6 @@
char hostname[256];
struct addrinfo hint;
struct addrinfo *res = NULL;
- struct addrinfo *search;
- struct sockaddr_in mask4;
- struct sockaddr_in6 mask6;
if(gethostname( hostname, 256 ) == SOCKET_ERROR)
return;
@@ -1333,29 +1331,36 @@
hint.ai_family = AF_UNSPEC;
hint.ai_socktype = SOCK_DGRAM;
- if(getaddrinfo(hostname, NULL, &hint, &res))
- return;
+ if(!getaddrinfo(hostname, NULL, &hint, &res))
+ {
+ struct sockaddr_in mask4;
+ struct sockaddr_in6 mask6;
+ struct addrinfo *search;
+
+ /* On operating systems where it's more difficult to find out the configured interfaces, we'll just assume a
+ * netmask with all bits set. */
+
+ memset(&mask4, 0, sizeof(mask4));
+ memset(&mask6, 0, sizeof(mask6));
+ mask4.sin_family = AF_INET;
+ memset(&mask4.sin_addr.s_addr, 0xFF, sizeof(mask4.sin_addr.s_addr));
+ mask6.sin6_family = AF_INET6;
+ memset(&mask6.sin6_addr, 0xFF, sizeof(mask6.sin6_addr));
- /* On operating systems where it's more difficult to find out the configured interfaces, we'll just assume a
- * netmask with all bits set. */
+ // add all IPs from returned list.
+ for(search = res; search; search = search->ai_next)
+ {
+ if(search->ai_family == AF_INET)
+ NET_AddLocalAddress("", search->ai_addr, (struct sockaddr *) &mask4);
+ else if(search->ai_family == AF_INET6)
+ NET_AddLocalAddress("", search->ai_addr, (struct sockaddr *) &mask6);
+ }
- memset(&mask4, 0, sizeof(mask4));
- memset(&mask6, 0, sizeof(mask6));
- mask4.sin_family = AF_INET;
- memset(&mask4.sin_addr.s_addr, 0xFF, sizeof(mask4.sin_addr.s_addr));
- mask6.sin6_family = AF_INET6;
- memset(&mask6.sin6_addr, 0xFF, sizeof(mask6.sin6_addr));
-
- // add all IPs from returned list.
- for(search = res; search; search = search->ai_next)
- {
- if(search->ai_family == AF_INET)
- NET_AddLocalAddress("", search->ai_addr, (struct sockaddr *) &mask4);
- else if(search->ai_family == AF_INET6)
- NET_AddLocalAddress("", search->ai_addr, (struct sockaddr *) &mask6);
+ Sys_ShowIP();
}
- Sys_ShowIP();
+ if(res)
+ freeaddrinfo(res);
}
#endif
More information about the quake3-commits
mailing list