1XDR(3) Linux Programmer's Manual XDR(3)
2
3
4
6 xdr - library routines for external data representation
7
9 These routines allow C programmers to describe arbitrary data struc‐
10 tures in a machine-independent fashion. Data for remote procedure
11 calls are transmitted using these routines.
12
13 The prototypes below are declared in <rpc/xdr.h> and make use of the
14 following types:
15
16 typedef int bool_t;
17
18 typedef bool_t (*xdrproc_t) (XDR *, void *,...);
19
20 For the declaration of the XDR type, see <rpc/xdr.h>.
21
22 bool_t xdr_array(XDR *xdrs, char **arrp, unsigned int *sizep,
23 unsigned int maxsize, unsigned int elsize,
24 xdrproc_t elproc);
25
26 A filter primitive that translates between variable-length ar‐
27 rays and their corresponding external representations. The ar‐
28 gument arrp is the address of the pointer to the array, while
29 sizep is the address of the element count of the array; this el‐
30 ement count cannot exceed maxsize. The argument elsize is the
31 sizeof each of the array's elements, and elproc is an XDR filter
32 that translates between the array elements' C form, and their
33 external representation. This routine returns one if it suc‐
34 ceeds, zero otherwise.
35
36 bool_t xdr_bool(XDR *xdrs, bool_t *bp);
37
38 A filter primitive that translates between booleans (C integers)
39 and their external representations. When encoding data, this
40 filter produces values of either one or zero. This routine re‐
41 turns one if it succeeds, zero otherwise.
42
43 bool_t xdr_bytes(XDR *xdrs, char **sp, unsigned int *sizep,
44 unsigned int maxsize);
45
46 A filter primitive that translates between counted byte strings
47 and their external representations. The argument sp is the ad‐
48 dress of the string pointer. The length of the string is lo‐
49 cated at address sizep; strings cannot be longer than maxsize.
50 This routine returns one if it succeeds, zero otherwise.
51
52 bool_t xdr_char(XDR *xdrs, char *cp);
53
54 A filter primitive that translates between C characters and
55 their external representations. This routine returns one if it
56 succeeds, zero otherwise. Note: encoded characters are not
57 packed, and occupy 4 bytes each. For arrays of characters, it
58 is worthwhile to consider xdr_bytes(), xdr_opaque() or
59 xdr_string().
60
61 void xdr_destroy(XDR *xdrs);
62
63 A macro that invokes the destroy routine associated with the XDR
64 stream, xdrs. Destruction usually involves freeing private data
65 structures associated with the stream. Using xdrs after invok‐
66 ing xdr_destroy() is undefined.
67
68 bool_t xdr_double(XDR *xdrs, double *dp);
69
70 A filter primitive that translates between C double precision
71 numbers and their external representations. This routine re‐
72 turns one if it succeeds, zero otherwise.
73
74 bool_t xdr_enum(XDR *xdrs, enum_t *ep);
75
76 A filter primitive that translates between C enums (actually in‐
77 tegers) and their external representations. This routine re‐
78 turns one if it succeeds, zero otherwise.
79
80 bool_t xdr_float(XDR *xdrs, float *fp);
81
82 A filter primitive that translates between C floats and their
83 external representations. This routine returns one if it suc‐
84 ceeds, zero otherwise.
85
86 void xdr_free(xdrproc_t proc, char *objp);
87
88 Generic freeing routine. The first argument is the XDR routine
89 for the object being freed. The second argument is a pointer to
90 the object itself. Note: the pointer passed to this routine is
91 not freed, but what it points to is freed (recursively).
92
93 unsigned int xdr_getpos(XDR *xdrs);
94
95 A macro that invokes the get-position routine associated with
96 the XDR stream, xdrs. The routine returns an unsigned integer,
97 which indicates the position of the XDR byte stream. A desir‐
98 able feature of XDR streams is that simple arithmetic works with
99 this number, although the XDR stream instances need not guaran‐
100 tee this.
101
102 long *xdr_inline(XDR *xdrs, int len);
103
104 A macro that invokes the inline routine associated with the XDR
105 stream, xdrs. The routine returns a pointer to a contiguous
106 piece of the stream's buffer; len is the byte length of the de‐
107 sired buffer. Note: pointer is cast to long *.
108
109 Warning: xdr_inline() may return NULL (0) if it cannot allocate
110 a contiguous piece of a buffer. Therefore the behavior may vary
111 among stream instances; it exists for the sake of efficiency.
112
113 bool_t xdr_int(XDR *xdrs, int *ip);
114
115 A filter primitive that translates between C integers and their
116 external representations. This routine returns one if it suc‐
117 ceeds, zero otherwise.
118
119 bool_t xdr_long(XDR *xdrs, long *lp);
120
121 A filter primitive that translates between C long integers and
122 their external representations. This routine returns one if it
123 succeeds, zero otherwise.
124
125 void xdrmem_create(XDR *xdrs, char *addr, unsigned int size,
126 enum xdr_op op);
127
128 This routine initializes the XDR stream object pointed to by
129 xdrs. The stream's data is written to, or read from, a chunk of
130 memory at location addr whose length is no more than size bytes
131 long. The op determines the direction of the XDR stream (either
132 XDR_ENCODE, XDR_DECODE, or XDR_FREE).
133
134 bool_t xdr_opaque(XDR *xdrs, char *cp, unsigned int cnt);
135
136 A filter primitive that translates between fixed size opaque
137 data and its external representation. The argument cp is the
138 address of the opaque object, and cnt is its size in bytes.
139 This routine returns one if it succeeds, zero otherwise.
140
141 bool_t xdr_pointer(XDR *xdrs, char **objpp,
142 unsigned int objsize, xdrproc_t xdrobj);
143
144 Like xdr_reference() except that it serializes null pointers,
145 whereas xdr_reference() does not. Thus, xdr_pointer() can rep‐
146 resent recursive data structures, such as binary trees or linked
147 lists.
148
149 void xdrrec_create(XDR *xdrs, unsigned int sendsize,
150 unsigned int recvsize, char *handle,
151 int (*readit) (char *, char *, int),
152 int (*writeit) (char *, char *, int));
153
154 This routine initializes the XDR stream object pointed to by
155 xdrs. The stream's data is written to a buffer of size send‐
156 size; a value of zero indicates the system should use a suitable
157 default. The stream's data is read from a buffer of size recv‐
158 size; it too can be set to a suitable default by passing a zero
159 value. When a stream's output buffer is full, writeit is
160 called. Similarly, when a stream's input buffer is empty, rea‐
161 dit is called. The behavior of these two routines is similar to
162 the system calls read(2) and write(2), except that handle is
163 passed to the former routines as the first argument. Note: the
164 XDR stream's op field must be set by the caller.
165
166 Warning: to read from an XDR stream created by this API, you'll
167 need to call xdrrec_skiprecord() first before calling any other
168 XDR APIs. This inserts additional bytes in the stream to pro‐
169 vide record boundary information. Also, XDR streams created
170 with different xdr*_create APIs are not compatible for the same
171 reason.
172
173 bool_t xdrrec_endofrecord(XDR *xdrs, int sendnow);
174
175 This routine can be invoked only on streams created by xdr‐
176 rec_create(). The data in the output buffer is marked as a com‐
177 pleted record, and the output buffer is optionally written out
178 if sendnow is nonzero. This routine returns one if it succeeds,
179 zero otherwise.
180
181 bool_t xdrrec_eof(XDR *xdrs);
182
183 This routine can be invoked only on streams created by xdr‐
184 rec_create(). After consuming the rest of the current record in
185 the stream, this routine returns one if the stream has no more
186 input, zero otherwise.
187
188 bool_t xdrrec_skiprecord(XDR *xdrs);
189
190 This routine can be invoked only on streams created by xdr‐
191 rec_create(). It tells the XDR implementation that the rest of
192 the current record in the stream's input buffer should be dis‐
193 carded. This routine returns one if it succeeds, zero other‐
194 wise.
195
196 bool_t xdr_reference(XDR *xdrs, char **pp, unsigned int size,
197 xdrproc_t proc);
198
199 A primitive that provides pointer chasing within structures.
200 The argument pp is the address of the pointer; size is the
201 sizeof the structure that *pp points to; and proc is an XDR pro‐
202 cedure that filters the structure between its C form and its ex‐
203 ternal representation. This routine returns one if it succeeds,
204 zero otherwise.
205
206 Warning: this routine does not understand null pointers. Use
207 xdr_pointer() instead.
208
209 xdr_setpos(XDR *xdrs, unsigned int pos);
210
211 A macro that invokes the set position routine associated with
212 the XDR stream xdrs. The argument pos is a position value ob‐
213 tained from xdr_getpos(). This routine returns one if the XDR
214 stream could be repositioned, and zero otherwise.
215
216 Warning: it is difficult to reposition some types of XDR
217 streams, so this routine may fail with one type of stream and
218 succeed with another.
219
220 bool_t xdr_short(XDR *xdrs, short *sp);
221
222 A filter primitive that translates between C short integers and
223 their external representations. This routine returns one if it
224 succeeds, zero otherwise.
225
226 void xdrstdio_create(XDR *xdrs, FILE *file, enum xdr_op op);
227
228 This routine initializes the XDR stream object pointed to by
229 xdrs. The XDR stream data is written to, or read from, the
230 stdio stream file. The argument op determines the direction of
231 the XDR stream (either XDR_ENCODE, XDR_DECODE, or XDR_FREE).
232
233 Warning: the destroy routine associated with such XDR streams
234 calls fflush(3) on the file stream, but never fclose(3).
235
236 bool_t xdr_string(XDR *xdrs, char **sp, unsigned int maxsize);
237
238 A filter primitive that translates between C strings and their
239 corresponding external representations. Strings cannot be
240 longer than maxsize. Note: sp is the address of the string's
241 pointer. This routine returns one if it succeeds, zero other‐
242 wise.
243
244 bool_t xdr_u_char(XDR *xdrs, unsigned char *ucp);
245
246 A filter primitive that translates between unsigned C characters
247 and their external representations. This routine returns one if
248 it succeeds, zero otherwise.
249
250 bool_t xdr_u_int(XDR *xdrs, unsigned *up);
251
252 A filter primitive that translates between C unsigned integers
253 and their external representations. This routine returns one if
254 it succeeds, zero otherwise.
255
256 bool_t xdr_u_long(XDR *xdrs, unsigned long *ulp);
257
258 A filter primitive that translates between C unsigned long inte‐
259 gers and their external representations. This routine returns
260 one if it succeeds, zero otherwise.
261
262 bool_t xdr_u_short(XDR *xdrs, unsigned short *usp);
263
264 A filter primitive that translates between C unsigned short in‐
265 tegers and their external representations. This routine returns
266 one if it succeeds, zero otherwise.
267
268 bool_t xdr_union(XDR *xdrs, int *dscmp, char *unp,
269 struct xdr_discrim *choices,
270 xdrproc_t defaultarm); /* may equal NULL */
271
272 A filter primitive that translates between a discriminated C
273 union and its corresponding external representation. It first
274 translates the discriminant of the union located at dscmp. This
275 discriminant is always an enum_t. Next the union located at unp
276 is translated. The argument choices is a pointer to an array of
277 xdr_discrim() structures. Each structure contains an ordered
278 pair of [value,proc]. If the union's discriminant is equal to
279 the associated value, then the proc is called to translate the
280 union. The end of the xdr_discrim() structure array is denoted
281 by a routine of value NULL. If the discriminant is not found in
282 the choices array, then the defaultarm procedure is called (if
283 it is not NULL). Returns one if it succeeds, zero otherwise.
284
285 bool_t xdr_vector(XDR *xdrs, char *arrp, unsigned int size,
286 unsigned int elsize, xdrproc_t elproc);
287
288 A filter primitive that translates between fixed-length arrays
289 and their corresponding external representations. The argument
290 arrp is the address of the pointer to the array, while size is
291 the element count of the array. The argument elsize is the
292 sizeof each of the array's elements, and elproc is an XDR filter
293 that translates between the array elements' C form, and their
294 external representation. This routine returns one if it suc‐
295 ceeds, zero otherwise.
296
297 bool_t xdr_void(void);
298
299 This routine always returns one. It may be passed to RPC rou‐
300 tines that require a function argument, where nothing is to be
301 done.
302
303 bool_t xdr_wrapstring(XDR *xdrs, char **sp);
304
305 A primitive that calls xdr_string(xdrs, sp,MAXUN.UNSIGNED );
306 where MAXUN.UNSIGNED is the maximum value of an unsigned inte‐
307 ger. xdr_wrapstring() is handy because the RPC package passes a
308 maximum of two XDR routines as arguments, and xdr_string(), one
309 of the most frequently used primitives, requires three. Returns
310 one if it succeeds, zero otherwise.
311
313 For an explanation of the terms used in this section, see at‐
314 tributes(7).
315
316 ┌────────────────────────────────┬───────────────┬─────────┐
317 │Interface │ Attribute │ Value │
318 ├────────────────────────────────┼───────────────┼─────────┤
319 │xdr_array(), xdr_bool(), │ Thread safety │ MT-Safe │
320 │xdr_bytes(), xdr_char(), │ │ │
321 │xdr_destroy(), xdr_double(), │ │ │
322 │xdr_enum(), xdr_float(), │ │ │
323 │xdr_free(), xdr_getpos(), │ │ │
324 │xdr_inline(), xdr_int(), │ │ │
325 │xdr_long(), xdrmem_create(), │ │ │
326 │xdr_opaque(), xdr_pointer(), │ │ │
327 │xdrrec_create(), xdrrec_eof(), │ │ │
328 │xdrrec_endofrecord(), │ │ │
329 │xdrrec_skiprecord(), │ │ │
330 │xdr_reference(), xdr_setpos(), │ │ │
331 │xdr_short(), xdrstdio_create(), │ │ │
332 │xdr_string(), xdr_u_char(), │ │ │
333 │xdr_u_int(), xdr_u_long(), │ │ │
334 │xdr_u_short(), xdr_union(), │ │ │
335 │xdr_vector(), xdr_void(), │ │ │
336 │xdr_wrapstring() │ │ │
337 └────────────────────────────────┴───────────────┴─────────┘
338
340 rpc(3)
341
342 The following manuals:
343 eXternal Data Representation Standard: Protocol Specification
344 eXternal Data Representation: Sun Technical Notes
345 XDR: External Data Representation Standard, RFC 1014, Sun Mi‐
346 crosystems, Inc., USC-ISI.
347
349 This page is part of release 5.10 of the Linux man-pages project. A
350 description of the project, information about reporting bugs, and the
351 latest version of this page, can be found at
352 https://www.kernel.org/doc/man-pages/.
353
354
355
356 2017-09-15 XDR(3)