Route OSX compile and tests

This commit is contained in:
Alex
2012-11-08 22:56:25 -06:00
parent 67a27ac2fa
commit fefe3b5d7a
6 changed files with 325 additions and 271 deletions

View File

@@ -36,6 +36,7 @@
#include "Poco/Net/IPAddress.h"
#include "Poco/Net/Route.h"
#include "Poco/Net/NetException.h"
#include <iostream>
#include <iomanip>
@@ -67,63 +68,6 @@ RouteTest::~RouteTest()
// with results we get back from NetworkInterface::list().
//
void RouteTest::testAllRoutes()
{
Route::RouteList routes = Route::list(IPAddress::IPv4);
assert(routes.size() >= 3);
std::cout << "Active IPv4 Routes:" << std::endl;
std::cout << "=============================================================================" << std::endl;
std::cout << std::setw(17) << "Destinaton"
<< std::setw(17) << "Netmask"
<< std::setw(17) << "Gateway"
<< std::setw(17) << "Interface"
<< std::setw(8) << "Metric" << std::endl;
Route::RouteList::const_iterator it = routes.begin();
Route::RouteList::const_iterator end = routes.end();
for (; it != end; ++it)
{
IPAddress ip = it->getNetworkInterface().firstAddress(IPAddress::IPv4);
if (!ip.isLinkLocal())
{
std::string gateway = it->getNextHop().isWildcard() ? "On-link" : it->getNextHop().toString();
std::cout << std::setw(17) << it->getDest().toString()
<< std::setw(17) << it->getNetmask().toString()
<< std::setw(17) << gateway
<< std::setw(17) << ip.toString()
<< std::setw(8) << it->getMetric() << std::endl;
}
}
std::cout << "=============================================================================" << std::endl;
routes = Route::list(IPAddress::IPv6);
assert(routes.size() >= 3);
std::cout << std::endl << "Active IPv6 Routes:" << std::endl;
std::cout << "=============================================================" << std::endl;
std::cout << std::setw(4) << "If"
<< std::setw(7) << "Metric"
<< std::setw(41) << "Destinaton"
<< std::setw(8) << "Gateway"
<< std::endl;
it = routes.begin();
for (; it != end; ++it)
{
IPAddress ip = it->getNetworkInterface().firstAddress(IPAddress::IPv6);
if (!ip.isLinkLocal())
{
std::string gateway = it->getNextHop().isWildcard() ? "On-link" : it->getNextHop().toString();
std::cout << std::setw(4) << it->getIfIndex()
<< std::setw(7) << it->getMetric()
<< std::setw(41) << it->getDest().toString()
<< std::setw(8) << gateway << std::endl;
}
}
std::cout << "=============================================================" << std::endl;
}
void RouteTest::testDefaultRoute()
{
@@ -158,6 +102,81 @@ void RouteTest::tearDown()
}
void RouteTest::testAllRoutes()
{
std::string metric = "Metric";
#if defined(POCO_OS_FAMILY_BSD)
metric = "Expire";
#endif
Route::RouteList routes = Route::list(IPAddress::IPv4);
assert(routes.size() >= 3);
std::cout << std::endl << "Active IPv4 Routes:" << std::endl;
std::cout << "=============================================================================" << std::endl;
std::cout << std::setw(17) << "Destinaton"
<< std::setw(17) << "Netmask"
<< std::setw(17) << "Gateway"
<< std::setw(17) << "Interface"
<< std::setw(8) << metric << std::endl;
Route::RouteList::const_iterator it = routes.begin();
Route::RouteList::const_iterator end = routes.end();
for (; it != end; ++it)
{
IPAddress ip = it->getNetworkInterface().firstAddress(IPAddress::IPv4);
if (!ip.isLinkLocal())
{
std::string gateway = it->getNextHop().isWildcard() ? "On-link" : it->getNextHop().toString();
std::cout << std::setw(17) << it->getDest().toString()
<< std::setw(17) << it->getNetmask().toString()
<< std::setw(17) << gateway
#if defined(POCO_OS_FAMILY_BSD)
<< std::setw(17) << it->getNetworkInterface().name();
#else
<< std::setw(17) << ip.toString();
#endif
if (it->getMetric() != Route::ROUTE_METRIC_UNKNOWN)
std::cout << std::setw(8) << it->getMetric();
std::cout << std::endl;
}
}
std::cout << "=============================================================================" << std::endl;
routes = Route::list(IPAddress::IPv6);
assert(routes.size() >= 3);
std::cout << std::endl << "Active IPv6 Routes:" << std::endl;
std::cout << "=============================================================" << std::endl;
std::cout << std::setw(4) << "If"
<< std::setw(7) << metric
<< std::setw(41) << "Destinaton"
<< std::setw(41) << "Gateway"
<< std::endl;
it = routes.begin();
for (; it != end; ++it)
{
IPAddress ip = it->getNetworkInterface().firstAddress(IPAddress::IPv6);
if (!ip.isLinkLocal())
{
std::string gateway = it->getNextHop().isWildcard() ? "On-link" : it->getNextHop().toString();
#if defined(POCO_OS_FAMILY_BSD)
std::cout << std::setw(4) << it->getNetworkInterface().name();
#else
std::cout << std::setw(4) << it->getIfIndex();
#endif
if (it->getMetric() != Route::ROUTE_METRIC_UNKNOWN)
std::cout << std::setw(7) << it->getMetric();
else
std::cout << std::setw(7) << "";
std::cout << std::setw(41) << it->getDest().toString()
<< std::setw(41) << gateway << std::endl;
}
}
std::cout << "=============================================================" << std::endl;
}
CppUnit::Test* RouteTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("RouteTest");