8000 Route develop by pprindeville · Pull Request #9 · pocoproject/poco · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Route develop #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 14, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ target = PocoNet
target_version = $(LIBVERSION)
target_libs = PocoFoundation

SYSLIBS += -lmnl

include $(POCO_BASE)/build/rules/lib
4 changes: 2 additions & 2 deletions Net/include/Poco/Net/Route.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ class Net_API Route
static RouteList match(IPAddress target);
/// Retruns routes matching target.

static const IPAddress getDefaultAddress(IPAddress::Family family);
/// Returns default IP address for the family.
static IPAddress::List getDefaultAddresses(IPAddress::Family family);
/// Returns default IP addresses for the family.

static std::string protocolName(RouteProto proto);
/// Returns protocol as string.
Expand Down
2 changes: 2 additions & 0 deletions Net/samples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ projects:
$(MAKE) -C HTTPTimeServer $(MAKECMDGOALS)
$(MAKE) -C HTTPFormServer $(MAKECMDGOALS)
$(MAKE) -C HTTPLoadTest $(MAKECMDGOALS)
$(MAKE) -C interfaces $(MAKECMDGOALS)
$(MAKE) -C download $(MAKECMDGOALS)
$(MAKE) -C EchoServer $(MAKECMDGOALS)
$(MAKE) -C Mail $(MAKECMDGOALS)
$(MAKE) -C Ping $(MAKECMDGOALS)
$(MAKE) -C TwitterClient $(MAKECMDGOALS)
$(MAKE) -C WebSocketServer $(MAKECMDGOALS)
$(MAKE) -C routes $(MAKECMDGOALS)
$(MAKE) -C SMTPLogger $(MAKECMDGOALS)
17 changes: 17 additions & 0 deletions Net/samples/interfaces/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Makefile
#
# $Id: //poco/Main/template/sample.make#4 $
#
# Makefile for Poco interfaces
#

include $(POCO_BASE)/build/rules/global

objects = interfaces

target = interfaces
target_version = 1
target_libs = PocoUtil PocoNet PocoFoundation

include $(POCO_BASE)/build/rules/exec
96 changes: 96 additions & 0 deletions Net/samples/interfaces/src/interfaces.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// interfaces.cpp
//
// $Id: //poco/1.4/Net/samples/interfaces/src/interfaces.cpp#1 $
//
// This sample demonstrates the NetworkInterface class.
//


#include "Poco/Path.h"
#include "Poco/Exception.h"
#include "Poco/Net/IPAddress.h"
#include "Poco/Net/NetworkInterface.h"
#include <memory>
#include <iostream>

using Poco::Path;
using Poco::Exception;
using Poco::Net::IPAddress;
using Poco::Net::NetworkInterface;


int main(int argc, char** argv)
{
if (argc != 1)
{
Path p(argv[0]);
std::cerr << "usage: " << p.getBaseName() << std::endl;
return 1;
}

try
{
const NetworkInterface::Map map = NetworkInterface::map();
for ( NetworkInterface::Map::const_iterator it = map.begin();
it != map.end(); ++it) {
const NetworkInterface& intf = it->second;
std::string sep("");

std::cout << intf.name() << " [" << intf.index() << "]: ";

std::cout << "<";
if (intf.isUp()) {
std::cout << sep << "UP"; sep = ",";
}
if (intf.isRunning()) {
std::cout << sep << "RUNNING"; sep = ",";
}
if (intf.isLoopback()) {
std::cout << sep << "LOOPBACK"; sep = ",";
}
if (intf.isPointToPoint()) {
std::cout << sep << "P2P"; sep = ",";
}
if (intf.supportsIPv4()) {
std::cout << sep << "IPv4"; sep = ",";
}
if (intf.supportsIPv6()) {
std::cout << sep << "IPv6"; sep = ",";
}
if (intf.supportsBroadcast()) {
std::cout << sep << "BCAST"; sep = ",";
}
if (intf.supportsMulticast()) {
std::cout << sep << "MCAST"; sep = ",";
}

std::cout << sep << std::dec << intf.mtu(); sep = ",";

std::cout << ">" << std::endl;

const NetworkInterface::AddressList& ipList = intf.addressList();

NetworkInterface::AddressList::const_iterator ipIt = ipList.begin();
NetworkInterface::AddressList::const_iterator ipEnd = ipList.end();
for (; ipIt != ipEnd; ++ipIt) {
std::cout << " " << ipIt->get<NetworkInterface::IP_ADDRESS>().toString();
IPAddress addr;
addr = ipIt->get<NetworkInterface::SUBNET_MASK>();
if (!addr.isWildcard()) std::cout << '/' << addr.toString() << " (" << addr.prefixLength() << ')';
addr = ipIt->get<NetworkInterface::BROADCAST_ADDRESS>();
if (!addr.isWildcard()) std::cout << (intf.isPointToPoint() ? " dest " : " bcast ") << addr.toString();
std::cout << std::endl;
}

std::cout << std::endl;
}
}
catch (Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}

return 0;
}
21 changes: 21 additions & 0 deletions Net/samples/routes/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Makefile
#
# $Id: //poco/Main/template/sample.make#4 $
#
# Makefile for Poco routes
#

include $(POCO_BASE)/build/rules/global

ifeq ($(OSNAME),Linux)
SYSLIBS += -lmnl
endif

objects = routes

target = routes
target_version = 1
target_libs = PocoUtil PocoNet PocoFoundation

include $(POCO_BASE)/build/rules/exec
53 changes: 53 additions & 0 deletions Net/samples/routes/src/routes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "Poco/Path.h"
#include <iostream>

#include "Poco/Net/IPAddress.h"
#include "Poco/Net/Route.h"
#include "Poco/Net/NetworkInterface.h"

using Poco::Path;
using Poco::Net::IPAddress;
using Poco::Net::Route;
using Poco::Net::NetworkInterface;

void dumpRoutes(const Route::RouteList& routes)
{
for (Route::RouteList::const_iterator it = routes.begin();
it != routes.end(); it++) {
std::cout << (*it).getDest().toString() << '/' << (*it).getPrefix();
if ((*it).getType() == Route::ROUTE_INDIRECT)
std::cout << " via " << (*it).getNextHop().toString();
std::cout << " dev " << (*it).getNetworkInterface().name();
if ((*it).validProto())
std::cout << " proto " << Route::protocolName((*it).getProto());
if ((*it).validAge())
std::cout << " age " << (*it).getAge();
if ((*it).validMTU())
std::cout << " mtu " << (*it).getMTU();
std::cout << std::endl;
}
}

int main(int argc, char** argv)
{
if (argc != 1) {
Path p(argv[0]);
std::cerr << "usage: " << p.getBaseName() << std::endl;
return 1;
}

Route::RouteList routes = Route::list(IPAddress::IPv4);

dumpRoutes(routes);

#if defined(POCO_HAVE_IPv6)
routes = Route::list(IPAddress::IPv6);

dumpRoutes(routes);
#endif

return 0;
}


// vim:ts=4
14 changes: 8 additions & 6 deletions Net/src/Route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,20 @@ Route::RouteList Route::match(IPAddress target)
}


const IPAddress Route::getDefaultAddress(IPAddress::Family family)
IPAddress::List Route::getDefaultAddresses(IPAddress::Family family)
{
Route::RouteList routes = Route::defaults(family);
IPAddress::List addresses;

if (! routes.empty()) {
Route::RouteList::const_iterator it = routes.begin();

RouteList::const_iterator it = routes.begin();
RouteList::const_iterator end = routes.end();
for (; it != end; ++it) {
IPAddress addr = it->getNetworkInterface().firstAddress(family);
return addr;

addresses.push_back(addr);
}

return IPAddress::wildcard(family);
return addresses;
}


Expand Down
17 changes: 13 additions & 4 deletions Net/src/Route_Linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
#include <libmnl/libmnl.h>
#include <linux/rtnetlink.h>

namespace Poco {
namespace Net {

class RouteHelper
{
public:
Expand Down Expand Up @@ -105,7 +108,7 @@ static Route::RouteProto xlateProto(unsigned prot)
void RouteHelper::createRouteIPv4(Route::RouteList *routes, struct rt_container *rt_stuff)
{
if (rt_stuff->table == RT_TABLE_MAIN && rt_stuff->type <= RTN_MULTICAST) {
Route *route;
Route* route;

if (rt_stuff->gw.in4.s_addr != 0)
route = new Route(IPAddress(&rt_stuff->dest.in4, sizeof(rt_stuff->dest.in4)), IPAddress(rt_stuff->prefix, IPAddress::IPv4), IPAddress(&rt_stuff->gw.in4, sizeof(rt_stuff->gw.in4)), rt_stuff->oif, Route::ROUTE_INDIRECT);
Expand All @@ -117,14 +120,16 @@ void RouteHelper::createRouteIPv4(Route::RouteList *routes, struct rt_container
// route->setPriority(rt_stuff->priority);

// no hops, usage, mtu, or age...
routes->push_back(route);
routes->push_back(*route);

delete route;
}
}

void RouteHelper::createRouteIPv6(Route::RouteList *routes, struct rt_container *rt_stuff)
{
if (rt_stuff->table == RT_TABLE_MAIN && rt_stuff->type <= RTN_MULTICAST) {
Route *route;
Route* route;

if (!in6zero(rt_stuff->gw.in6))
route = new Route(IPAddress(&rt_stuff->dest.in6, sizeof(rt_stuff->dest.in6)), IPAddress(rt_stuff->prefix, IPAddress::IPv6), IPAddress(&rt_stuff->gw.in6, sizeof(rt_stuff->gw.in6), rt_stuff->oif), rt_stuff->oif, Route::ROUTE_INDIRECT);
Expand All @@ -136,7 +141,9 @@ void RouteHelper::createRouteIPv6(Route::RouteList *routes, struct rt_container
// route->setPriority(rt_stuff->priority);

// no hops, usage, mtu, or age...
routes->push_back(route);
routes->push_back(*route);

delete route;
}
}

Expand Down Expand Up @@ -330,3 +337,5 @@ Route::RouteList Route::list(IPAddress::Family family)

return routes;
}

}} // namespace Poco::Net
3 changes: 3 additions & 0 deletions build/config/Linux
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ RELEASEOPT_CC = -O2 -DNDEBUG
RELEASEOPT_CXX = -O2 -DNDEBUG
RELEASEOPT_LINK = -O2

# needed to build libmnl
CXXFLAGS += -std=c++0x

#
# System Specific Flags
#
Expand Down
0