make enum_net use feature ifdefs instead of platform ifdefs

This commit is contained in:
Arvid Norberg 2011-04-09 03:49:46 +00:00
parent 61ceaba6de
commit 8aae74ea03
2 changed files with 48 additions and 27 deletions

View File

@ -147,11 +147,17 @@ POSSIBILITY OF SUCH DAMAGE.
#endif
#define TORRENT_HAS_FALLOCATE 0
#define TORRENT_USE_IFADDRS 1
#define TORRENT_USE_SYSCTL 1
#define TORRENT_USE_IFCONF 1
// ==== LINUX ===
#elif defined __linux__
#define TORRENT_LINUX
#define TORRENT_USE_IFADDRS 1
#define TORRENT_USE_NETLINK 1
#define TORRENT_USE_IFCONF 1
#define TORRENT_HAS_SALEN 0
// ==== MINGW ===
#elif defined __MINGW32__
@ -162,10 +168,19 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_USE_LOCALE 1
#endif
#define TORRENT_USE_RLIMIT 0
#define TORRENT_USE_NETLINK 1
#define TORRENT_USE_GETADAPTERSADDRESSES 1
#define TORRENT_HAS_SALEN 0
#define TORRENT_USE_GETIPFORWARDTABLE 0
// ==== WINDOWS ===
#elif defined WIN32
#define TORRENT_WINDOWS
#ifndef TORRENT_USE_GETIPFORWARDTABLE
#define TORRENT_USE_GETIPFORWARDTABLE 1
#endif
#define TORRENT_USE_GETADAPTERSADDRESSES 1
#define TORRENT_HAS_SALEN 0
// windows has its own functions to convert
// apple uses utf-8 as its locale, so no conversion
// is necessary
@ -180,6 +195,7 @@ POSSIBILITY OF SUCH DAMAGE.
#elif defined sun || defined __sun
#define TORRENT_SOLARIS
#define TORRENT_COMPLETE_TYPES_REQUIRED 1
#define TORRENT_USE_IFCONF 1
// ==== BEOS ===
#elif defined __BEOS__ || defined __HAIKU__
@ -260,6 +276,26 @@ inline int snprintf(char* buf, int len, char const* fmt, ...)
#define TORRENT_USE_ICONV 1
#endif
#ifndef TORRENT_HAS_SALEN
#define TORRENT_HAS_SALEN 1
#endif
#ifndef TORRENT_USE_GETADAPTERSADDRESSES
#define TORRENT_USE_GETADAPTERSADDRESSES 0
#endif
#ifndef TORRENT_USE_NETLINK
#define TORRENT_USE_NETLINK 0
#endif
#ifndef TORRENT_USE_SYSCTL
#define TORRENT_USE_SYSCTL 0
#endif
#ifndef TORRENT_USE_GETIPFORWARDTABLE
#define TORRENT_USE_GETIPFORWARDTABLE 0
#endif
#ifndef TORRENT_USE_LOCALE
#define TORRENT_USE_LOCALE 0
#endif

View File

@ -53,7 +53,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/scoped_array.hpp>
#endif
#if defined TORRENT_BSD
#if TORRENT_USE_SYSCTL
#include <sys/sysctl.h>
#endif
@ -112,10 +112,10 @@ namespace libtorrent { namespace
int sockaddr_len(sockaddr const* sin)
{
#if defined TORRENT_WINDOWS || defined TORRENT_MINGW || defined TORRENT_LINUX
return sin->sa_family == AF_INET ? sizeof(sockaddr_in) : sizeof(sockaddr_in6);
#else
#if TORRENT_HAS_SALEN
return sin->sa_len;
#else
return sin->sa_family == AF_INET ? sizeof(sockaddr_in) : sizeof(sockaddr_in6);
#endif
}
@ -132,7 +132,7 @@ namespace libtorrent { namespace
return address();
}
#if defined TORRENT_LINUX
#if TORRENT_USE_NETLINK
int read_nl_sock(int sock, char *buf, int bufsize, int seq, int pid)
{
@ -220,7 +220,7 @@ namespace libtorrent { namespace
}
#endif
#if defined TORRENT_BSD
#if TORRENT_USE_SYSCTL
bool parse_route(int s, rt_msghdr* rtm, ip_route* rt_info)
{
@ -270,20 +270,6 @@ namespace libtorrent { namespace
}
#endif
#ifdef TORRENT_BSD
bool verify_sockaddr(sockaddr_in* sin)
{
return (sin->sin_len == sizeof(sockaddr_in)
&& sin->sin_family == AF_INET)
#if TORRENT_USE_IPV6
|| (sin->sin_len == sizeof(sockaddr_in6)
&& sin->sin_family == AF_INET6)
#endif
;
}
#endif
#if TORRENT_USE_IFADDRS
bool iface_from_ifaddrs(ifaddrs *ifa, ip_interface &rv, error_code& ec)
{
@ -354,7 +340,7 @@ namespace libtorrent
return false;
}
#if defined TORRENT_WINDOWS || defined TORRENT_MINGW
#if TORRENT_USE_GETIPFORWARDTABLE
address build_netmask(int bits, int family)
{
if (family == AF_INET)
@ -450,7 +436,7 @@ namespace libtorrent
close(s);
freeifaddrs(ifaddr);
// MacOS X, BSD and solaris
#elif defined TORRENT_LINUX || defined TORRENT_BSD || defined TORRENT_SOLARIS
#elif TORRENT_USE_IFCONF
int s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
{
@ -532,7 +518,7 @@ namespace libtorrent
}
close(s);
#elif defined TORRENT_WINDOWS || defined TORRENT_MINGW
#elif TORRENT_USE_GETADAPTERSADDRESSES
#if _WIN32_WINNT >= 0x0501
// Load Iphlpapi library
@ -665,7 +651,7 @@ namespace libtorrent
{
std::vector<ip_route> ret;
#if defined TORRENT_BSD
#if TORRENT_USE_SYSCTL
/*
struct rt_msg
{
@ -813,7 +799,7 @@ namespace libtorrent
}
close(s);
#elif defined TORRENT_WINDOWS || defined TORRENT_MINGW
#elif TORRENT_USE_GETIPFORWARDTABLE
/*
move this to enum_net_interfaces
// Load Iphlpapi library
@ -976,8 +962,7 @@ namespace libtorrent
// Free memory
free(routes);
FreeLibrary(iphlp);
#elif defined TORRENT_LINUX
#elif TORRENT_USE_NETLINK
enum { BUFSIZE = 8192 };
int sock = socket(PF_ROUTE, SOCK_DGRAM, NETLINK_ROUTE);