From 3d25e1b33c420b410fc8514732cfa8cc304b10cd Mon Sep 17 00:00:00 2001 From: thilo Date: Sat, 5 Apr 2008 13:18:09 +0000 Subject: Fix compilation on Solaris and possibly other platforms that have no getifaddrs() git-svn-id: svn://svn.icculus.org/quake3/trunk@1291 edf5b092-35ff-0310-97b2-ce42778d08ea --- code/qcommon/net_ip.c | 115 +++++++++++--------------------------------------- 1 file changed, 24 insertions(+), 91 deletions(-) (limited to 'code/qcommon') diff --git a/code/qcommon/net_ip.c b/code/qcommon/net_ip.c index ff73fc2..0002a6a 100644 --- a/code/qcommon/net_ip.c +++ b/code/qcommon/net_ip.c @@ -55,7 +55,9 @@ static qboolean winsockInitialized = qfalse; #include #include #include +#ifndef __sun #include +#endif #ifdef __sun #include @@ -1079,7 +1081,28 @@ void NET_AddLocalNetmask(struct sockaddr *sa, int position) } } -#ifdef _WIN32 +#if defined(__linux__) || defined(MACOSX) || defined(__BSD__) +void NET_GetLocalAddress(void) +{ + struct ifaddrs *ifap, *search; + int retval; + + if(getifaddrs(&ifap)) + Com_Printf("NET_GetLocalAddress: Unable to get list of network interfaces: %s\n", NET_ErrorString()); + else + { + for(search = ifap; search; search = search->ifa_next) + { + if((retval = NET_AddLocalAddress(search->ifa_addr)) >= 0) + NET_AddLocalNetmask(search->ifa_netmask, retval); + } + + freeifaddrs(ifap); + + Sys_ShowIP(); + } +} +#else void NET_GetLocalAddress( void ) { char hostname[256]; struct addrinfo hint; @@ -1108,96 +1131,6 @@ void NET_GetLocalAddress( void ) { Sys_ShowIP(); } - -#else -/* int NET_AddInterfaceToList(char (*interfaces)[IF_NAMESIZE], int numinterfaces, char *add) -{ - int index; - - for(index = 0; index < numinterfaces && index < MAX_IPS; index++) - { - if(!strcmp(interfaces[index], add)) - break; - } - - if(index >= numinterfaces && index < MAX_IPS) - { - Q_strncpyz(interfaces[index], add, IF_NAMESIZE); - numinterfaces++; - } - - return numinterfaces; -}*/ - -void NET_GetLocalAddress(void) -{ - struct ifaddrs *ifap, *search; - int retval; - - if(getifaddrs(&ifap)) - Com_Printf("NET_GetLocalAddress: Unable to get list of network interfaces: %s\n", NET_ErrorString()); - else - { - for(search = ifap; search; search = search->ifa_next) - { - if((retval = NET_AddLocalAddress(search->ifa_addr)) >= 0) - NET_AddLocalNetmask(search->ifa_netmask, retval); - } - - freeifaddrs(ifap); - - Sys_ShowIP(); - } - -/* - char interfaces[MAX_IPS][IF_NAMESIZE]; - int numinterfaces; - struct ifreq irbuf[MAX_IPS], ireq; - struct ifconf ifc; - int index, numdev; - - memset(interfaces, '\0', sizeof(interfaces)); - - ifc.ifc_req = irbuf; - - // compile a list of all available interfaces on this machine. - - if(ip_socket != INVALID_SOCKET) - { - ifc.ifc_len = sizeof(irbuf); - - // Use our IP sockets for the ioctl stuff. - if(ioctl(ip_socket, SIOCGIFCONF, &ifc)) - { - Com_Printf("NET_GetLocalAddress: Unable to get list of network interfaces: %s\n", NET_ErrorString()); - return; - } - - numdev = ifc.ifc_len / sizeof(*irbuf); - - for(index = 0; index < numdev; index++) - numinterfaces = NET_AddInterfaceToList(interfaces, numinterfaces, irbuf[index].ifr_name); - } - - if(ip6_socket != INVALID_SOCKET) - { - ifc.ifc_len = sizeof(irbuf); - - // Use our IP sockets for the ioctl stuff. - if(ioctl(ip6_socket, SIOCGIFCONF, &ifc)) - { - Com_Printf("NET_GetLocalAddress: Unable to get list of network interfaces: %s\n", NET_ErrorString()); - return; - } - - numdev = ifc.ifc_len / sizeof(*irbuf); - - for(index = 0; index < numdev; index++) - numinterfaces = NET_AddInterfaceToList(interfaces, numinterfaces, irbuf[index].ifr_name); - } - - */ -} #endif /* -- cgit v1.2.3