diff options
author | thilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2009-06-26 18:11:45 +0000 |
---|---|---|
committer | thilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2009-06-26 18:11:45 +0000 |
commit | 1bfc7abd59141813afbd6d912555f221a417ad0c (patch) | |
tree | 372973c60f47149c19a4c5a14c5288e7fdda8330 /code/qcommon | |
parent | 6b933415d6c20935c98b0b3748724aa2485d82a9 (diff) | |
download | ioquake3-aero-1bfc7abd59141813afbd6d912555f221a417ad0c.tar.gz ioquake3-aero-1bfc7abd59141813afbd6d912555f221a417ad0c.zip |
- 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.
git-svn-id: svn://svn.icculus.org/quake3/trunk@1579 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code/qcommon')
-rw-r--r-- | code/qcommon/net_ip.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/code/qcommon/net_ip.c b/code/qcommon/net_ip.c index 2cbd52b..b305249 100644 --- a/code/qcommon/net_ip.c +++ b/code/qcommon/net_ip.c @@ -341,7 +341,8 @@ static void Sys_SockaddrToString(char *dest, int destlen, struct sockaddr *input 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 @@ void NET_GetLocalAddress( void ) { 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 @@ void NET_GetLocalAddress( void ) { hint.ai_family = AF_UNSPEC; hint.ai_socktype = SOCK_DGRAM; - if(getaddrinfo(hostname, NULL, &hint, &res)) - return; - - /* 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)); - - // add all IPs from returned list. - for(search = res; search; search = search->ai_next) + if(!getaddrinfo(hostname, NULL, &hint, &res)) { - 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); + 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)); + + // 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 |