From e9b2613d5facc5c3540eeb53be66a6becdfd347b Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 6 Apr 2016 16:57:37 -0700 Subject: Put routing table code back in osdep/ --- osdep/BSDRoutingTable.cpp | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'osdep/BSDRoutingTable.cpp') diff --git a/osdep/BSDRoutingTable.cpp b/osdep/BSDRoutingTable.cpp index 6d44c3ec..5b24af96 100644 --- a/osdep/BSDRoutingTable.cpp +++ b/osdep/BSDRoutingTable.cpp @@ -25,6 +25,10 @@ * LLC. Start here: http://www.zerotier.com/ */ +#include "../node/Constants.hpp" + +#ifdef __BSD__ + #include #include #include @@ -45,7 +49,6 @@ #include #include -#include "../node/Constants.hpp" #include "BSDRoutingTable.hpp" // All I wanted was the bloody rounting table. I didn't expect the Spanish inquisition. @@ -62,9 +65,9 @@ BSDRoutingTable::~BSDRoutingTable() { } -std::vector BSDRoutingTable::get(bool includeLinkLocal,bool includeLoopback) const +std::vector BSDRoutingTable::get(bool includeLinkLocal,bool includeLoopback) const { - std::vector entries; + std::vector entries; int mib[6]; size_t needed; @@ -88,7 +91,7 @@ std::vector BSDRoutingTable::get(bool includeLinkLocal,bool char *saend = next + rtm->rtm_msglen; if (((rtm->rtm_flags & RTF_LLINFO) == 0)&&((rtm->rtm_flags & RTF_HOST) == 0)&&((rtm->rtm_flags & RTF_UP) != 0)&&((rtm->rtm_flags & RTF_MULTICAST) == 0)) { - RoutingTable::Entry e; + RoutingTableEntry e; e.deviceIndex = -9999; // unset int which = 0; @@ -202,14 +205,14 @@ std::vector BSDRoutingTable::get(bool includeLinkLocal,bool } } - for(std::vector::iterator e1(entries.begin());e1!=entries.end();++e1) { + for(std::vector::iterator e1(entries.begin());e1!=entries.end();++e1) { if ((!e1->device[0])&&(e1->deviceIndex >= 0)) if_indextoname(e1->deviceIndex,e1->device); } - for(std::vector::iterator e1(entries.begin());e1!=entries.end();++e1) { + for(std::vector::iterator e1(entries.begin());e1!=entries.end();++e1) { if ((!e1->device[0])&&(e1->gateway)) { int bestMetric = 9999999; - for(std::vector::iterator e2(entries.begin());e2!=entries.end();++e2) { + for(std::vector::iterator e2(entries.begin());e2!=entries.end();++e2) { if ((e1->gateway.within(e2->destination))&&(e2->metric <= bestMetric)) { bestMetric = e2->metric; Utils::scopy(e1->device,sizeof(e1->device),e2->device); @@ -223,14 +226,14 @@ std::vector BSDRoutingTable::get(bool includeLinkLocal,bool return entries; } -RoutingTable::Entry BSDRoutingTable::set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric) +RoutingTableEntry BSDRoutingTable::set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric) { if ((!gateway)&&((!device)||(!device[0]))) - return RoutingTable::Entry(); + return RoutingTableEntry(); - std::vector rtab(get(true,true)); + std::vector rtab(get(true,true)); - for(std::vector::iterator e(rtab.begin());e!=rtab.end();++e) { + for(std::vector::iterator e(rtab.begin());e!=rtab.end();++e) { if (e->destination == destination) { if (((!device)||(!device[0]))||(!strcmp(device,e->device))) { long p = (long)fork(); @@ -248,7 +251,7 @@ RoutingTable::Entry BSDRoutingTable::set(const InetAddress &destination,const In } if (metric < 0) - return RoutingTable::Entry(); + return RoutingTableEntry(); { char hcstr[64]; @@ -270,8 +273,8 @@ RoutingTable::Entry BSDRoutingTable::set(const InetAddress &destination,const In } rtab = get(true,true); - std::vector::iterator bestEntry(rtab.end()); - for(std::vector::iterator e(rtab.begin());e!=rtab.end();++e) { + std::vector::iterator bestEntry(rtab.end()); + for(std::vector::iterator e(rtab.begin());e!=rtab.end();++e) { if ((e->destination == destination)&&(e->gateway.ipsEqual(gateway))) { if ((device)&&(device[0])) { if (!strcmp(device,e->device)) { @@ -286,7 +289,7 @@ RoutingTable::Entry BSDRoutingTable::set(const InetAddress &destination,const In if (bestEntry != rtab.end()) return *bestEntry; - return RoutingTable::Entry(); + return RoutingTableEntry(); } } // namespace ZeroTier @@ -299,8 +302,8 @@ int main(int argc,char **argv) BSDRoutingTable rt; printf(" \n"); - std::vector ents(rt.get()); - for(std::vector::iterator e(ents.begin());e!=ents.end();++e) + std::vector ents(rt.get()); + for(std::vector::iterator e(ents.begin());e!=ents.end();++e) printf("%s\n",e->toString().c_str()); printf("\n"); @@ -311,7 +314,7 @@ int main(int argc,char **argv) printf(" \n"); ents = rt.get(); - for(std::vector::iterator e(ents.begin());e!=ents.end();++e) + for(std::vector::iterator e(ents.begin());e!=ents.end();++e) printf("%s\n",e->toString().c_str()); printf("\n"); @@ -322,10 +325,12 @@ int main(int argc,char **argv) printf(" \n"); ents = rt.get(); - for(std::vector::iterator e(ents.begin());e!=ents.end();++e) + for(std::vector::iterator e(ents.begin());e!=ents.end();++e) printf("%s\n",e->toString().c_str()); printf("\n"); return 0; } #endif + +#endif // __BSD__ -- cgit v1.2.3