[Ns-bugs] [Bug 639] implementation of Buffer::CopyData(std::ostream* os, uint32_t size) is not correct

code@nsnam.ece.gatech.edu code at nsnam.ece.gatech.edu
Wed Jul 15 11:20:40 PDT 2009


http://www.nsnam.org/bugzilla/show_bug.cgi?id=639


Mathieu Lacage <mathieu.lacage at sophia.inria.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mathieu.lacage at sophia.inria.
                   |                            |fr




--- Comment #2 from Mathieu Lacage <mathieu.lacage at sophia.inria.fr>  2009-07-15 14:20:40 EDT ---
(In reply to comment #0)
> PcapWriter writes packet data to file using Buffer::CopyData(std::ostream *os,
> uint32_t size). The function interface is not documented. One would expect that
> the size parameter allows the caller to specify the maximum amount of
> bytes to copy. However, this is not the actual behavior. 
> 
> Looking at the implementation of the function, I can't really understand the
> reason for this check: 
> if (size == GetSize ())
> 
> The only code calling this method is PcapWriter (which calls it through
> Packet::CopyData(std::ostream *os, uint32_t size)), I could see no other use of
> this function. PcapWriter passes packet->.GetSize () as the value of the size
> parameter, so the above check is always true, and the "else" part of the
> statement is never executed. Furthremore, this "else" part does not limit the
> size of the write operation (I wonder what it was meant to do).

the 'else' part is missing a size--; statement to write only the requested
amount of bytes

> 
> Making the size parameter limit the size of the write operation is desirable,
> e.g., to implement a capture size limit for PCAP traces.

exactly. I was planning to an a MaxSize attribute to the PcapWriter to allow
users control over that per-packet limit.

If you tested your patch better than the current code was tested, feel free to
push it.


-- 
Configure bugmail: http://www.nsnam.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the Ns-bugs mailing list