generalize use of getifaddrs
This commit is contained in:
@@ -138,10 +138,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#define TORRENT_HAS_FALLOCATE 0
|
#define TORRENT_HAS_FALLOCATE 0
|
||||||
|
#define TORRENT_USE_IFADDRS 1
|
||||||
|
|
||||||
// ==== LINUX ===
|
// ==== LINUX ===
|
||||||
#elif defined __linux__
|
#elif defined __linux__
|
||||||
#define TORRENT_LINUX
|
#define TORRENT_LINUX
|
||||||
|
#define TORRENT_USE_IFADDRS 1
|
||||||
|
|
||||||
// ==== MINGW ===
|
// ==== MINGW ===
|
||||||
#elif defined __MINGW32__
|
#elif defined __MINGW32__
|
||||||
@@ -287,6 +289,10 @@ inline int snprintf(char* buf, int len, char const* fmt, ...)
|
|||||||
#define TORRENT_USE_RLIMIT 1
|
#define TORRENT_USE_RLIMIT 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef TORRENT_USE_IFADDRS
|
||||||
|
#define TORRENT_USE_IFADDRS 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef TORRENT_USE_IPV6
|
#ifndef TORRENT_USE_IPV6
|
||||||
#define TORRENT_USE_IPV6 1
|
#define TORRENT_USE_IPV6 1
|
||||||
#endif
|
#endif
|
||||||
|
@@ -81,6 +81,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TORRENT_USE_IFADDRS
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -281,7 +284,7 @@ namespace libtorrent { namespace
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined TORRENT_LINUX
|
#if TORRENT_USE_IFADDRS
|
||||||
bool iface_from_ifaddrs(ifaddrs *ifa, ip_interface &rv, error_code& ec)
|
bool iface_from_ifaddrs(ifaddrs *ifa, ip_interface &rv, error_code& ec)
|
||||||
{
|
{
|
||||||
int family = ifa->ifa_addr->sa_family;
|
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> enum_net_interfaces(io_service& ios, error_code& ec)
|
||||||
{
|
{
|
||||||
std::vector<ip_interface> ret;
|
std::vector<ip_interface> ret;
|
||||||
#if defined TORRENT_LINUX
|
#if TORRENT_USE_IFADDRS
|
||||||
int s = socket(AF_INET, SOCK_DGRAM, 0);
|
int s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (s < 0)
|
if (s < 0)
|
||||||
{
|
{
|
||||||
@@ -446,7 +449,7 @@ namespace libtorrent
|
|||||||
close(s);
|
close(s);
|
||||||
freeifaddrs(ifaddr);
|
freeifaddrs(ifaddr);
|
||||||
// MacOS X, BSD and solaris
|
// 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);
|
int s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (s < 0)
|
if (s < 0)
|
||||||
{
|
{
|
||||||
@@ -519,7 +522,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
#if defined TORRENT_BSD
|
#if defined TORRENT_BSD
|
||||||
int current_size = item.ifr_addr.sa_len + IFNAMSIZ;
|
int current_size = item.ifr_addr.sa_len + IFNAMSIZ;
|
||||||
#elif defined TORRENT_LINUX || defined TORRENT_SOLARIS
|
#else
|
||||||
int current_size = sizeof(ifreq);
|
int current_size = sizeof(ifreq);
|
||||||
#endif
|
#endif
|
||||||
ifr += current_size;
|
ifr += current_size;
|
||||||
|
Reference in New Issue
Block a user