1 .\" This page was taken from the 4.4BSD-Lite CDROM (BSD license)
3 .\" %%%LICENSE_START(BSD_ONELINE_CDROM)
4 .\" This page was taken from the 4.4BSD-Lite CDROM (BSD license)
7 .\" @(#)xdr.3n 2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI
9 .\" 2007-12-30, mtk, Convert function prototypes to modern C syntax
11 .TH XDR 3 2017-09-15 "" "Linux Programmer's Manual"
13 xdr \- library routines for external data representation
14 .SH SYNOPSIS AND DESCRIPTION
16 These routines allow C programmers to describe
17 arbitrary data structures in a machine-independent fashion.
18 Data for remote procedure calls are transmitted using these
21 The prototypes below are declared in
23 and make use of the following types:
27 .BI "typedef int " bool_t ;
29 .BI "typedef bool_t (*" xdrproc_t ") (XDR *, void *,...);"
33 For the declaration of the
39 .BI "bool_t xdr_array(XDR *" xdrs ", char **" arrp ", unsigned int *" sizep ,
40 .BI " unsigned int " maxsize ", unsigned int " elsize ,
41 .BI " xdrproc_t " elproc );
44 A filter primitive that translates between variable-length arrays
45 and their corresponding external representations.
48 is the address of the pointer to the array, while
50 is the address of the element count of the array;
51 this element count cannot exceed
57 each of the array's elements, and
59 is an XDR filter that translates between
60 the array elements' C form, and their external
62 This routine returns one if it succeeds, zero otherwise.
65 .BI "bool_t xdr_bool(XDR *" xdrs ", bool_t *" bp );
68 A filter primitive that translates between booleans (C
70 and their external representations.
71 When encoding data, this
72 filter produces values of either one or zero.
73 This routine returns one if it succeeds, zero otherwise.
76 .BI "bool_t xdr_bytes(XDR *" xdrs ", char **" sp ", unsigned int *" sizep ,
77 .BI " unsigned int " maxsize );
80 A filter primitive that translates between counted byte
81 strings and their external representations.
84 is the address of the string pointer.
86 string is located at address
88 strings cannot be longer than
90 This routine returns one if it succeeds, zero otherwise.
93 .BI "bool_t xdr_char(XDR *" xdrs ", char *" cp );
96 A filter primitive that translates between C characters
97 and their external representations.
98 This routine returns one if it succeeds, zero otherwise.
99 Note: encoded characters are not packed, and occupy 4 bytes each.
100 For arrays of characters, it is worthwhile to
108 .BI "void xdr_destroy(XDR *" xdrs );
111 A macro that invokes the destroy routine associated with the XDR stream,
113 Destruction usually involves freeing private data structures
114 associated with the stream.
122 .BI "bool_t xdr_double(XDR *" xdrs ", double *" dp );
125 A filter primitive that translates between C
127 precision numbers and their external representations.
128 This routine returns one if it succeeds, zero otherwise.
131 .BI "bool_t xdr_enum(XDR *" xdrs ", enum_t *" ep );
134 A filter primitive that translates between C
136 (actually integers) and their external representations.
137 This routine returns one if it succeeds, zero otherwise.
140 .BI "bool_t xdr_float(XDR *" xdrs ", float *" fp );
143 A filter primitive that translates between C
145 and their external representations.
146 This routine returns one if it succeeds, zero otherwise.
149 .BI "void xdr_free(xdrproc_t " proc ", char *" objp );
152 Generic freeing routine.
153 The first argument is the XDR routine for the object being freed.
154 The second argument is a pointer to the object itself.
155 Note: the pointer passed to this routine is
157 freed, but what it points to
162 .BI "unsigned int xdr_getpos(XDR *" xdrs );
165 A macro that invokes the get-position routine
166 associated with the XDR stream,
168 The routine returns an unsigned integer,
169 which indicates the position of the XDR byte stream.
170 A desirable feature of XDR
171 streams is that simple arithmetic works with this number,
172 although the XDR stream instances need not guarantee this.
175 .BI "long *xdr_inline(XDR *" xdrs ", int " len );
178 A macro that invokes the inline routine associated with the XDR stream,
180 The routine returns a pointer
181 to a contiguous piece of the stream's buffer;
183 is the byte length of the desired buffer.
184 Note: pointer is cast to
190 if it cannot allocate a contiguous piece of a buffer.
191 Therefore the behavior may vary among stream instances;
192 it exists for the sake of efficiency.
195 .BI "bool_t xdr_int(XDR *" xdrs ", int *" ip );
198 A filter primitive that translates between C integers
199 and their external representations.
200 This routine returns one if it succeeds, zero otherwise.
203 .BI "bool_t xdr_long(XDR *" xdrs ", long *" lp );
206 A filter primitive that translates between C
208 integers and their external representations.
209 This routine returns one if it succeeds, zero otherwise.
212 .BI "void xdrmem_create(XDR *" xdrs ", char *" addr ", unsigned int " size ,
213 .BI " enum xdr_op " op );
216 This routine initializes the XDR stream object pointed to by
218 The stream's data is written to, or read from,
219 a chunk of memory at location
221 whose length is no more than
226 determines the direction of the XDR stream (either
233 .BI "bool_t xdr_opaque(XDR *" xdrs ", char *" cp ", unsigned int " cnt );
236 A filter primitive that translates between fixed size opaque data
237 and its external representation.
240 is the address of the opaque object, and
242 is its size in bytes.
243 This routine returns one if it succeeds, zero otherwise.
246 .BI "bool_t xdr_pointer(XDR *" xdrs ", char **" objpp ,
247 .BI " unsigned int " objsize ", xdrproc_t " xdrobj );
252 except that it serializes null pointers, whereas
258 recursive data structures, such as binary trees or
262 .BI "void xdrrec_create(XDR *" xdrs ", unsigned int " sendsize ,
263 .BI " unsigned int " recvsize ", char *" handle ,
264 .BI " int (*" readit ") (char *, char *, int),"
265 .BI " int (*" writeit ") (char *, char *, int));"
268 This routine initializes the XDR stream object pointed to by
270 The stream's data is written to a buffer of size
272 a value of zero indicates the system should use a suitable default.
273 The stream's data is read from a buffer of size
275 it too can be set to a suitable default by passing a zero value.
276 When a stream's output buffer is full,
279 Similarly, when a stream's input buffer is empty,
282 The behavior of these two routines is similar to
289 is passed to the former routines as the first argument.
290 Note: the XDR stream's
292 field must be set by the caller.
294 Warning: to read from an XDR stream created by this API,
296 .BR xdrrec_skiprecord ()
297 first before calling any other XDR APIs.
298 This inserts additional bytes in the stream to provide
299 record boundary information.
300 Also, XDR streams created with different
302 APIs are not compatible for the same reason.
305 .BI "bool_t xdrrec_endofrecord(XDR *" xdrs ", int " sendnow );
308 This routine can be invoked only on streams created by
309 .BR xdrrec_create ().
310 The data in the output buffer is marked as a completed record,
311 and the output buffer is optionally written out if
314 This routine returns one if it succeeds, zero otherwise.
317 .BI "bool_t xdrrec_eof(XDR *" xdrs );
320 This routine can be invoked only on streams created by
321 .BR xdrrec_create ().
322 After consuming the rest of the current record in the stream,
323 this routine returns one if the stream has no more input,
327 .BI "bool_t xdrrec_skiprecord(XDR *" xdrs );
330 This routine can be invoked only on
332 .BR xdrrec_create ().
333 It tells the XDR implementation that the rest of the current record
334 in the stream's input buffer should be discarded.
335 This routine returns one if it succeeds, zero otherwise.
338 .BI "bool_t xdr_reference(XDR *" xdrs ", char **" pp ", unsigned int " size ,
339 .BI " xdrproc_t " proc );
342 A primitive that provides pointer chasing within structures.
345 is the address of the pointer;
353 is an XDR procedure that filters the structure
354 between its C form and its external representation.
355 This routine returns one if it succeeds, zero otherwise.
357 Warning: this routine does not understand null pointers.
363 .BI "xdr_setpos(XDR *" xdrs ", unsigned int " pos );
366 A macro that invokes the set position routine associated with
371 is a position value obtained from
373 This routine returns one if the XDR stream could be repositioned,
376 Warning: it is difficult to reposition some types of XDR
377 streams, so this routine may fail with one
378 type of stream and succeed with another.
381 .BI "bool_t xdr_short(XDR *" xdrs ", short *" sp );
384 A filter primitive that translates between C
386 integers and their external representations.
387 This routine returns one if it succeeds, zero otherwise.
390 .BI "void xdrstdio_create(XDR *" xdrs ", FILE *" file ", enum xdr_op " op );
393 This routine initializes the XDR stream object pointed to by
395 The XDR stream data is written to, or read from, the
401 determines the direction of the XDR stream (either
407 Warning: the destroy routine associated with such XDR streams calls
415 .BI "bool_t xdr_string(XDR *" xdrs ", char **" sp ", unsigned int " maxsize );
418 A filter primitive that translates between C strings and
419 their corresponding external representations.
420 Strings cannot be longer than
424 is the address of the string's pointer.
425 This routine returns one if it succeeds, zero otherwise.
428 .BI "bool_t xdr_u_char(XDR *" xdrs ", unsigned char *" ucp );
431 A filter primitive that translates between
433 C characters and their external representations.
434 This routine returns one if it succeeds, zero otherwise.
437 .BI "bool_t xdr_u_int(XDR *" xdrs ", unsigned *" up );
440 A filter primitive that translates between C
442 integers and their external representations.
443 This routine returns one if it succeeds, zero otherwise.
446 .BI "bool_t xdr_u_long(XDR *" xdrs ", unsigned long *" ulp );
449 A filter primitive that translates between C
451 integers and their external representations.
452 This routine returns one if it succeeds, zero otherwise.
455 .BI "bool_t xdr_u_short(XDR *" xdrs ", unsigned short *" usp );
458 A filter primitive that translates between C
460 integers and their external representations.
461 This routine returns one if it succeeds, zero otherwise.
464 .BI "bool_t xdr_union(XDR *" xdrs ", int *" dscmp ", char *" unp ,
465 .BI " struct xdr_discrim *" choices ,
466 .BI " xdrproc_t " defaultarm "); /* may equal NULL */"
469 A filter primitive that translates between a discriminated C
471 and its corresponding external representation.
473 translates the discriminant of the union located at
475 This discriminant is always an
477 Next the union located at
482 is a pointer to an array of
485 Each structure contains an ordered pair of
486 .RI [ value , proc ].
487 If the union's discriminant is equal to the associated
491 is called to translate the union.
494 structure array is denoted by a routine of value NULL.
495 If the discriminant is not found in the
499 procedure is called (if it is not NULL).
500 Returns one if it succeeds, zero otherwise.
503 .BI "bool_t xdr_vector(XDR *" xdrs ", char *" arrp ", unsigned int " size ,
504 .BI " unsigned int " elsize ", xdrproc_t " elproc );
507 A filter primitive that translates between fixed-length arrays
508 and their corresponding external representations.
511 is the address of the pointer to the array, while
513 is the element count of the array.
518 each of the array's elements, and
520 is an XDR filter that translates between
521 the array elements' C form, and their external
523 This routine returns one if it succeeds, zero otherwise.
526 .BI "bool_t xdr_void(void);"
529 This routine always returns one.
530 It may be passed to RPC routines that require a function argument,
531 where nothing is to be done.
534 .BI "bool_t xdr_wrapstring(XDR *" xdrs ", char **" sp );
537 A primitive that calls
538 .B "xdr_string(xdrs, sp,MAXUN.UNSIGNED );"
541 is the maximum value of an unsigned integer.
542 .BR xdr_wrapstring ()
543 is handy because the RPC package passes a maximum of two XDR
544 routines as arguments, and
546 one of the most frequently used primitives, requires three.
547 Returns one if it succeeds, zero otherwise.
549 For an explanation of the terms used in this section, see
555 Interface Attribute Value
576 .BR xdrmem_create (),
581 .BR xdrrec_create (),
584 .BR xdrrec_endofrecord (),
586 .BR xdrrec_skiprecord (),
588 .BR xdr_reference (),
592 .BR xdrstdio_create (),
606 .BR xdr_wrapstring ()
607 T} Thread safety MT-Safe
613 The following manuals:
615 eXternal Data Representation Standard: Protocol Specification
617 eXternal Data Representation: Sun Technical Notes
619 .IR "XDR: External Data Representation Standard" ,
620 RFC\ 1014, Sun Microsystems, Inc.,