X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/7c1dc8765369f868bb3ef9ba9d86050f532da42c..91fb3ca6b56328c626dabb35e2de9a5ae525b1b1:/practicas/pipi/src/routetable.cpp diff --git a/practicas/pipi/src/routetable.cpp b/practicas/pipi/src/routetable.cpp index 3363952..f8e6cbd 100644 --- a/practicas/pipi/src/routetable.cpp +++ b/practicas/pipi/src/routetable.cpp @@ -1,4 +1,6 @@ #include "routetable.h" +#include +#include #ifdef DEBUG #include #endif @@ -7,12 +9,13 @@ RouteTable::RouteTable(Dev& default_iface): default_iface(default_iface) { } -void RouteTable::add(const IPAddr& net, const IPAddr& gw, unsigned metric, Dev& iface) +void RouteTable::add(const IPAddr& net, const IPAddr& gw, unsigned mtu, + unsigned metric, Dev& iface) { - table[net] = Route(gw, metric, iface); -#ifdef DEBUG - //std::cout << "Se agregó tabla para " << net << ": gw = " << gw - // << ", metric = " << metric << "\n"; + table[net] = Route(gw, metric, mtu, iface); +#ifdef DEBUG_ROUTE + std::cout << "Se agregó tabla para " << net << ": gw = " << gw + << ", metric = " << metric << "\n"; #endif } @@ -29,4 +32,21 @@ RouteTable::Route* RouteTable::get(const IPAddr& dst) return &table[dst]; } +void add_routes(RouteTable& rt, std::istream& is, Dev& dev) +{ + std::string line; + while (std::getline(is, line)) + { + std::istringstream iss(line); + std::string net; + std::string gw; + unsigned mtu; + unsigned metric; + iss >> net >> gw >> mtu >> metric; + if (net == "0") net = "0.0.0.0"; + if (gw == "0") gw = "0.0.0.0"; + rt.add(net, gw, metric, mtu, dev); + } +} + // vim: set et sw=4 sts=4 :