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 20, 2001 28a1a5ca55SBoris Popov.Dt MBCHAIN 9 29a1a5ca55SBoris Popov.Os 30a1a5ca55SBoris Popov.Sh NAME 31a1a5ca55SBoris Popov.Nm mbchain , 32a1a5ca55SBoris Popov.Nm mb_init , 33a1a5ca55SBoris Popov.Nm mb_initm , 34a1a5ca55SBoris Popov.Nm mb_done , 35a1a5ca55SBoris Popov.Nm mb_detach , 36a1a5ca55SBoris Popov.Nm mb_fixhdr , 37a1a5ca55SBoris Popov.Nm mb_reserve , 38a1a5ca55SBoris Popov.Nm mb_put_uint8 , 39a1a5ca55SBoris Popov.Nm mb_put_uint16be , 40a1a5ca55SBoris Popov.Nm mb_put_uint16le , 41a1a5ca55SBoris Popov.Nm mb_put_uint32be , 42a1a5ca55SBoris Popov.Nm mb_put_uint32le , 43a1a5ca55SBoris Popov.Nm mb_put_int64be , 44a1a5ca55SBoris Popov.Nm mb_put_int64le , 45a1a5ca55SBoris Popov.Nm mb_put_mem , 46a1a5ca55SBoris Popov.Nm mb_put_mbuf , 47a1a5ca55SBoris Popov.Nm mb_put_uio 48a1a5ca55SBoris Popov.Nd "set of functions to build an mbuf chain from various data types" 49a1a5ca55SBoris Popov.Sh SYNOPSIS 50a1a5ca55SBoris Popov.Cd options LIBMCHAIN 51a1a5ca55SBoris Popov.Li kldload libmchain 52a1a5ca55SBoris Popov.Pp 5332eef9aeSRuslan Ermilov.In sys/param.h 54f16b3c0dSChad David.In sys/uio.h 5532eef9aeSRuslan Ermilov.In sys/mchain.h 56a1a5ca55SBoris Popov.Ft int 57a1a5ca55SBoris Popov.Fn mb_init "struct mbchain *mbp" 58a1a5ca55SBoris Popov.Ft void 59a1a5ca55SBoris Popov.Fn mb_initm "struct mbchain *mbp" "struct mbuf *m" 60a1a5ca55SBoris Popov.Ft void 61a1a5ca55SBoris Popov.Fn mb_done "struct mbchain *mbp" 62a1a5ca55SBoris Popov.Ft struct mbuf * 63a1a5ca55SBoris Popov.Fn mb_detach "struct mbchain *mbp" 64a1a5ca55SBoris Popov.Ft int 65a1a5ca55SBoris Popov.Fn mb_fixhdr "struct mbchain *mbp" 66a1a5ca55SBoris Popov.Ft caddr_t 67a1a5ca55SBoris Popov.Fn mb_reserve "struct mbchain *mbp" "int size" 68a1a5ca55SBoris Popov.Ft int 69a1a5ca55SBoris Popov.Fn mb_put_uint8 "struct mbchain *mbp" "u_int8_t x" 70a1a5ca55SBoris Popov.Ft int 71a1a5ca55SBoris Popov.Fn mb_put_uint16be "struct mbchain *mbp" "u_int16_t x" 72a1a5ca55SBoris Popov.Ft int 73a1a5ca55SBoris Popov.Fn mb_put_uint16le "struct mbchain *mbp" "u_int16_t x" 74a1a5ca55SBoris Popov.Ft int 75a1a5ca55SBoris Popov.Fn mb_put_uint32be "struct mbchain *mbp" "u_int32_t x" 76a1a5ca55SBoris Popov.Ft int 77a1a5ca55SBoris Popov.Fn mb_put_uint32le "struct mbchain *mbp" "u_int32_t x" 78a1a5ca55SBoris Popov.Ft int 79a1a5ca55SBoris Popov.Fn mb_put_int64be "struct mbchain *mbp" "int64_t x" 80a1a5ca55SBoris Popov.Ft int 81a1a5ca55SBoris Popov.Fn mb_put_int64le "struct mbchain *mbp" "int64_t x" 82a1a5ca55SBoris Popov.Ft int 83a1a5ca55SBoris Popov.Fn mb_put_mem "struct mbchain *mbp" "c_caddr_t source" "int size" "int type" 84a1a5ca55SBoris Popov.Ft int 85a1a5ca55SBoris Popov.Fn mb_put_mbuf "struct mbchain *mbp" "struct mbuf *m" 86a1a5ca55SBoris Popov.Ft int 87a1a5ca55SBoris Popov.Fn mb_put_uio "struct mbchain *mbp" "struct uio *uiop" "int size" 88a1a5ca55SBoris Popov.Sh DESCRIPTION 89a1a5ca55SBoris PopovThese functions are used to compose mbuf chains from various data types. 90a1a5ca55SBoris PopovThe 91a1a5ca55SBoris Popov.Vt mbchain 92a1a5ca55SBoris Popovstructure is used as a working context and should be initialized with a call 93a1a5ca55SBoris Popovto either 94a1a5ca55SBoris Popov.Fn mb_init 95a1a5ca55SBoris Popovor 96a1a5ca55SBoris Popov.Fn mb_initm . 97a1a5ca55SBoris PopovIt has the following fields: 98b0536a9bSRuslan Ermilov.Bl -tag -width ".Va mb_count" 99a1a5ca55SBoris Popov.It Va "mb_top" 100b0536a9bSRuslan Ermilov.Pq Vt "struct mbuf *" 101b0536a9bSRuslan ErmilovA pointer to the top of constructed mbuf chain. 102a1a5ca55SBoris Popov.It Va mb_cur 103b0536a9bSRuslan Ermilov.Pq Vt "struct mbuf *" 104b0536a9bSRuslan ErmilovA pointer to the currently filled mbuf. 105a1a5ca55SBoris Popov.It Va mb_mleft 106b0536a9bSRuslan Ermilov.Pq Vt int 107b0536a9bSRuslan ErmilovNumber of bytes left in the current mbuf. 108a1a5ca55SBoris Popov.It Va mb_count 109b0536a9bSRuslan Ermilov.Pq Vt int 110b0536a9bSRuslan ErmilovTotal number of bytes placed in the mbuf chain. 111a1a5ca55SBoris Popov.It Va mb_copy 112b0536a9bSRuslan Ermilov.Pq Vt "mb_copy_t *" 113b0536a9bSRuslan ErmilovUser-defined function to perform a copy into mbuf; 114a1a5ca55SBoris Popovuseful if any unusual 115b0536a9bSRuslan Ermilovdata conversion is necessary. 116a1a5ca55SBoris Popov.It Va mb_udata 117b0536a9bSRuslan Ermilov.Pq Vt "void *" 118b0536a9bSRuslan ErmilovUser-supplied data which can be used in the 119a1a5ca55SBoris Popov.Va mb_copy 120b0536a9bSRuslan Ermilovfunction. 121a1a5ca55SBoris Popov.El 122a1a5ca55SBoris Popov.Pp 123a1a5ca55SBoris Popov.Fn mb_done 124a1a5ca55SBoris Popovfunction disposes an mbuf chain pointed to by 125a1a5ca55SBoris Popov.Fa mbp->mb_top 126a1a5ca55SBoris Popovfield and sets 127a1a5ca55SBoris Popovthe field to 128a1a5ca55SBoris Popov.Dv NULL . 129a1a5ca55SBoris Popov.Pp 130a1a5ca55SBoris Popov.Fn mb_detach 131a1a5ca55SBoris Popovfunction returns the value of 132a1a5ca55SBoris Popov.Fa mbp->mb_top 133a1a5ca55SBoris Popovfield and sets its value to 134a1a5ca55SBoris Popov.Dv NULL . 135a1a5ca55SBoris Popov.Pp 136a1a5ca55SBoris Popov.Fn mb_fixhdr 137a1a5ca55SBoris Popovrecalculates the length of an mbuf chain and updates the 138a1a5ca55SBoris Popov.Va m_pkthdr.len 139a1a5ca55SBoris Popovfield of the first mbuf in the chain. 140fa1b1bbcSMurray StokelyIt returns the calculated length. 141a1a5ca55SBoris Popov.Pp 142a1a5ca55SBoris Popov.Fn mb_reserve 143a1a5ca55SBoris Popovensures that the object of the length specified by the 144a1a5ca55SBoris Popov.Fa size 145a1a5ca55SBoris Popovargument will fit in the current mbuf (mbuf allocation is performed if 146a1a5ca55SBoris Popovnecessary), and advances all pointers as if the real data was placed. 147a1a5ca55SBoris PopovReturned 148a1a5ca55SBoris Popovvalue will point to the beginning of the reserved space. 149a1a5ca55SBoris PopovNote that the size 150a1a5ca55SBoris Popovof the object should not exceed 151a1a5ca55SBoris Popov.Dv MLEN 152a1a5ca55SBoris Popovbytes. 153a1a5ca55SBoris Popov.Pp 154a1a5ca55SBoris PopovAll 155a1a5ca55SBoris Popov.Fn mb_put_* 156a1a5ca55SBoris Popovfunctions perform an actual copy of the data into mbuf chain. 157a1a5ca55SBoris PopovFunctions which have 158a1a5ca55SBoris Popov.Cm le 159a1a5ca55SBoris Popovor 160a1a5ca55SBoris Popov.Cm be 161a1a5ca55SBoris Popovsuffixes will perform conversion to the little\- or big\-endian data formats. 162a1a5ca55SBoris Popov.Pp 163a1a5ca55SBoris Popov.Fn mb_put_mem 164a1a5ca55SBoris Popovfunction copies 165a1a5ca55SBoris Popov.Fa size 166a1a5ca55SBoris Popovbytes of data specified by the 167a1a5ca55SBoris Popov.Fa source 168a1a5ca55SBoris Popovargument to an mbuf chain. 169a1a5ca55SBoris PopovThe 170a1a5ca55SBoris Popov.Fa type 171a1a5ca55SBoris Popovargument specifies the method used to perform a copy, 172a1a5ca55SBoris Popovand can be one of the following: 173b0536a9bSRuslan Ermilov.Bl -tag -width ".Dv MB_MINLINE" 174a1a5ca55SBoris Popov.It Dv MB_MSYSTEM 175b0536a9bSRuslan ErmilovUse 176a1a5ca55SBoris Popov.Fn bcopy 177b0536a9bSRuslan Ermilovfunction. 178a1a5ca55SBoris Popov.It Dv MB_MUSER 179b0536a9bSRuslan ErmilovUse 180a1a5ca55SBoris Popov.Xr copyin 9 181b0536a9bSRuslan Ermilovfunction. 182a1a5ca55SBoris Popov.It Dv MB_MINLINE 183b0536a9bSRuslan ErmilovUse an 184a1a5ca55SBoris Popov.Dq inline 185b0536a9bSRuslan Ermilovloop which does not call any function. 186a1a5ca55SBoris Popov.It Dv MB_MZERO 187b0536a9bSRuslan ErmilovDo not copy any data, but just fill the destination with zero bytes. 188a1a5ca55SBoris Popov.It Dv MB_MCUSTOM 189b0536a9bSRuslan ErmilovCall function specified by the 190a1a5ca55SBoris Popov.Fa mbp->mb_copy 191b0536a9bSRuslan Ermilovfield. 192a1a5ca55SBoris Popov.El 193a1a5ca55SBoris Popov.Sh RETURN VALUES 194a1a5ca55SBoris PopovAll 195a1a5ca55SBoris Popov.Ft int 196fa1b1bbcSMurray Stokelyfunctions except 197fa1b1bbcSMurray Stokely.Fn mb_fixhdr 198fa1b1bbcSMurray Stokelyreturn zero if successful and an error code otherwise. 199a1a5ca55SBoris Popov.Pp 200a1a5ca55SBoris Popov.Em Note : 201a1a5ca55SBoris Popovafter failure of any function, an mbuf chain is left in the broken state, 202a1a5ca55SBoris Popovand only 203a1a5ca55SBoris Popov.Fn mb_done 204a1a5ca55SBoris Popovfunction can safely be called to destroy it. 205a1a5ca55SBoris Popov.Sh EXAMPLES 206a1a5ca55SBoris Popov.Bd -literal 207a1a5ca55SBoris Popovstruct mbchain *mbp; 208a1a5ca55SBoris Popovstruct mbuf *m; 209a1a5ca55SBoris Popov 210a1a5ca55SBoris Popovmb_init(mbp); 211a1a5ca55SBoris Popovmb_put_uint8(mbp, 33); 212a1a5ca55SBoris Popovmb_put_uint16le(mbp, length); 213eb085c43SRuslan Ermilovm = m_copym(mbp->mb_top, 0, M_COPYALL, M_WAIT); 214a1a5ca55SBoris Popovsend(m); 215a1a5ca55SBoris Popovmb_done(mbp); 216a1a5ca55SBoris Popov.Ed 217a1a5ca55SBoris Popov.Sh SEE ALSO 218a1a5ca55SBoris Popov.Xr mbuf 9 , 219a1a5ca55SBoris Popov.Xr mdchain 9 220a1a5ca55SBoris Popov.Sh AUTHORS 221a1a5ca55SBoris PopovThis manual page was written by 222a1a5ca55SBoris Popov.An Boris Popov Aq bp@FreeBSD.org . 223