xref: /freebsd/share/man/man9/mdchain.9 (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
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.Dd February 28, 2001
26.Dt MDCHAIN 9
27.Os
28.Sh NAME
29.Nm mdchain ,
30.Nm md_initm ,
31.Nm md_done ,
32.Nm md_append_record ,
33.Nm md_next_record ,
34.Nm md_get_uint8 ,
35.Nm md_get_uint16 ,
36.Nm md_get_uint16be ,
37.Nm md_get_uint16le ,
38.Nm md_get_uint32 ,
39.Nm md_get_uint32be ,
40.Nm md_get_uint32le ,
41.Nm md_get_int64 ,
42.Nm md_get_int64be ,
43.Nm md_get_int64le ,
44.Nm md_get_mem ,
45.Nm md_get_mbuf ,
46.Nm md_get_uio
47.Nd "set of functions to dissect an mbuf chain to various data types"
48.Sh SYNOPSIS
49.Cd options LIBMCHAIN
50.Li kldload libmchain
51.Pp
52.In sys/param.h
53.In sys/uio.h
54.In sys/mchain.h
55.Ft void
56.Fn md_initm "struct mdchain *mdp" "struct mbuf *m"
57.Ft void
58.Fn md_done "struct mdchain *mdp"
59.Ft void
60.Fn md_append_record "struct mdchain *mdp" "struct mbuf *top"
61.Ft int
62.Fn md_next_record "struct mdchain *mdp"
63.Ft int
64.Fn md_get_uint8 "struct mdchain *mdp" "uint8_t *x"
65.Ft int
66.Fn md_get_uint16 "struct mdchain *mdp" "uint16_t *x"
67.Ft int
68.Fn md_get_uint16be "struct mdchain *mdp" "uint16_t *x"
69.Ft int
70.Fn md_get_uint16le "struct mdchain *mdp" "uint16_t *x"
71.Ft int
72.Fn md_get_uint32 "struct mdchain *mdp" "uint32_t *x"
73.Ft int
74.Fn md_get_uint32be "struct mdchain *mdp" "uint32_t *x"
75.Ft int
76.Fn md_get_uint32le "struct mdchain *mdp" "uint32_t *x"
77.Ft int
78.Fn md_get_int64 "struct mdchain *mdp" "int64_t *x"
79.Ft int
80.Fn md_get_int64be "struct mdchain *mdp" "int64_t *x"
81.Ft int
82.Fn md_get_int64le "struct mdchain *mdp" "int64_t *x"
83.Ft int
84.Fn md_get_mem "struct mdchain *mdp" "caddr_t target" "int size" "int type"
85.Ft int
86.Fn md_get_mbuf "struct mdchain *mdp" "int size" "struct mbuf **m"
87.Ft int
88.Fn md_get_uio "struct mdchain *mdp" "struct uio *uiop" "int size"
89.Sh DESCRIPTION
90These functions are used to decompose mbuf chains to various data types.
91The
92.Vt mdchain
93structure is used as a working context
94and should be initialized through a call of the
95.Fn mb_initm
96function.
97It has the following fields:
98.Bl -tag -width "md_top"
99.It Va "md_top"
100.Pq Vt "struct mbuf *"
101A pointer to the top of the parsed mbuf chain.
102.It Va md_cur
103.Pq Vt "struct mbuf *"
104A pointer to the currently parsed mbuf.
105.It Va md_pas
106.Pq Vt int
107Offset in the current mbuf.
108.El
109.Pp
110The
111.Fn md_done
112function disposes of an mbuf chain pointed to by the
113.Fa mdp->md_top
114field and sets the field to
115.Dv NULL .
116.Pp
117The
118.Fn md_append_record
119appends a new mbuf chain using
120.Va m_nextpkt
121field to form a single linked list of mbuf chains.
122If the
123.Fa mdp->md_top
124field is
125.Dv NULL ,
126then this function behaves exactly as the
127.Fn md_initm
128function.
129.Pp
130The
131.Fn md_next_record
132function extracts the next mbuf chain and disposes the current one, if any.
133For a new mbuf chain it calls the
134.Fn md_initm
135function.
136If there is no data left the function returns
137.Er ENOENT .
138.Pp
139All
140.Fn md_get_*
141functions perform an actual copy of the data from an mbuf chain.
142Functions which have
143.Cm le
144or
145.Cm be
146suffixes will perform conversion to the little\- or big\-endian data formats.
147.Pp
148.Fn md_get_mem
149function copies
150.Fa size
151bytes of data specified by the
152.Fa source
153argument from an mbuf chain.
154The
155.Fa type
156argument specifies the method used to perform a copy,
157and can be one of the following:
158.Bl -tag -width ".Dv MB_MINLINE"
159.It Dv MB_MSYSTEM
160Use the
161.Fn bcopy
162function.
163.It Dv MB_MUSER
164Use the
165.Xr copyin 9
166function.
167.It Dv MB_MINLINE
168Use an
169.Dq inline
170loop which does not call any function.
171.El
172.Pp
173If
174.Fa target
175is
176.Dv NULL ,
177an actual copy is not performed
178and the function just skips the given number of bytes.
179.Sh RETURN VALUES
180All
181.Ft int
182functions return zero if successful,
183otherwise an error code is returned.
184.Pp
185.Em Note :
186after failure of any function,
187an mbuf chain is left in the broken state and only the
188.Fn md_done
189function can safely be called to destroy it.
190.Sh EXAMPLES
191.Bd -literal
192struct mdchain *mdp;
193struct mbuf *m;
194uint16_t length;
195uint8_t byte;
196
197receive(so, &m);
198md_initm(mdp, m);
199if (md_get_uint8(mdp, &byte) != 0 ||
200    md_get_uint16le(mdp, &length) != 0)
201	error = EBADRPC;
202mb_done(mdp);
203.Ed
204.Sh SEE ALSO
205.Xr mbchain 9 ,
206.Xr mbuf 9
207.Sh AUTHORS
208This manual page was written by
209.An Boris Popov Aq Mt bp@FreeBSD.org .
210