{
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)
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;
}
}
/// 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())
<< 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;
}
}
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);
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...