From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 15 21:06:54 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 571D516A41A for ; Fri, 15 Feb 2008 21:06:54 +0000 (UTC) (envelope-from freebsd.dev@gmail.com) Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.176]) by mx1.freebsd.org (Postfix) with ESMTP id 22B7513C447 for ; Fri, 15 Feb 2008 21:06:53 +0000 (UTC) (envelope-from freebsd.dev@gmail.com) Received: by py-out-1112.google.com with SMTP id u52so1021689pyb.10 for ; Fri, 15 Feb 2008 13:06:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=+sen+768uyIvYPnrs3M2vFyk5MCHU13PQDP3hB6+Dt0=; b=V+wQvCsADkI6YMFKnxmBOf/WR/IFi9/9NyOupqR33roskYaWZh4ZxGHq60urTV8o9ibVwfPiZu6/FJwZH/7Rp2EYGRR2EX5y1O+g0M448nK5nqlzufS0NksgzscX/YvSnvaYhF7HhEoty1ayn2erRJGYKRfa7J+ESy7lYXZT3cU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=JCPIezQ4gtHT7A2bMJPFjJ3UTCpOZGP+ET3tkKSGxAvflIq1uGEyu2xg/ZIFD9Dxx3LMnBQmqDkIadr2iAisi9Z++FhxsCNjSV1alCG5ZKLOaUuextQAy26y5xpfDGcdZ2UmTUDHL4Cpf3EHvGjh+gq3SQoe0XzqGXUe45Aw1Cg= Received: by 10.140.208.14 with SMTP id f14mr2210636rvg.283.1203109612778; Fri, 15 Feb 2008 13:06:52 -0800 (PST) Received: by 10.141.20.13 with HTTP; Fri, 15 Feb 2008 13:06:52 -0800 (PST) Message-ID: <50cd4e5f0802151306j72e61780m594cf3fd8b5ea7f9@mail.gmail.com> Date: Fri, 15 Feb 2008 15:06:52 -0600 From: "Biks N" To: freebsd-hackers@freebsd.org In-Reply-To: <50cd4e5f0802121005s191a7875s98ffe2ca512389bc@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <50cd4e5f0802071222w1222d901o3ce8770b5f5725b4@mail.gmail.com> <47AB7775.2040000@errno.com> <50cd4e5f0802121005s191a7875s98ffe2ca512389bc@mail.gmail.com> Subject: Re: retrive data from mbuf chain X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Feb 2008 21:06:54 -0000 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 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 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 > > > > >