Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Feb 2008 15:06:52 -0600
From:      "Biks N" <freebsd.dev@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Re: retrive data from mbuf chain
Message-ID:  <50cd4e5f0802151306j72e61780m594cf3fd8b5ea7f9@mail.gmail.com>
In-Reply-To: <50cd4e5f0802121005s191a7875s98ffe2ca512389bc@mail.gmail.com>
References:  <50cd4e5f0802071222w1222d901o3ce8770b5f5725b4@mail.gmail.com> <47AB7775.2040000@errno.com> <50cd4e5f0802121005s191a7875s98ffe2ca512389bc@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Please ignore my previous post.

I was having problem because I didn't allocate memory to my_data_copy.

Also, the correct usage is:

m_copydata(  m, 0, m->m_pkthdr.len , (caddr_t) my_data_copy);

thanks


On Tue, Feb 12, 2008 at 12:05 PM, Biks N <freebsd.dev@gmail.com> wrote:
> Hi, thanks to everyone for providing me with different ideas.
>
> First I am trying to use m_copydata() method because I think it will
> be easy for me to copy data back and forth (using m_copydataback() ).
>
> But right now I am having problem using m_copydata() function.
>
> I want to copy data in all mbufs (only payload but no tcp/ip header)
> except the first Mbuf in chain.
> If payload is small enough to fit within 1st mbuf then I don't need that either.
>
> I am getting kernel panic ( please see below).
> I can see custom message "Starting m_copydata()" in log file.
> So I assume the problem is due to incorrect parameter in m_copydata().
>
>
> here is the sample of code I am trying to use:
>
> /********************************/
>    caddr_t my_data_copy = NULL;
>
>
>  /* check if m_len < m_pkthdr.len */
>
>   if ( m->m_len <  m->m_pkthdr.len ) {
>
>          /* copy data if there are more than 1 Mbufs in Chain */
>          log (LOG_DEBUG,"Starting m_copydata() \n");
>
>          m_copydata( m, m->m_len , m->m_pkthdr.len - m->m_len , my_data_copy);
>
>          log (LOG_DEBUG,"%d Byte of Data copied\n", m->m_pkthdr.len -
>  m->m_len);
>
>    }
>    else {
>          /* skip if there is only 1 MBUF */
>          //log (LOG_DEBUG,"There must Only 1 MBUF in chain\n");
>    }
> /********************************/
>
>
> Kernel Panic:
>
> Feb 12 11:36:09 bsd1 /kernel: Fatal trap 12: page fault while in kernel mode
> Feb 12 11:36:09 bsd1 /kernel: fault virtual address     = 0x0
> Feb 12 11:36:09 bsd1 /kernel: fault code                = supervisor
> write, page not present
> Feb 12 11:36:09 bsd1 /kernel: instruction pointer       = 0x8:0xc024efc2
> Feb 12 11:36:09 bsd1 /kernel: stack pointer             = 0x10:0xd15e8d08
> Feb 12 11:36:09 bsd1 /kernel: frame pointer             = 0x10:0xd15e8d2c
> Feb 12 11:36:09 bsd1 /kernel: code segment              = base 0x0,
> limit 0xfffff, type 0x1b
> Feb 12 11:36:09 bsd1 /kernel: = DPL 0, pres 1, def32 1, gran 1
> Feb 12 11:36:09 bsd1 /kernel: processor eflags  = interrupt enabled,
> resume, IOPL = 0
> Feb 12 11:36:09 bsd1 /kernel: current process           = 154 (ping)
> Feb 12 11:36:09 bsd1 /kernel: interrupt mask            =
> Feb 12 11:36:09 bsd1 /kernel:
>
>
> I am using "ping -s 1200 host" to send larger packets so that system
> creates at least 2 mbufs.
>
> ------------
>
> On Feb 7, 2008 3:26 PM, Sam Leffler <sam@errno.com> wrote:
> >
>
> > Biks N wrote:
> > > Hi,
> > >
> > > I am new to FreeBSD kernel programming.
> > >
> > > Currently I am trying to work on mbuf data manupulation.
> > >
> > > >From my understanding: data (payload) is stored into one or more mufs
> > > which are chained together through m_next pointer.
> > >
> > > Now, I need to retrive all data in mbuf chain ( mbufs linked by
> > > m_next). I am working ip_output() in netinet/ip_output.c
> > >
> > > Does there exist inbuilt function/macro to retrive all the data in mbuf chain?
> > >
> >
> > man 9 mbuf; look for m_copydata.
> >
> >    Sam
> >
> >
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?50cd4e5f0802151306j72e61780m594cf3fd8b5ea7f9>