From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 8 09:52:32 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 3719316A41A for ; Fri, 8 Feb 2008 09:52:32 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.freebsd.org (Postfix) with ESMTP id 141B613C46B for ; Fri, 8 Feb 2008 09:52:32 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [209.31.154.41]) by cyrus.watson.org (Postfix) with ESMTP id A303C4B7E6; Fri, 8 Feb 2008 04:52:31 -0500 (EST) Date: Fri, 8 Feb 2008 09:52:31 +0000 (GMT) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Biks N In-Reply-To: <50cd4e5f0802071222w1222d901o3ce8770b5f5725b4@mail.gmail.com> Message-ID: <20080208094836.P3375@fledge.watson.org> References: <50cd4e5f0802071222w1222d901o3ce8770b5f5725b4@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-hackers@freebsd.org 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, 08 Feb 2008 09:52:32 -0000 On Thu, 7 Feb 2008, Biks N wrote: > 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? netsmb and friends use a kernel library, mchain, to do marshalling and unmarashalling. This is generally not used by lower level protocol code because casting to a data structure via m_pull() and mtod() generally does the trick. However, for more complex protocols with conditional structuring, mchain can make life easier. mdchain(9) describes functions for pulling data out of mbuf chains, and mbchain(9) describes functions for constructing a chain. You'll need to declare a module dependency on mchain. NAME mdchain, md_initm, md_done, md_append_record, md_next_record, md_get_uint8, md_get_uint16, md_get_uint16be, md_get_uint16le, md_get_uint32, md_get_uint32be, md_get_uint32le, md_get_int64, md_get_int64be, md_get_int64le, md_get_mem, md_get_mbuf, md_get_uio -- set of functions to dissect an mbuf chain to various data types NAME mbchain, mb_init, mb_initm, mb_done, mb_detach, mb_fixhdr, mb_reserve, mb_put_uint8, mb_put_uint16be, mb_put_uint16le, mb_put_uint32be, mb_put_uint32le, mb_put_int64be, mb_put_int64le, mb_put_mem, mb_put_mbuf, mb_put_uio -- set of functions to build an mbuf chain from various data types I'm not sure if these routines introduce additional data copies or not, but if implementing an RPC-like protocol they presumably make life a lot easier. Robert N M Watson Computer Laboratory University of Cambridge