From 63516fdd4cb64b01971750be1d29d7244b1f9e5e Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 23 Jun 2006 06:09:56 +0000 Subject: [PATCH] =?utf8?q?Se=20vuelven=20para=20atr=C3=A1s=20los=20cambios?= =?utf8?q?=20de=20buffer=20y=20filtrado=20y,=20por=20el=20contrario,=20ya?= =?utf8?q?=20no=20se=20filtra=20tampoco=20por=20protocolo,=20si=20no=20que?= =?utf8?q?=20IPIn=20recibe=20cualquier=20cosa,=20y=20deja=20el=20protocolo?= =?utf8?q?=20en=20el=20par=C3=A1metro.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- practicas/pipi/src/ip.cpp | 5 +++-- practicas/pipi/src/ipin.cpp | 33 ++------------------------------- practicas/pipi/src/ipin.h | 16 +--------------- 3 files changed, 6 insertions(+), 48 deletions(-) diff --git a/practicas/pipi/src/ip.cpp b/practicas/pipi/src/ip.cpp index b131524..6bffcfd 100644 --- a/practicas/pipi/src/ip.cpp +++ b/practicas/pipi/src/ip.cpp @@ -28,7 +28,7 @@ int main(int argc, char* argv[]) { bool router = false; bool forward = false; - unsigned proto = 0; + uint8_t proto = 0; uint16_t port = DEVTCP_DEFAULT_PORT; std::string fname = "route.txt"; if (argc < 2) @@ -97,7 +97,8 @@ int main(int argc, char* argv[]) IPAddr src, dst; std::string s = ipin.recv(proto, src, dst); std::cout << "Recibido '" << s << "' (len " << s.size() << ") de " - << src << " para " << dst << " (proto = " << proto << ")\n"; + << src << " para " << dst << " (proto = " << unsigned(proto) + << ")\n"; } return 0; } diff --git a/practicas/pipi/src/ipin.cpp b/practicas/pipi/src/ipin.cpp index 73913ab..1ff0560 100644 --- a/practicas/pipi/src/ipin.cpp +++ b/practicas/pipi/src/ipin.cpp @@ -27,34 +27,11 @@ void IPIn::drop(const std::string& msg, const IPHeader& iph) } /// Recibe un paquete IP -std::string IPIn::recv(uint8_t proto, IPAddr& src, IPAddr& dst, bool filter) +std::string IPIn::recv(uint8_t& proto, IPAddr& src, IPAddr& dst) throw (std::runtime_error) { while (true) { - // Reviso buffers completos a ver si puedo sacar algo - buffer_complete_type::iterator f = buffer_complete.find(proto); - if (f != buffer_complete.end()) // Hay algo - { - srcmap_type& srcmap = f->second; - srcmap_type::iterator b; - if (filter) - b = srcmap.find(src); // Si filtro, busco el que me interesa - else - b = srcmap.begin(); // Si no filtro, agarro el primero - if (b != srcmap.end()) - { - src = b->first; - dst = (b->second).dst; - std::string data = b->second.data; - // Limpio buffers - srcmap.erase(src); - if (srcmap.empty()) - buffer_complete.erase(proto); - return data; - } - } - // Si no pude sacar nada, recibo std::string buf = dev.receive(); // No es siquiera IP if (buf.size() < IPHeader::header_len()) @@ -127,16 +104,10 @@ std::string IPIn::recv(uint8_t proto, IPAddr& src, IPAddr& dst, bool filter) << data << "'\n"; #endif buffer.erase(iph); - // Si es un protocolo distinto o no es de quien quiero, rearmo paquete - // (ya sé que no hay más fragmentos) y guardo en buffer nomás - if ((iph.proto != proto) || (filter == true && src != iph.src)) - { - buffer_complete[proto][iph.src] = BufferPkt(iph.dst, data); - continue; - } //TODO faltaría limpiar fragmentos viejos cada tanto (timer?) src = iph.src; dst = iph.dst; + proto = iph.proto; return data; } } diff --git a/practicas/pipi/src/ipin.h b/practicas/pipi/src/ipin.h index ecdc93e..8a452b2 100644 --- a/practicas/pipi/src/ipin.h +++ b/practicas/pipi/src/ipin.h @@ -47,19 +47,6 @@ struct IPIn typedef std::map< BufferKey, offsetmap_type > buffer_type; buffer_type buffer; - /// Buffers de paquetes completos - struct BufferPkt - { - uint32_t dst; - std::string data; - BufferPkt() {} - BufferPkt(const IPAddr& dst, const std::string& data): - dst(dst), data(data) {} - }; - typedef std::map< IPAddr, BufferPkt > srcmap_type; - typedef std::map< uint8_t, srcmap_type > buffer_complete_type; - buffer_complete_type buffer_complete; - /// Constructor IPIn(const IPAddr& ip, Dev& dev, Dev& forward_que, bool router = false, bool forward = false, std::ostream& log = std::cout); @@ -69,8 +56,7 @@ struct IPIn void drop(const std::string& msg, const IPHeader& iph); /// Recibe un paquete IP - std::string recv(uint8_t proto, IPAddr& src, IPAddr& dst, - bool filter = false) + std::string recv(uint8_t& proto, IPAddr& src, IPAddr& dst) throw (std::runtime_error); // Nada de andar copiando placas... -- 2.43.0