r1291 - trunk/code/qcommon
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Sat Apr 5 09:18:11 EDT 2008
Author: thilo
Date: 2008-04-05 09:18:09 -0400 (Sat, 05 Apr 2008)
New Revision: 1291
Modified:
trunk/code/qcommon/net_ip.c
Log:
Fix compilation on Solaris and possibly other platforms that have no getifaddrs()
Modified: trunk/code/qcommon/net_ip.c
===================================================================
--- trunk/code/qcommon/net_ip.c 2008-04-04 23:22:22 UTC (rev 1290)
+++ trunk/code/qcommon/net_ip.c 2008-04-05 13:18:09 UTC (rev 1291)
@@ -55,7 +55,9 @@
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
+#ifndef __sun
#include <ifaddrs.h>
+#endif
#ifdef __sun
#include <sys/filio.h>
@@ -1079,7 +1081,28 @@
}
}
-#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 @@
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
/*
More information about the quake3-commits
mailing list