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