60 s.open(filename,
append ? (std::ios::app) : (std::ios::out));
62 throw cRuntimeError(
"cannot open `%s' for write", filename);
65 s <<
"Kernel IPv4 routing table" << endl;
66 s <<
"Destination Gateway Genmask ";
74 cModule *rtmod = target->getSubmodule(
"routingTable");
76 std::vector<std::string> lines;
78 IIPv4RoutingTable *rt = check_and_cast<IIPv4RoutingTable *>(rtmod);
79 for (
int i = 0; i < rt->getNumRoutes(); i++) {
80 IPv4Address dest = rt->getRoute(i)->getDestination();
82 if (dest.isMulticast())
85 if (rt->getRoute(i)->getInterface()->isLoopback())
88 IPv4Address netmask = rt->getRoute(i)->getNetmask();
89 IPv4Address gateway = rt->getRoute(i)->getGateway();
90 int metric = rt->getRoute(i)->getMetric();
92 std::ostringstream line;
95 IPv4Address prefix = compat ? dest.doAnd(netmask) : dest;
97 if (prefix.isUnspecified())
103 if (gateway.isUnspecified())
109 if (netmask.isUnspecified())
117 if (!gateway.isUnspecified())
137 line << rt->getRoute(i)->getInterfaceName() << endl;
140 lines.push_back(line.str());
150 std::stable_sort(lines.begin(), lines.end());
151 for (std::vector<std::string>::reverse_iterator it = lines.rbegin(); it != lines.rend(); it++)
comes from an interface's netmask
Definition: IRoute.h:41
void append(std::vector< int > &dest, const std::vector< int > &src)
TODO documentation.
Definition: Utils.cc:114
value< double, units::s > s
Definition: Units.h:1049
static const IPv4Address ALLONES_ADDRESS
255.255.255.255
Definition: IPv4Address.h:105