polish up ifreq support in enum_net_interrfaces

This commit is contained in:
Arvid Norberg
2012-05-13 18:48:10 +00:00
parent 36f7228001
commit 6a80638014

View File

@@ -459,10 +459,20 @@ namespace libtorrent
char *ifr = (char*)ifc.ifc_req;
int remaining = ifc.ifc_len;
while (remaining > sizeof(ifreq))
while (remaining > 0)
{
ifreq const& item = *reinterpret_cast<ifreq*>(ifr);
#ifdef _SIZEOF_ADDR_IFREQ
int current_size = _SIZEOF_ADDR_IFREQ(item);
#elif defined TORRENT_BSD
int current_size = item.ifr_addr.sa_len + IFNAMSIZ;
#else
int current_size = sizeof(ifreq);
#endif
if (remaining < current_size) break;
if (item.ifr_addr.sa_family == AF_INET
#if TORRENT_USE_IPV6
|| item.ifr_addr.sa_family == AF_INET6
@@ -510,13 +520,6 @@ namespace libtorrent
ret.push_back(iface);
}
#ifdef _SIZEOF_ADDR_IFREQ
int current_size = _SIZEOF_ADDR_IFREQ(item);
#elif defined TORRENT_BSD
int current_size = item.ifr_addr.sa_len + IFNAMSIZ;
#else
int current_size = sizeof(ifreq);
#endif
ifr += current_size;
remaining -= current_size;
}