tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: question about mbuf intialization



On Sep 18, 2013, at 4:43 PM, Iain Hibbert <plunky%ogmig.net@localhost> wrote:

> On Wed, 18 Sep 2013, Beverly Schwartz wrote:
> 
>> 
>> On Sep 18, 2013, at 12:16 PM, Matt Thomas <matt%3am-software.com@localhost> 
>> wrote:
>> 
>>> 
>>> On Sep 18, 2013, at 8:33 AM, Beverly Schwartz <bschwart%bbn.com@localhost> 
>>> wrote:
>>> 
>>>> Any reason why we can't add
>>>>    m->m_len = 0;
>>>> to m_get, and
>>>>    m->m_pkthdr.len = 0;
>>>> to m_gethdr?
>>> 
>>> Why not m->m_len = MLEN or MHLEN and m->m_pkthdr.len = MHLEN?
>>> 
>>> That way you know how much space is left.
>> 
>> m_len and m_pkthdr.len report on the data that is there, not on how much
>> space exists.  At initialiation, there is no data, so should be
>> initialized to 0.
> 
> Weeell, it sometimes is the space rather than the data. for example,
> m_copyback() will copy data into the space that is there and then possibly
> extend the chain. if you give it a mbuf with zero data lengths, and ask to
> copy more data? it just adds another mbuf which contains all the data..

When m_copyback extends the chain, it sets m_len in the new mbuf's to the 
amount of data in the mbuf.  m_len is *only* used to indicate how much data is 
within the mbuf itself.  m_pkthdr.len is also adjusted by m_copyback if it has 
to add to the chain.

-Bev



Home | Main Index | Thread Index | Old Index