1a1a5ca55SBoris Popov.\" -*- nroff -*- 2a1a5ca55SBoris Popov.\" 3a1a5ca55SBoris Popov.\" Copyright (c) 2001 Boris Popov 4a1a5ca55SBoris Popov.\" 5a1a5ca55SBoris Popov.\" Redistribution and use in source and binary forms, with or without 6a1a5ca55SBoris Popov.\" modification, are permitted provided that the following conditions 7a1a5ca55SBoris Popov.\" are met: 8a1a5ca55SBoris Popov.\" 1. Redistributions of source code must retain the above copyright 9a1a5ca55SBoris Popov.\" notice, this list of conditions and the following disclaimer. 10a1a5ca55SBoris Popov.\" 2. Redistributions in binary form must reproduce the above copyright 11a1a5ca55SBoris Popov.\" notice, this list of conditions and the following disclaimer in the 12a1a5ca55SBoris Popov.\" documentation and/or other materials provided with the distribution. 13a1a5ca55SBoris Popov.\" 14a1a5ca55SBoris Popov.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 15a1a5ca55SBoris Popov.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16a1a5ca55SBoris Popov.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17a1a5ca55SBoris Popov.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 18a1a5ca55SBoris Popov.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19a1a5ca55SBoris Popov.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20a1a5ca55SBoris Popov.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21a1a5ca55SBoris Popov.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22a1a5ca55SBoris Popov.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23a1a5ca55SBoris Popov.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24a1a5ca55SBoris Popov.\" 25a1a5ca55SBoris Popov.\" $FreeBSD$ 26a1a5ca55SBoris Popov.\" 27a1a5ca55SBoris Popov.Dd February 28, 2001 28a1a5ca55SBoris Popov.Dt MDCHAIN 9 29a1a5ca55SBoris Popov.Os 30a1a5ca55SBoris Popov.Sh NAME 31a1a5ca55SBoris Popov.Nm mdchain , 32a1a5ca55SBoris Popov.Nm md_initm , 33a1a5ca55SBoris Popov.Nm md_done , 34a1a5ca55SBoris Popov.Nm md_append_record , 35a1a5ca55SBoris Popov.Nm md_next_record , 36a1a5ca55SBoris Popov.Nm md_get_uint8 , 37a1a5ca55SBoris Popov.Nm md_get_uint16 , 38a1a5ca55SBoris Popov.Nm md_get_uint16be , 39a1a5ca55SBoris Popov.Nm md_get_uint16le , 40a1a5ca55SBoris Popov.Nm md_get_uint32 , 41a1a5ca55SBoris Popov.Nm md_get_uint32be , 42a1a5ca55SBoris Popov.Nm md_get_uint32le , 43a1a5ca55SBoris Popov.Nm md_get_int64 , 44a1a5ca55SBoris Popov.Nm md_get_int64be , 45a1a5ca55SBoris Popov.Nm md_get_int64le , 46a1a5ca55SBoris Popov.Nm md_get_mem , 47a1a5ca55SBoris Popov.Nm md_get_mbuf , 48a1a5ca55SBoris Popov.Nm md_get_uio 49a1a5ca55SBoris Popov.Nd "set of functions to dissect an mbuf chain to various data types" 50a1a5ca55SBoris Popov.Sh SYNOPSIS 51a1a5ca55SBoris Popov.Cd options LIBMCHAIN 52a1a5ca55SBoris Popov.Li kldload libmchain 53a1a5ca55SBoris Popov.Pp 54a1a5ca55SBoris Popov.Fd #include <sys/param.h> 55a1a5ca55SBoris Popov.Fd #include <sys/mchain.h> 56a1a5ca55SBoris Popov.Ft void 57a1a5ca55SBoris Popov.Fn md_initm "struct mdchain *mdp" "struct mbuf *m" 58a1a5ca55SBoris Popov.Ft void 59a1a5ca55SBoris Popov.Fn md_done "struct mdchain *mdp" 60a1a5ca55SBoris Popov.Ft void 61a1a5ca55SBoris Popov.Fn md_append_record "struct mdchain *mdp" "struct mbuf *top" 62a1a5ca55SBoris Popov.Ft int 63a1a5ca55SBoris Popov.Fn md_next_record "struct mdchain *mdp" 64a1a5ca55SBoris Popov.Ft int 65a1a5ca55SBoris Popov.Fn md_get_uint8 "struct mdchain *mdp" "u_int8_t x" 66a1a5ca55SBoris Popov.Ft int 67a1a5ca55SBoris Popov.Fn md_get_uint16 "struct mdchain *mdp" "u_int16_t x" 68a1a5ca55SBoris Popov.Ft int 69a1a5ca55SBoris Popov.Fn md_get_uint16be "struct mdchain *mdp" "u_int16_t x" 70a1a5ca55SBoris Popov.Ft int 71a1a5ca55SBoris Popov.Fn md_get_uint16le "struct mdchain *mdp" "u_int16_t x" 72a1a5ca55SBoris Popov.Ft int 73a1a5ca55SBoris Popov.Fn md_get_uint32 "struct mdchain *mdp" "u_int32_t x" 74a1a5ca55SBoris Popov.Ft int 75a1a5ca55SBoris Popov.Fn md_get_uint32be "struct mdchain *mdp" "u_int32_t x" 76a1a5ca55SBoris Popov.Ft int 77a1a5ca55SBoris Popov.Fn md_get_uint32le "struct mdchain *mdp" "u_int32_t x" 78a1a5ca55SBoris Popov.Ft int 79a1a5ca55SBoris Popov.Fn md_get_int64 "struct mdchain *mdp" "int64_t x" 80a1a5ca55SBoris Popov.Ft int 81a1a5ca55SBoris Popov.Fn md_get_int64be "struct mdchain *mdp" "int64_t x" 82a1a5ca55SBoris Popov.Ft int 83a1a5ca55SBoris Popov.Fn md_get_int64le "struct mdchain *mdp" "int64_t x" 84a1a5ca55SBoris Popov.Ft int 85a1a5ca55SBoris Popov.Fn md_get_mem "struct mdchain *mdp" "caddr_t target" "int size" "int type" 86a1a5ca55SBoris Popov.Ft int 87a1a5ca55SBoris Popov.Fn md_get_mbuf "struct mdchain *mdp" "struct mbuf *m" 88a1a5ca55SBoris Popov.Ft int 89a1a5ca55SBoris Popov.Fn md_get_uio "struct mdchain *mdp" "struct uio *uiop" "int size" 90a1a5ca55SBoris Popov.Sh DESCRIPTION 91a1a5ca55SBoris PopovThese functions are used to decompose mbuf chains to various data types. 92a1a5ca55SBoris PopovThe 93a1a5ca55SBoris Popov.Vt mdchain 94a1a5ca55SBoris Popovstructure is used as a working context 95e95f5612SBoris Popovand should be initialized through a call of the 96a1a5ca55SBoris Popov.Fn mb_initm 97a1a5ca55SBoris Popovfunction. 98a1a5ca55SBoris PopovIt has the following fields: 99a1a5ca55SBoris Popov.Bl -tag -width "md_top" 100a1a5ca55SBoris Popov.It Va "md_top" 101a1a5ca55SBoris Popov.Vt ( "struct mbuf *" ) 102a1a5ca55SBoris Popova pointer to the top of the parsed mbuf chain 103a1a5ca55SBoris Popov.It Va md_cur 104a1a5ca55SBoris Popov.Vt ( "struct mbuf *" ) 105a1a5ca55SBoris Popova pointer to the currently parsed mbuf 106a1a5ca55SBoris Popov.It Va md_pas 107a1a5ca55SBoris Popov.Vt ( int ) 108a1a5ca55SBoris Popovoffset in the current mbuf 109a1a5ca55SBoris Popov.El 110a1a5ca55SBoris Popov.Pp 111a1a5ca55SBoris PopovThe 112a1a5ca55SBoris Popov.Fn md_done 113a1a5ca55SBoris Popovfunction disposes of an mbuf chain pointed to by the 114a1a5ca55SBoris Popov.Fa mdp->md_top 115a1a5ca55SBoris Popovfield and sets the field to 116a1a5ca55SBoris Popov.Dv NULL . 117a1a5ca55SBoris Popov.Pp 118a1a5ca55SBoris PopovThe 119a1a5ca55SBoris Popov.Fn md_append_record 120a1a5ca55SBoris Popovappends a new mbuf chain using 121a1a5ca55SBoris Popov.Va m_nextpkt 122e95f5612SBoris Popovfield to form a single linked list of mbuf chains. 123e95f5612SBoris PopovIf the 12490bd2994SRuslan Ermilov.Fa mdp->md_top 125a1a5ca55SBoris Popovfield is 126a1a5ca55SBoris Popov.Dv NULL , 127e95f5612SBoris Popovthen this function behaves exactly as the 128a1a5ca55SBoris Popov.Fn md_initm 129a1a5ca55SBoris Popovfunction. 130a1a5ca55SBoris Popov.Pp 131a1a5ca55SBoris PopovThe 132a1a5ca55SBoris Popov.Fn md_next_record 133e95f5612SBoris Popovfunction extracts the next mbuf chain and disposes the current one, if any. 134e95f5612SBoris PopovFor a new mbuf chain it calls the 135a1a5ca55SBoris Popov.Fn md_initm 136a1a5ca55SBoris Popovfunction. 137e95f5612SBoris PopovIf there is no data left the function returns 13890bd2994SRuslan Ermilov.Er ENOENT . 139a1a5ca55SBoris Popov.Pp 140a1a5ca55SBoris PopovAll 141a1a5ca55SBoris Popov.Fn md_get_* 142a1a5ca55SBoris Popovfunctions perform an actual copy of the data from an mbuf chain. 143a1a5ca55SBoris PopovFunctions which have 144a1a5ca55SBoris Popov.Cm le 145a1a5ca55SBoris Popovor 146a1a5ca55SBoris Popov.Cm be 14790bd2994SRuslan Ermilovsuffixes will perform conversion to the little\- or big\-endian data formats. 148a1a5ca55SBoris Popov.Pp 149a1a5ca55SBoris Popov.Fn md_get_mem 150a1a5ca55SBoris Popovfunction copies 151a1a5ca55SBoris Popov.Fa size 152a1a5ca55SBoris Popovbytes of data specified by the 153a1a5ca55SBoris Popov.Fa source 154a1a5ca55SBoris Popovargument from an mbuf chain. 155a1a5ca55SBoris PopovThe 156a1a5ca55SBoris Popov.Fa type 157a1a5ca55SBoris Popovargument specifies the method used to perform a copy, 158a1a5ca55SBoris Popovand can be one of the following: 159a1a5ca55SBoris Popov.Bl -tag -width "MB_MINLINE" 160a1a5ca55SBoris Popov.It Dv MB_MSYSTEM 161e95f5612SBoris PopovUse the 162a1a5ca55SBoris Popov.Fn bcopy 163e95f5612SBoris Popovfunction. 164a1a5ca55SBoris Popov.It Dv MB_MUSER 165e95f5612SBoris PopovUse the 166a1a5ca55SBoris Popov.Xr copyin 9 167e95f5612SBoris Popovfunction. 168a1a5ca55SBoris Popov.It Dv MB_MINLINE 169e95f5612SBoris PopovUse an 170a1a5ca55SBoris Popov.Dq inline 171e95f5612SBoris Popovloop which does not call any function. 172a1a5ca55SBoris Popov.El 173a1a5ca55SBoris Popov.Pp 174a1a5ca55SBoris PopovIf 17590bd2994SRuslan Ermilov.Fa target 176e95f5612SBoris Popovis 177a1a5ca55SBoris Popov.Dv NULL , 178e95f5612SBoris Popovan actual copy is not performed 179e95f5612SBoris Popovand the function just skips the given number of bytes. 180a1a5ca55SBoris Popov.Sh RETURN VALUES 181a1a5ca55SBoris PopovAll 182a1a5ca55SBoris Popov.Ft int 183a1a5ca55SBoris Popovfunctions return zero if successful, 184a1a5ca55SBoris Popovotherwise an error code is returned. 185a1a5ca55SBoris Popov.Pp 186a1a5ca55SBoris Popov.Em Note : 187a1a5ca55SBoris Popovafter failure of any function, 188e95f5612SBoris Popovan mbuf chain is left in the broken state and only the 189a1a5ca55SBoris Popov.Fn md_done 190a1a5ca55SBoris Popovfunction can safely be called to destroy it. 191a1a5ca55SBoris Popov.Sh EXAMPLES 192a1a5ca55SBoris Popov.Bd -literal 193a1a5ca55SBoris Popovstruct mdchain *mdp; 194a1a5ca55SBoris Popovstruct mbuf *m; 195a1a5ca55SBoris Popovu_int16_t length; 196a1a5ca55SBoris Popovu_int8_t byte; 19790bd2994SRuslan Ermilov 198a1a5ca55SBoris Popovreceive(so, &m); 199a1a5ca55SBoris Popovmd_initm(mdp, m); 200a1a5ca55SBoris Popovif (md_get_uint8(mdp, &byte) != 0 || 201a1a5ca55SBoris Popov md_get_uint16le(mdp, &length) != 0) 202a1a5ca55SBoris Popov error = EBADRPC; 203a1a5ca55SBoris Popovmb_done(mdp); 204a1a5ca55SBoris Popov.Ed 205a1a5ca55SBoris Popov.Sh SEE ALSO 206a1a5ca55SBoris Popov.Xr mbuf 9 , 207a1a5ca55SBoris Popov.Xr mbchain 9 208a1a5ca55SBoris Popov.Sh AUTHORS 209a1a5ca55SBoris PopovThis manual page was written by 210a1a5ca55SBoris Popov.An Boris Popov Aq bp@FreeBSD.org . 211