4 #include "routetable.h"
13 #include <sys/types.h>
17 // Uso: ./test_ipout ip dst mtu routes_file proto queue_id
19 void add_routes(RouteTable& rt, std::istream& is, Dev& dev);
21 int main(int argc, char* argv[])
23 IPAddr addr("10.10.10.2");
24 IPAddr dst("10.10.10.1");
27 key_t queue_id = DEV_DEFAULT_KEY;
28 std::string fname = "route.txt";
30 addr = IPAddr(argv[1]);
32 dst = IPAddr(argv[2]);
38 proto = atoi(argv[5]);
40 queue_id = atoi(argv[6]);
41 int que_id = msgget(queue_id, IPC_CREAT | 0666); assert(que_id != -1);
42 que_id = msgget(queue_id+1, IPC_CREAT | 0666); assert(que_id != -1);
43 std::ifstream ifs(fname.c_str()); assert(ifs);
44 Dev dev(addr, mtu, queue_id);
45 Dev fwque(addr, DEV_MAX_MTU, queue_id+1);
46 RouteTable table(dev);
47 add_routes(table, ifs, dev);
48 IPOut ipout(addr, table, fwque, std::cerr);
50 while (std::getline(std::cin, msg))
52 if (ipout.send(msg, proto, dst))
53 std::cout << "Enviado '" << msg << "' a " << dst << "\n";
55 std::cout << "NO SE PUDO ENVIAR '" << msg << "' a " << dst << "\n";
60 void add_routes(RouteTable& rt, std::istream& is, Dev& dev)
63 while (std::getline(is, line))
65 std::istringstream iss(line);
69 iss >> net >> gw >> metric;
70 if (net == "0") net = "0.0.0.0";
71 if (gw == "0") gw = "0.0.0.0";
72 rt.add(net.c_str(), gw.c_str(), metric, dev);
76 // vim: set et sw=4 sts=4 :