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