5 #include "routetable.h"
16 #include <sys/types.h>
22 // Uso: ./ip ip [routes_file servers_file forward port]
24 void send_loop(Resolver& res);
26 int main(int argc, char* argv[])
29 uint16_t port = DEVTCP_DEFAULT_PORT;
30 std::string rfile = "route.txt";
31 std::string sfile = "resolver.txt";
34 std::cerr << "Uso: " << argv[0] << " ip [routes_file servers_file "
44 forward = atoi(argv[4]);
48 std::ifstream rifs(rfile.c_str()); assert(rifs);
49 std::ifstream sifs(sfile.c_str()); assert(sifs);
50 // Creo medio físico y cola para forwarding
51 DevTCP dev(addr, port);
52 DevQue fwque(addr, DEVQUE_DEFAULT_KEY-1);
53 DevQue resresque(addr, DEVQUE_DEFAULT_KEY-5);
54 // Creo tabla de ruteo e IP
55 RouteTable table(dev);
56 add_routes(table, rifs, dev);
57 IPOut ipout(addr, table, fwque, std::cerr);
58 IPIn ipin(addr, dev, fwque, false, forward, std::cerr);
59 Resolver res(sifs, ipin, ipout, resresque);
61 pid_t pid_send = fork();
64 perror("fork() send");
67 if (pid_send) // IPOut
69 pid_t pid_fw = fork();
72 perror("fork() forward");
75 if (pid_fw) // Padre (IPOut send)
79 kill(pid_send, SIGTERM);
80 waitpid(pid_send, &ret, 0);
81 kill(pid_fw, SIGTERM);
82 waitpid(pid_fw, &ret, 0);
85 else // Hijo 1 (IPOut forward)
99 void send_loop(Resolver& res)
102 while (std::getline(std::cin, name))
104 std::cout << "Resolviendo " << name << "...\n";
105 Resolver::ipvec_t ips;
106 Resolver::result_t r = res.gethostbyname(name, ips);
110 std::cout << "Encontrado: " << ips << "\n";
112 case Resolver::HOST_NOT_FOUND:
113 std::cout << "No encontrado!\n";
115 case Resolver::NO_RECOVERY:
116 std::cout << "Error irrecuperable!\n";
118 case Resolver::TRY_AGAIN:
119 std::cout << "Error temporal, pruebe más tarde...\n";
125 // vim: set et sw=4 sts=4 :