malloc.3: ffix
[man-pages.git] / man3 / xdr.3
blob83f668dc9373edb489236226c1fcc349f555327e
1 .\" This page was taken from the 4.4BSD-Lite CDROM (BSD license)
2 .\"
3 .\" %%%LICENSE_START(BSD_ONELINE_CDROM)
4 .\" This page was taken from the 4.4BSD-Lite CDROM (BSD license)
5 .\" %%%LICENSE_END
6 .\"
7 .\" @(#)xdr.3n  2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI
8 .\"
9 .\" 2007-12-30, mtk, Convert function prototypes to modern C syntax
10 .\"
11 .TH XDR 3 2021-03-22 "" "Linux Programmer's Manual"
12 .SH NAME
13 xdr \- library routines for external data representation
14 .SH SYNOPSIS AND DESCRIPTION
15 These routines allow C programmers to describe
16 arbitrary data structures in a machine-independent fashion.
17 Data for remote procedure calls are transmitted using these
18 routines.
19 .PP
20 The prototypes below are declared in
21 .I <rpc/xdr.h>
22 and make use of the following types:
23 .PP
24 .RS 4
25 .EX
26 .BI "typedef int " bool_t ;
27 .PP
28 .BI "typedef bool_t (*" xdrproc_t ")(XDR *, void *,...);"
29 .EE
30 .RE
31 .PP
32 For the declaration of the
33 .I XDR
34 type, see
35 .IR <rpc/xdr.h> .
36 .PP
37 .nf
38 .BI "bool_t xdr_array(XDR *" xdrs ", char **" arrp ", unsigned int *" sizep ,
39 .BI "                 unsigned int " maxsize ", unsigned int " elsize ,
40 .BI "                 xdrproc_t " elproc );
41 .fi
42 .IP
43 A filter primitive that translates between variable-length arrays
44 and their corresponding external representations.
45 The argument
46 .I arrp
47 is the address of the pointer to the array, while
48 .I sizep
49 is the address of the element count of the array;
50 this element count cannot exceed
51 .IR maxsize .
52 The argument
53 .I elsize
54 is the
55 .I sizeof
56 each of the array's elements, and
57 .I elproc
58 is an XDR filter that translates between
59 the array elements' C form, and their external
60 representation.
61 This routine returns one if it succeeds, zero otherwise.
62 .PP
63 .nf
64 .BI "bool_t xdr_bool(XDR *" xdrs ", bool_t *" bp );
65 .fi
66 .IP
67 A filter primitive that translates between booleans (C
68 integers)
69 and their external representations.
70 When encoding data, this
71 filter produces values of either one or zero.
72 This routine returns one if it succeeds, zero otherwise.
73 .PP
74 .nf
75 .BI "bool_t xdr_bytes(XDR *" xdrs ", char **" sp ", unsigned int *" sizep ,
76 .BI "                 unsigned int " maxsize );
77 .fi
78 .IP
79 A filter primitive that translates between counted byte
80 strings and their external representations.
81 The argument
82 .I sp
83 is the address of the string pointer.
84 The length of the
85 string is located at address
86 .IR sizep ;
87 strings cannot be longer than
88 .IR maxsize .
89 This routine returns one if it succeeds, zero otherwise.
90 .PP
91 .nf
92 .BI "bool_t xdr_char(XDR *" xdrs ", char *" cp );
93 .fi
94 .IP
95 A filter primitive that translates between C characters
96 and their external representations.
97 This routine returns one if it succeeds, zero otherwise.
98 Note: encoded characters are not packed, and occupy 4 bytes each.
99 For arrays of characters, it is worthwhile to
100 consider
101 .BR xdr_bytes (),
102 .BR xdr_opaque (),
104 .BR xdr_string ().
107 .BI "void xdr_destroy(XDR *" xdrs );
110 A macro that invokes the destroy routine associated with the XDR stream,
111 .IR xdrs .
112 Destruction usually involves freeing private data structures
113 associated with the stream.
114 Using
115 .I xdrs
116 after invoking
117 .BR xdr_destroy ()
118 is undefined.
121 .BI "bool_t xdr_double(XDR *" xdrs ", double *" dp );
124 A filter primitive that translates between C
125 .I double
126 precision numbers and their external representations.
127 This routine returns one if it succeeds, zero otherwise.
130 .BI "bool_t xdr_enum(XDR *" xdrs ", enum_t *" ep );
133 A filter primitive that translates between C
134 .IR enum s
135 (actually integers) and their external representations.
136 This routine returns one if it succeeds, zero otherwise.
139 .BI "bool_t xdr_float(XDR *" xdrs ", float *" fp );
142 A filter primitive that translates between C
143 .IR float s
144 and their external representations.
145 This routine returns one if it succeeds, zero otherwise.
148 .BI "void xdr_free(xdrproc_t " proc ", char *" objp );
151 Generic freeing routine.
152 The first argument is the XDR routine for the object being freed.
153 The second argument is a pointer to the object itself.
154 Note: the pointer passed to this routine is
155 .I not
156 freed, but what it points to
157 .I is
158 freed (recursively).
161 .BI "unsigned int xdr_getpos(XDR *" xdrs );
164 A macro that invokes the get-position routine
165 associated with the XDR stream,
166 .IR xdrs .
167 The routine returns an unsigned integer,
168 which indicates the position of the XDR byte stream.
169 A desirable feature of XDR
170 streams is that simple arithmetic works with this number,
171 although the XDR stream instances need not guarantee this.
174 .BI "long *xdr_inline(XDR *" xdrs ", int " len );
177 A macro that invokes the inline routine associated with the XDR stream,
178 .IR xdrs .
179 The routine returns a pointer
180 to a contiguous piece of the stream's buffer;
181 .I len
182 is the byte length of the desired buffer.
183 Note: pointer is cast to
184 .IR "long\ *" .
186 Warning:
187 .BR xdr_inline ()
188 may return NULL (0)
189 if it cannot allocate a contiguous piece of a buffer.
190 Therefore the behavior may vary among stream instances;
191 it exists for the sake of efficiency.
194 .BI "bool_t xdr_int(XDR *" xdrs ", int *" ip );
197 A filter primitive that translates between C integers
198 and their external representations.
199 This routine returns one if it succeeds, zero otherwise.
202 .BI "bool_t xdr_long(XDR *" xdrs ", long *" lp );
205 A filter primitive that translates between C
206 .I long
207 integers and their external representations.
208 This routine returns one if it succeeds, zero otherwise.
211 .BI "void xdrmem_create(XDR *" xdrs ", char *" addr ", unsigned int " size ,
212 .BI "                   enum xdr_op " op );
215 This routine initializes the XDR stream object pointed to by
216 .IR xdrs .
217 The stream's data is written to, or read from,
218 a chunk of memory at location
219 .I addr
220 whose length is no more than
221 .I size
222 bytes long.
224 .I op
225 determines the direction of the XDR stream (either
226 .BR XDR_ENCODE ,
227 .BR XDR_DECODE ,
229 .BR XDR_FREE ).
232 .BI "bool_t xdr_opaque(XDR *" xdrs ", char *" cp ", unsigned int " cnt );
235 A filter primitive that translates between fixed size opaque data
236 and its external representation.
237 The argument
238 .I cp
239 is the address of the opaque object, and
240 .I cnt
241 is its size in bytes.
242 This routine returns one if it succeeds, zero otherwise.
245 .BI "bool_t xdr_pointer(XDR *" xdrs ", char **" objpp ,
246 .BI "                   unsigned int " objsize ", xdrproc_t " xdrobj );
249 Like
250 .BR xdr_reference ()
251 except that it serializes null pointers, whereas
252 .BR xdr_reference ()
253 does not.
254 Thus,
255 .BR xdr_pointer ()
256 can represent
257 recursive data structures, such as binary trees or
258 linked lists.
261 .BI "void xdrrec_create(XDR *" xdrs ", unsigned int " sendsize ,
262 .BI "                   unsigned int " recvsize ", char *" handle ,
263 .BI "                   int (*" readit ")(char *, char *, int),"
264 .BI "                   int (*" writeit ")(char *, char *, int));"
267 This routine initializes the XDR stream object pointed to by
268 .IR xdrs .
269 The stream's data is written to a buffer of size
270 .IR sendsize ;
271 a value of zero indicates the system should use a suitable default.
272 The stream's data is read from a buffer of size
273 .IR recvsize ;
274 it too can be set to a suitable default by passing a zero value.
275 When a stream's output buffer is full,
276 .I writeit
277 is called.
278 Similarly, when a stream's input buffer is empty,
279 .I readit
280 is called.
281 The behavior of these two routines is similar to
282 the system calls
283 .BR read (2)
285 .BR write (2),
286 except that
287 .I handle
288 is passed to the former routines as the first argument.
289 Note: the XDR stream's
290 .I op
291 field must be set by the caller.
293 Warning: to read from an XDR stream created by this API,
294 you'll need to call
295 .BR xdrrec_skiprecord ()
296 first before calling any other XDR APIs.
297 This inserts additional bytes in the stream to provide
298 record boundary information.
299 Also, XDR streams created with different
300 .BR xdr*_create
301 APIs are not compatible for the same reason.
304 .BI "bool_t xdrrec_endofrecord(XDR *" xdrs ", int " sendnow );
307 This routine can be invoked only on streams created by
308 .BR xdrrec_create ().
309 The data in the output buffer is marked as a completed record,
310 and the output buffer is optionally written out if
311 .I sendnow
312 is nonzero.
313 This routine returns one if it succeeds, zero otherwise.
316 .BI "bool_t xdrrec_eof(XDR *" xdrs );
319 This routine can be invoked only on streams created by
320 .BR xdrrec_create ().
321 After consuming the rest of the current record in the stream,
322 this routine returns one if the stream has no more input,
323 zero otherwise.
326 .BI "bool_t xdrrec_skiprecord(XDR *" xdrs );
329 This routine can be invoked only on
330 streams created by
331 .BR xdrrec_create ().
332 It tells the XDR implementation that the rest of the current record
333 in the stream's input buffer should be discarded.
334 This routine returns one if it succeeds, zero otherwise.
337 .BI "bool_t xdr_reference(XDR *" xdrs ", char **" pp ", unsigned int " size ,
338 .BI "                     xdrproc_t " proc );
341 A primitive that provides pointer chasing within structures.
342 The argument
343 .I pp
344 is the address of the pointer;
345 .I size
346 is the
347 .I sizeof
348 the structure that
349 .I *pp
350 points to; and
351 .I proc
352 is an XDR procedure that filters the structure
353 between its C form and its external representation.
354 This routine returns one if it succeeds, zero otherwise.
356 Warning: this routine does not understand null pointers.
358 .BR xdr_pointer ()
359 instead.
362 .BI "xdr_setpos(XDR *" xdrs ", unsigned int " pos );
365 A macro that invokes the set position routine associated with
366 the XDR stream
367 .IR xdrs .
368 The argument
369 .I pos
370 is a position value obtained from
371 .BR xdr_getpos ().
372 This routine returns one if the XDR stream could be repositioned,
373 and zero otherwise.
375 Warning: it is difficult to reposition some types of XDR
376 streams, so this routine may fail with one
377 type of stream and succeed with another.
380 .BI "bool_t xdr_short(XDR *" xdrs ", short *" sp );
383 A filter primitive that translates between C
384 .I short
385 integers and their external representations.
386 This routine returns one if it succeeds, zero otherwise.
389 .BI "void xdrstdio_create(XDR *" xdrs ", FILE *" file ", enum xdr_op " op );
392 This routine initializes the XDR stream object pointed to by
393 .IR xdrs .
394 The XDR stream data is written to, or read from, the
395 .I stdio
396 stream
397 .IR file .
398 The argument
399 .I op
400 determines the direction of the XDR stream (either
401 .BR XDR_ENCODE ,
402 .BR XDR_DECODE ,
404 .BR XDR_FREE ).
406 Warning: the destroy routine associated with such XDR streams calls
407 .BR fflush (3)
408 on the
409 .I file
410 stream, but never
411 .BR fclose (3).
414 .BI "bool_t xdr_string(XDR *" xdrs ", char **" sp ", unsigned int " maxsize );
417 A filter primitive that translates between C strings and
418 their corresponding external representations.
419 Strings cannot be longer than
420 .IR maxsize .
421 Note:
422 .I sp
423 is the address of the string's pointer.
424 This routine returns one if it succeeds, zero otherwise.
427 .BI "bool_t xdr_u_char(XDR *" xdrs ", unsigned char *" ucp );
430 A filter primitive that translates between
431 .I unsigned
432 C characters and their external representations.
433 This routine returns one if it succeeds, zero otherwise.
436 .BI "bool_t xdr_u_int(XDR *" xdrs ", unsigned int *" up );
439 A filter primitive that translates between C
440 .I unsigned
441 integers and their external representations.
442 This routine returns one if it succeeds, zero otherwise.
445 .BI "bool_t xdr_u_long(XDR *" xdrs ", unsigned long *" ulp );
448 A filter primitive that translates between C
449 .I "unsigned long"
450 integers and their external representations.
451 This routine returns one if it succeeds, zero otherwise.
454 .BI "bool_t xdr_u_short(XDR *" xdrs ", unsigned short *" usp );
457 A filter primitive that translates between C
458 .I "unsigned short"
459 integers and their external representations.
460 This routine returns one if it succeeds, zero otherwise.
463 .BI "bool_t xdr_union(XDR *" xdrs ", enum_t *" dscmp ", char *" unp ,
464 .BI "                 const struct xdr_discrim *" choices ,
465 .BI "                 xdrproc_t " defaultarm ");     /* may equal NULL */"
468 A filter primitive that translates between a discriminated C
469 .I union
470 and its corresponding external representation.
471 It first
472 translates the discriminant of the union located at
473 .IR dscmp .
474 This discriminant is always an
475 .IR enum_t .
476 Next the union located at
477 .I unp
478 is translated.
479 The argument
480 .I choices
481 is a pointer to an array of
482 .BR xdr_discrim ()
483 structures.
484 Each structure contains an ordered pair of
485 .RI [ value , proc ].
486 If the union's discriminant is equal to the associated
487 .IR value ,
488 then the
489 .I proc
490 is called to translate the union.
491 The end of the
492 .BR xdr_discrim ()
493 structure array is denoted by a routine of value NULL.
494 If the discriminant is not found in the
495 .I choices
496 array, then the
497 .I defaultarm
498 procedure is called (if it is not NULL).
499 Returns one if it succeeds, zero otherwise.
502 .BI "bool_t xdr_vector(XDR *" xdrs ", char *" arrp ", unsigned int " size ,
503 .BI "                  unsigned int " elsize ", xdrproc_t " elproc );
506 A filter primitive that translates between fixed-length arrays
507 and their corresponding external representations.
508 The argument
509 .I arrp
510 is the address of the pointer to the array, while
511 .I size
512 is the element count of the array.
513 The argument
514 .I elsize
515 is the
516 .I sizeof
517 each of the array's elements, and
518 .I elproc
519 is an XDR filter that translates between
520 the array elements' C form, and their external
521 representation.
522 This routine returns one if it succeeds, zero otherwise.
525 .BI "bool_t xdr_void(void);"
528 This routine always returns one.
529 It may be passed to RPC routines that require a function argument,
530 where nothing is to be done.
533 .BI "bool_t xdr_wrapstring(XDR *" xdrs ", char **" sp );
536 A primitive that calls
537 .B "xdr_string(xdrs, sp,MAXUN.UNSIGNED );"
538 where
539 .B MAXUN.UNSIGNED
540 is the maximum value of an unsigned integer.
541 .BR xdr_wrapstring ()
542 is handy because the RPC package passes a maximum of two XDR
543 routines as arguments, and
544 .BR xdr_string (),
545 one of the most frequently used primitives, requires three.
546 Returns one if it succeeds, zero otherwise.
547 .SH ATTRIBUTES
548 For an explanation of the terms used in this section, see
549 .BR attributes (7).
550 .ad l
553 allbox;
554 lbx lb lb
555 l l l.
556 Interface       Attribute       Value
558 .BR xdr_array (),
559 .BR xdr_bool (),
560 .BR xdr_bytes (),
561 .BR xdr_char (),
562 .BR xdr_destroy (),
563 .BR xdr_double (),
564 .BR xdr_enum (),
565 .BR xdr_float (),
566 .BR xdr_free (),
567 .BR xdr_getpos (),
568 .BR xdr_inline (),
569 .BR xdr_int (),
570 .BR xdr_long (),
571 .BR xdrmem_create (),
572 .BR xdr_opaque (),
573 .BR xdr_pointer (),
574 .BR xdrrec_create (),
575 .BR xdrrec_eof (),
576 .BR xdrrec_endofrecord (),
577 .BR xdrrec_skiprecord (),
578 .BR xdr_reference (),
579 .BR xdr_setpos (),
580 .BR xdr_short (),
581 .BR xdrstdio_create (),
582 .BR xdr_string (),
583 .BR xdr_u_char (),
584 .BR xdr_u_int (),
585 .BR xdr_u_long (),
586 .BR xdr_u_short (),
587 .BR xdr_union (),
588 .BR xdr_vector (),
589 .BR xdr_void (),
590 .BR xdr_wrapstring ()
591 T}      Thread safety   MT-Safe
595 .sp 1
596 .SH SEE ALSO
597 .BR rpc (3)
599 The following manuals:
601 eXternal Data Representation Standard: Protocol Specification
603 eXternal Data Representation: Sun Technical Notes
605 .IR "XDR: External Data Representation Standard" ,
606 RFC\ 1014, Sun Microsystems, Inc.,
607 USC-ISI.