Cuestion about Packet::uniqueify()

Eddie Kohler kohler at icir.org
Mon Nov 4 10:28:40 EST 2002


> I have a little cuestion about Packet::uniqueify() method. I read in the
> C++ Programming manual that this method returns a WritablePacket that
> doesn't share the packet's data. Well, I'm using this method (in the way
> that is used in ftpportmapper element), and by mistake, after the
> translation of the packet I was pushing the original packet instead of
> the new writable one. As a result, the packet was arriving at the ftp
> server with the correct translated content. As I see it, the new writable
> packet is endeed sharing the same data as the original one, or what is
> happening?

Packet::uniqueify() makes sure that a Packet is unique. If the packet was
already unique (it had never been clone()d), then Packet::uniqueify() *may*
return the same Packet pointer that you gave it. That is probably what
happened here. It is an error to use the old Packet pointer after calling
Packet::uniqueify().

> Another cuestion, why if I push a packet through an output, the rest of
> the element code after the push is executed? I was doing a validation
> about the packet's content looking for EPRT/EPSV/PASV/PORT commands, if
> none of the was found I pushed the packet through an output, but the code
> after this push, the one that does the translation was getting executed.
> I know that this was happening because some click_chatter messages that I
> have in that part of the code where getting displayed after the push (but
> not inmediatedly), and a I had a seg fault too, until I puted that code
> into a big if (command_found){ ... }. can any one give me an explanation
> of what is happening here?

push() is just a function call. Eventually control will return from the
function call, and continue right after the push(). If you want to push()
and then stop processing, do this:

   output(WHATEVER).push(p);
   return;

Eddie




More information about the click mailing list