X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/61db0fa798876deeb90fc27f4ebdc207d3a53457..91fb3ca6b56328c626dabb35e2de9a5ae525b1b1:/practicas/pipi/src/dns.cpp diff --git a/practicas/pipi/src/dns.cpp b/practicas/pipi/src/dns.cpp index 5b3c66c..eb7e706 100644 --- a/practicas/pipi/src/dns.cpp +++ b/practicas/pipi/src/dns.cpp @@ -23,8 +23,6 @@ void send_loop(NameServer& ns); -void add_routes(RouteTable& rt, std::istream& is, Dev& dev); - int main(int argc, char* argv[]) { uint16_t port = DEVTCP_DEFAULT_PORT; @@ -65,31 +63,47 @@ int main(int argc, char* argv[]) perror("fork() send"); return 2; } - if (pid_send) // IPOut + if (pid_send) // Padre { - pid_t pid_fw = fork(); - if (pid_fw == -1) + pid_t pid_recv = fork(); + if (pid_recv == -1) { - perror("fork() forward"); + perror("fork() recv"); return 3; } - if (pid_fw) // Padre (Entrada por teclado) + if (pid_recv) // Padre { - int ret; - send_loop(ns); - kill(pid_send, SIGTERM); - waitpid(pid_send, &ret, 0); - kill(pid_fw, SIGTERM); - waitpid(pid_fw, &ret, 0); - return 0; + pid_t pid_req = fork(); + if (pid_req == -1) + { + perror("fork() req"); + return 3; + } + if (pid_req) // Padre (Entrada por teclado) + { + int ret; + send_loop(ns); + kill(pid_send, SIGTERM); + waitpid(pid_send, &ret, 0); + kill(pid_recv, SIGTERM); + waitpid(pid_recv, &ret, 0); + kill(pid_req, SIGTERM); + waitpid(pid_req, &ret, 0); + return 0; + } + else // Hijo 1 (Proceso de request DNS) + { + ns.req_loop(); + return 0; + } } - else // Hijo 1 (envío del DNS) + else // Hijo 2 (envío del DNS) { ns.send_loop(); return 0; } } - else // Hijo 2 (recepción del DNS) + else // Hijo 3 (recepción del DNS) { ns.recv_loop(); return 0; @@ -108,21 +122,4 @@ void send_loop(NameServer& ns) } } -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 :