SIOCGIFCONF fix

This commit is contained in:
Arvid Norberg 2012-05-12 16:15:36 +00:00
parent e74fc839e9
commit 32cd6e10b9
1 changed files with 9 additions and 4 deletions

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/enum_net.hpp"
#include "libtorrent/broadcast_socket.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/assert.hpp"
#if BOOST_VERSION < 103500
#include <asio/ip/host_name.hpp>
#else
@ -444,9 +445,10 @@ namespace libtorrent
return ret;
}
ifconf ifc;
char buf[1024];
// make sure the buffer is aligned to hold ifreq structs
ifreq buf[30];
ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = buf;
ifc.ifc_buf = (char*)buf;
if (ioctl(s, SIOCGIFCONF, &ifc) < 0)
{
ec = error_code(errno, asio::error::system_category);
@ -457,7 +459,7 @@ namespace libtorrent
char *ifr = (char*)ifc.ifc_req;
int remaining = ifc.ifc_len;
while (remaining)
while (remaining > sizeof(ifreq))
{
ifreq const& item = *reinterpret_cast<ifreq*>(ifr);
@ -508,7 +510,9 @@ namespace libtorrent
ret.push_back(iface);
}
#if defined TORRENT_BSD
#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);
@ -516,6 +520,7 @@ namespace libtorrent
ifr += current_size;
remaining -= current_size;
}
TORRENT_ASSERT(remaining == 0);
close(s);
#elif TORRENT_USE_GETADAPTERSADDRESSES