generalize use of getifaddrs

This commit is contained in:
Arvid Norberg 2011-02-15 07:42:46 +00:00
parent 7eba4cc310
commit d35670e53d
2 changed files with 13 additions and 4 deletions

View File

@ -138,10 +138,12 @@ POSSIBILITY OF SUCH DAMAGE.
#endif
#endif
#define TORRENT_HAS_FALLOCATE 0
#define TORRENT_USE_IFADDRS 1
// ==== LINUX ===
#elif defined __linux__
#define TORRENT_LINUX
#define TORRENT_USE_IFADDRS 1
// ==== MINGW ===
#elif defined __MINGW32__
@ -287,6 +289,10 @@ inline int snprintf(char* buf, int len, char const* fmt, ...)
#define TORRENT_USE_RLIMIT 1
#endif
#ifndef TORRENT_USE_IFADDRS
#define TORRENT_USE_IFADDRS 0
#endif
#ifndef TORRENT_USE_IPV6
#define TORRENT_USE_IPV6 1
#endif

View File

@ -81,6 +81,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#endif
#if TORRENT_USE_IFADDRS
#include <ifaddrs.h>
#endif
@ -281,7 +284,7 @@ namespace libtorrent { namespace
}
#endif
#if defined TORRENT_LINUX
#if TORRENT_USE_IFADDRS
bool iface_from_ifaddrs(ifaddrs *ifa, ip_interface &rv, error_code& ec)
{
int family = ifa->ifa_addr->sa_family;
@ -400,7 +403,7 @@ namespace libtorrent
std::vector<ip_interface> enum_net_interfaces(io_service& ios, error_code& ec)
{
std::vector<ip_interface> ret;
#if defined TORRENT_LINUX
#if TORRENT_USE_IFADDRS
int s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
{
@ -446,7 +449,7 @@ namespace libtorrent
close(s);
freeifaddrs(ifaddr);
// MacOS X, BSD and solaris
#elif defined TORRENT_BSD || defined TORRENT_SOLARIS
#elif defined TORRENT_LINUX || defined TORRENT_BSD || defined TORRENT_SOLARIS
int s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
{
@ -519,7 +522,7 @@ namespace libtorrent
#if defined TORRENT_BSD
int current_size = item.ifr_addr.sa_len + IFNAMSIZ;
#elif defined TORRENT_LINUX || defined TORRENT_SOLARIS
#else
int current_size = sizeof(ifreq);
#endif
ifr += current_size;