mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
Make the interface code more portable.
It turns out SIOCGIFINDEX isn't (readily?) available in BSD, but if_nametoindex() is defined by posix, so use that instead.
This commit is contained in:
parent
4cec4b9f96
commit
53049e33eb
1 changed files with 5 additions and 11 deletions
|
@ -132,7 +132,7 @@ get_iface_list (int sock)
|
|||
#ifdef HAVE_GETIFADDRS
|
||||
struct ifaddrs *ifa_head;
|
||||
struct ifaddrs *ifa;
|
||||
struct ifreq ifreq;
|
||||
int index;
|
||||
|
||||
if (getifaddrs (&ifa_head) < 0)
|
||||
goto no_ifaddrs;
|
||||
|
@ -141,26 +141,20 @@ get_iface_list (int sock)
|
|||
continue;
|
||||
if (!ifa->ifa_addr || ifa->ifa_addr->sa_family != AF_INET)
|
||||
continue;
|
||||
strncpy (ifreq.ifr_name, ifa->ifa_name, IFNAMSIZ);
|
||||
ifreq.ifr_name[IFNAMSIZ - 1] = 0;
|
||||
ioctl (sock, SIOCGIFINDEX, (char*) &ifreq);
|
||||
if (ifreq.ifr_ifindex > num_ifaces)
|
||||
num_ifaces = ifreq.ifr_ifindex;
|
||||
index = if_nametoindex (ifa->ifa_name);
|
||||
if (index > num_ifaces)
|
||||
num_ifaces = index;
|
||||
}
|
||||
ifaces = malloc (num_ifaces * sizeof (uint32_t));
|
||||
Sys_MaskPrintf (SYS_NET, "%d interfaces\n", num_ifaces);
|
||||
for (ifa = ifa_head; ifa; ifa = ifa->ifa_next) {
|
||||
int index;
|
||||
struct sockaddr_in *sa;
|
||||
|
||||
if (!ifa->ifa_flags & IFF_UP)
|
||||
continue;
|
||||
if (!ifa->ifa_addr || ifa->ifa_addr->sa_family != AF_INET)
|
||||
continue;
|
||||
strncpy (ifreq.ifr_name, ifa->ifa_name, IFNAMSIZ);
|
||||
ifreq.ifr_name[IFNAMSIZ - 1] = 0;
|
||||
ioctl (sock, SIOCGIFINDEX, (char*) &ifreq);
|
||||
index = ifreq.ifr_ifindex - 1;
|
||||
index = if_nametoindex (ifa->ifa_name) - 1;
|
||||
sa = (struct sockaddr_in *) ifa->ifa_addr;
|
||||
memcpy (&ifaces[index], &sa->sin_addr, sizeof (uint32_t));
|
||||
Sys_MaskPrintf (SYS_NET, " %-10s %s\n", ifa->ifa_name,
|
||||
|
|
Loading…
Reference in a new issue