From 6b86e5faa3b12750ac0f218bc8fbbdf2a9fe1e12 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 7 Aug 2007 07:29:51 +0000 Subject: [PATCH] fixed #109 --- src/upnp.cpp | 7 ++++--- test/test_primitives.cpp | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/upnp.cpp b/src/upnp.cpp index c60725e9d..42c62166e 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -62,9 +62,10 @@ namespace libtorrent { if (a.is_v6()) return false; address_v4 a4 = a.to_v4(); - return ((a4.to_ulong() & 0xff000000) == 0x0a000000 - || (a4.to_ulong() & 0xfff00000) == 0xac100000 - || (a4.to_ulong() & 0xffff0000) == 0xc0a80000); + unsigned long ip = htonl(a4.to_ulong()); + return ((ip & 0xff000000) == 0x0a000000 + || (ip & 0xfff00000) == 0xac100000 + || (ip & 0xffff0000) == 0xc0a80000); } address_v4 guess_local_address(asio::io_service& ios) diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index d546084d9..99951160a 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -2,6 +2,7 @@ #include "libtorrent/http_tracker_connection.hpp" #include "libtorrent/buffer.hpp" #include "libtorrent/xml_parse.hpp" +#include "libtorrent/upnp.hpp" #include #include #include @@ -159,6 +160,13 @@ int test_main() , boost::ref(out4), _1, _2, _3)); std::cerr << out4 << std::endl; TEST_CHECK(out4 == "BaPgarbage inside element bracketsSfooFaPgarbage inside element brackets"); + + // test network functions + + TEST_CHECK(is_local(address::from_string("192.168.0.1"))); + TEST_CHECK(is_local(address::from_string("10.1.1.56"))); + TEST_CHECK(!is_local(address::from_string("14.14.251.63"))); + return 0; }