Merge branch 'vendor/OPENSSL'
[dragonfly.git] / lib / libc / xdr / xdr.3
1 .\" @(#)xdr.3n  2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI
2 .\" $FreeBSD: src/lib/libc/xdr/xdr.3,v 1.17 2005/11/24 07:12:01 ru Exp $
3 .\" $DragonFly: src/lib/libc/xdr/xdr.3,v 1.3 2007/11/23 23:16:36 swildner Exp $
4 .\"
5 .Dd April 23, 2009
6 .Dt XDR 3
7 .Os
8 .Sh NAME
9 .Nm xdr ,
10 .Nm xdr_array ,
11 .Nm xdr_bool ,
12 .Nm xdr_bytes ,
13 .Nm xdr_char ,
14 .Nm xdr_destroy ,
15 .Nm xdr_double ,
16 .Nm xdr_enum ,
17 .Nm xdr_float ,
18 .Nm xdr_free ,
19 .Nm xdr_getpos ,
20 .Nm xdr_hyper ,
21 .Nm xdr_inline ,
22 .Nm xdr_int ,
23 .Nm xdr_long ,
24 .Nm xdr_longlong_t ,
25 .Nm xdr_int64_t ,
26 .Nm xdrmem_create ,
27 .Nm xdr_opaque ,
28 .Nm xdr_pointer ,
29 .Nm xdrrec_create ,
30 .Nm xdrrec_endofrecord ,
31 .Nm xdrrec_eof ,
32 .Nm xdrrec_skiprecord ,
33 .Nm xdr_reference ,
34 .Nm xdr_setpos ,
35 .Nm xdr_short ,
36 .Nm xdrstdio_create ,
37 .Nm xdr_string ,
38 .Nm xdr_u_char ,
39 .Nm xdr_u_hyper ,
40 .Nm xdr_u_int ,
41 .Nm xdr_u_long ,
42 .Nm xdr_u_longlong_t ,
43 .Nm xdr_u_int64_t ,
44 .Nm xdr_u_short ,
45 .Nm xdr_union ,
46 .Nm xdr_vector ,
47 .Nm xdr_void ,
48 .Nm xdr_wrapstring
49 .Nd "library routines for external data representation"
50 .Sh LIBRARY
51 .Lb libc
52 .Sh SYNOPSIS
53 .In rpc/types.h
54 .In rpc/xdr.h
55 .Pp
56 See
57 .Sx DESCRIPTION
58 for function declarations.
59 .Sh DESCRIPTION
60 These routines allow C programmers to describe
61 arbitrary data structures in a machine-independent fashion.
62 Data for remote procedure calls are transmitted using these
63 routines.
64 .Pp
65 .Bl -tag -width indent -compact
66 .It Xo
67 .Ft int
68 .Xc
69 .It Xo
70 .Fo xdr_array
71 .Fa "XDR *xdrs"
72 .Fa "char **arrp"
73 .Fa "u_int *sizep"
74 .Fa "u_int maxsize"
75 .Fa "u_int elsize"
76 .Fa "xdrproc_t elproc"
77 .Fc
78 .Xc
79 .Pp
80 A filter primitive that translates between variable-length
81 arrays
82 and their corresponding external representations.
83 The
84 .Fa arrp
85 argument
86 is the address of the pointer to the array, while
87 .Fa sizep
88 is the address of the element count of the array;
89 this element count cannot exceed
90 .Fa maxsize .
91 The
92 .Fa elsize
93 argument
94 is the
95 .Ic sizeof
96 each of the array's elements, and
97 .Fa elproc
98 is an
99 .Tn XDR
100 filter that translates between
101 the array elements' C form, and their external
102 representation.
103 This routine returns one if it succeeds, zero otherwise.
104 .Pp
105 .It Xo
106 .Ft int
107 .Xc
108 .It Xo
109 .Fn xdr_bool "XDR *xdrs" "bool_t *bp"
110 .Xc
111 .Pp
112 A filter primitive that translates between booleans (C
113 integers)
114 and their external representations.
115 When encoding data, this
116 filter produces values of either one or zero.
117 This routine returns one if it succeeds, zero otherwise.
118 .Pp
119 .It Xo
120 .Ft int
121 .Xc
122 .It Xo
123 .Fn xdr_bytes "XDR *xdrs" "char **sp" "u_int *sizep" "u_int maxsize"
124 .Xc
125 .Pp
126 A filter primitive that translates between counted byte
127 strings and their external representations.
128 The
129 .Fa sp
130 argument
131 is the address of the string pointer.
132 The length of the
133 string is located at address
134 .Fa sizep ;
135 strings cannot be longer than
136 .Fa maxsize .
137 This routine returns one if it succeeds, zero otherwise.
138 .Pp
139 .It Xo
140 .Ft int
141 .Xc
142 .It Xo
143 .Fn xdr_char "XDR *xdrs" "char *cp"
144 .Xc
145 .Pp
146 A filter primitive that translates between C characters
147 and their external representations.
148 This routine returns one if it succeeds, zero otherwise.
149 Note: encoded characters are not packed, and occupy 4 bytes
150 each.
151 For arrays of characters, it is worthwhile to
152 consider
153 .Fn xdr_bytes ,
154 .Fn xdr_opaque
155 or
156 .Fn xdr_string .
157 .Pp
158 .It Xo
159 .Ft void
160 .Xc
161 .It Xo
162 .Fn xdr_destroy "XDR *xdrs"
163 .Xc
164 .Pp
165 A macro that invokes the destroy routine associated with the
166 .Tn XDR
167 stream,
168 .Fa xdrs .
169 Destruction usually involves freeing private data structures
170 associated with the stream.
171 Using
172 .Fa xdrs
173 after invoking
174 .Fn xdr_destroy
175 is undefined.
176 .Pp
177 .It Xo
178 .Ft int
179 .Xc
180 .It Xo
181 .Fn xdr_double "XDR *xdrs" "double *dp"
182 .Xc
183 .Pp
184 A filter primitive that translates between C
185 .Vt double
186 precision numbers and their external representations.
187 This routine returns one if it succeeds, zero otherwise.
188 .Pp
189 .It Xo
190 .Ft int
191 .Xc
192 .It Xo
193 .Fn xdr_enum "XDR *xdrs" "enum_t *ep"
194 .Xc
195 .Pp
196 A filter primitive that translates between C
197 .Vt enum Ns s
198 (actually integers) and their external representations.
199 This routine returns one if it succeeds, zero otherwise.
200 .Pp
201 .It Xo
202 .Ft int
203 .Xc
204 .It Xo
205 .Fn xdr_float "XDR *xdrs" "float *fp"
206 .Xc
207 .Pp
208 A filter primitive that translates between C
209 .Vt float Ns s
210 and their external representations.
211 This routine returns one if it succeeds, zero otherwise.
212 .Pp
213 .It Xo
214 .Ft void
215 .Xc
216 .It Xo
217 .Fn xdr_free "xdrproc_t proc" "void *objp"
218 .Xc
219 .Pp
220 Generic freeing routine.
221 The first argument is the
222 .Tn XDR
223 routine for the object being freed.
224 The second argument
225 is a pointer to the object itself.
226 Note: the pointer passed
227 to this routine is
228 .Em not
229 freed, but what it points to
230 .Em is
231 freed (recursively).
232 .Pp
233 .It Xo
234 .Ft u_int
235 .Xc
236 .It Xo
237 .Fn xdr_getpos "XDR *xdrs"
238 .Xc
239 .Pp
240 A macro that invokes the get\-position routine
241 associated with the
242 .Tn XDR
243 stream,
244 .Fa xdrs .
245 The routine returns an unsigned integer,
246 which indicates the position of the
247 .Tn XDR
248 byte stream.
249 A desirable feature of
250 .Tn XDR
251 streams is that simple arithmetic works with this number,
252 although the
253 .Tn XDR
254 stream instances need not guarantee this.
255 .Pp
256 .It Xo
257 .Ft int
258 .Xc
259 .It Xo
260 .Fn xdr_hyper "XDR *xdrs" "quad_t *llp"
261 .Xc
262 A filter primitive that translates between ANSI C
263 .Vt "long long"
264 integers and their external representations.
265 This routine returns one if it succeeds, zero otherwise.
266 .Pp
267 .It Xo
268 .Ft "long *"
269 .Xc
270 .It Xo
271 .Fn xdr_inline "XDR *xdrs" "int len"
272 .Xc
273 .Pp
274 A macro that invokes the in-line routine associated with the
275 .Tn XDR
276 stream,
277 .Fa xdrs .
278 The routine returns a pointer
279 to a contiguous piece of the stream's buffer;
280 .Fa len
281 is the byte length of the desired buffer.
282 Note: pointer is cast to
283 .Vt "long *" .
284 .Pp
285 Warning:
286 .Fn xdr_inline
287 may return
288 .Dv NULL
289 (0)
290 if it cannot allocate a contiguous piece of a buffer.
291 Therefore the behavior may vary among stream instances;
292 it exists for the sake of efficiency.
293 .Pp
294 .It Xo
295 .Ft int
296 .Xc
297 .It Xo
298 .Fn xdr_int "XDR *xdrs" "int *ip"
299 .Xc
300 .Pp
301 A filter primitive that translates between C integers
302 and their external representations.
303 This routine returns one if it succeeds, zero otherwise.
304 .Pp
305 .It Xo
306 .Ft int
307 .Xc
308 .It Xo
309 .Fn xdr_long "XDR *xdrs" "long *lp"
310 .Xc
311 .Pp
312 A filter primitive that translates between C
313 .Vt long
314 integers and their external representations.
315 This routine returns one if it succeeds, zero otherwise.
316 .Pp
317 .It Xo
318 .Ft int
319 .Xc
320 .It Xo
321 .Fn xdr_longlong_t "XDR *xdrs" "quad_t *llp"
322 .Xc
323 A filter primitive that translates between ANSI C
324 .Vt "long long"
325 integers and their external representations.
326 This routine returns one if it succeeds, zero otherwise.
327 .Pp
328 .It Xo
329 .Ft int
330 .Xc
331 .It Xo
332 .Fn xdr_int64_t "XDR *xdrs" "int64_t *llp"
333 .Xc
334 A filter primitive that translates between ANSI C
335 .Vt int64_t
336 integers and their external representations.
337 This routine returns one if it succeeds, zero otherwise.
338 .Pp
339 .It Xo
340 .Ft void
341 .Xc
342 .It Xo
343 .Fn xdrmem_create "XDR *xdrs" "char *addr" "u_int size" "enum xdr_op op"
344 .Xc
345 .Pp
346 This routine initializes the
347 .Tn XDR
348 stream object pointed to by
349 .Fa xdrs .
350 The stream's data is written to, or read from,
351 a chunk of memory at location
352 .Fa addr
353 whose length is no more than
354 .Fa size
355 bytes long.
356 The
357 .Fa op
358 argument
359 determines the direction of the
360 .Tn XDR
361 stream
362 (either
363 .Dv XDR_ENCODE ,
364 .Dv XDR_DECODE ,
365 or
366 .Dv XDR_FREE ) .
367 .Pp
368 .It Xo
369 .Ft int
370 .Xc
371 .It Xo
372 .Fn xdr_opaque "XDR *xdrs" "char *cp" "u_int cnt"
373 .Xc
374 .Pp
375 A filter primitive that translates between fixed size opaque
376 data
377 and its external representation.
378 The
379 .Fa cp
380 argument
381 is the address of the opaque object, and
382 .Fa cnt
383 is its size in bytes.
384 This routine returns one if it succeeds, zero otherwise.
385 .Pp
386 .It Xo
387 .Ft int
388 .Xc
389 .It Xo
390 .Fn xdr_pointer "XDR *xdrs" "char **objpp" "u_int objsize" "xdrproc_t xdrobj"
391 .Xc
392 .Pp
393 Like
394 .Fn xdr_reference
395 except that it serializes
396 .Dv NULL
397 pointers, whereas
398 .Fn xdr_reference
399 does not.
400 Thus,
401 .Fn xdr_pointer
402 can represent
403 recursive data structures, such as binary trees or
404 linked lists.
405 .Pp
406 .It Xo
407 .Ft void
408 .Xc
409 .It Xo
410 .Fo xdrrec_create
411 .Fa "XDR *xdrs"
412 .Fa "u_int sendsize"
413 .Fa "u_int recvsize"
414 .Fa "void *handle"
415 .Fa "int \*(lp*readit\*(rp\*(lp\*(rp"
416 .Fa "int \*(lp*writeit\*(rp\*(lp\*(rp"
417 .Fc
418 .Xc
419 .Pp
420 This routine initializes the
421 .Tn XDR
422 stream object pointed to by
423 .Fa xdrs .
424 The stream's data is written to a buffer of size
425 .Fa sendsize ;
426 a value of zero indicates the system should use a suitable
427 default.
428 The stream's data is read from a buffer of size
429 .Fa recvsize ;
430 it too can be set to a suitable default by passing a zero
431 value.
432 When a stream's output buffer is full,
433 .Fn writeit
434 is called.
435 Similarly, when a stream's input buffer is empty,
436 .Fn readit
437 is called.
438 The behavior of these two routines is similar to
439 the
440 system calls
441 .Xr read 2
442 and
443 .Xr write 2 ,
444 except that
445 .Fa handle
446 is passed to the former routines as the first argument.
447 Note: the
448 .Tn XDR
449 stream's
450 .Fa op
451 field must be set by the caller.
452 .Pp
453 Warning: this
454 .Tn XDR
455 stream implements an intermediate record stream.
456 Therefore there are additional bytes in the stream
457 to provide record boundary information.
458 .Pp
459 .It Xo
460 .Ft int
461 .Xc
462 .It Xo
463 .Fn xdrrec_endofrecord "XDR *xdrs" "int sendnow"
464 .Xc
465 .Pp
466 This routine can be invoked only on
467 streams created by
468 .Fn xdrrec_create .
469 The data in the output buffer is marked as a completed
470 record,
471 and the output buffer is optionally written out if
472 .Fa sendnow
473 is non-zero.
474 This routine returns one if it succeeds, zero
475 otherwise.
476 .Pp
477 .It Xo
478 .Ft int
479 .Xc
480 .It Xo
481 .Fn xdrrec_eof "XDR *xdrs"
482 .Xc
483 .Pp
484 This routine can be invoked only on
485 streams created by
486 .Fn xdrrec_create .
487 After consuming the rest of the current record in the stream,
488 this routine returns one if the stream has no more input,
489 zero otherwise.
490 .Pp
491 .It Xo
492 .Ft int
493 .Xc
494 .It Xo
495 .Fn xdrrec_skiprecord "XDR *xdrs"
496 .Xc
497 .Pp
498 This routine can be invoked only on
499 streams created by
500 .Fn xdrrec_create .
501 It tells the
502 .Tn XDR
503 implementation that the rest of the current record
504 in the stream's input buffer should be discarded.
505 This routine returns one if it succeeds, zero otherwise.
506 .Pp
507 .It Xo
508 .Ft int
509 .Xc
510 .It Xo
511 .Fn xdr_reference "XDR *xdrs" "char **pp" "u_int size" "xdrproc_t proc"
512 .Xc
513 .Pp
514 A primitive that provides pointer chasing within structures.
515 The
516 .Fa pp
517 argument
518 is the address of the pointer;
519 .Fa size
520 is the
521 .Ic sizeof
522 the structure that
523 .Fa *pp
524 points to; and
525 .Fa proc
526 is an
527 .Tn XDR
528 procedure that filters the structure
529 between its C form and its external representation.
530 This routine returns one if it succeeds, zero otherwise.
531 .Pp
532 Warning: this routine does not understand
533 .Dv NULL
534 pointers.
535 Use
536 .Fn xdr_pointer
537 instead.
538 .Pp
539 .It Xo
540 .Ft int
541 .Xc
542 .It Xo
543 .Fn xdr_setpos "XDR *xdrs" "u_int pos"
544 .Xc
545 .Pp
546 A macro that invokes the set position routine associated with
547 the
548 .Tn XDR
549 stream
550 .Fa xdrs .
551 The
552 .Fa pos
553 argument
554 is a position value obtained from
555 .Fn xdr_getpos .
556 This routine returns one if the
557 .Tn XDR
558 stream could be repositioned,
559 and zero otherwise.
560 .Pp
561 Warning: it is difficult to reposition some types of
562 .Tn XDR
563 streams, so this routine may fail with one
564 type of stream and succeed with another.
565 .Pp
566 .It Xo
567 .Ft int
568 .Xc
569 .It Xo
570 .Fn xdr_short "XDR *xdrs" "short *sp"
571 .Xc
572 .Pp
573 A filter primitive that translates between C
574 .Vt short
575 integers and their external representations.
576 This routine returns one if it succeeds, zero otherwise.
577 .Pp
578 .It Li "#ifdef _STDIO_H_"
579 .It Li "/* XDR using stdio library */"
580 .It Xo
581 .Ft void
582 .Xc
583 .It Xo
584 .Fn xdrstdio_create "XDR *xdrs" "FILE *file" "enum xdr_op op"
585 .Xc
586 .It Li "#endif"
587 .Pp
588 This routine initializes the
589 .Tn XDR
590 stream object pointed to by
591 .Fa xdrs .
592 The
593 .Tn XDR
594 stream data is written to, or read from, the Standard
595 .Tn I/O
596 stream
597 .Fa file .
598 The
599 .Fa op
600 argument
601 determines the direction of the
602 .Tn XDR
603 stream (either
604 .Dv XDR_ENCODE ,
605 .Dv XDR_DECODE ,
606 or
607 .Dv XDR_FREE ) .
608 .Pp
609 Warning: the destroy routine associated with such
610 .Tn XDR
611 streams calls
612 .Xr fflush 3
613 on the
614 .Fa file
615 stream, but never
616 .Xr fclose 3 .
617 .Pp
618 .It Xo
619 .Ft int
620 .Xc
621 .It Xo
622 .Fn xdr_string "XDR *xdrs" "char **sp" "u_int maxsize"
623 .Xc
624 .Pp
625 A filter primitive that translates between C strings and
626 their
627 corresponding external representations.
628 Strings cannot be longer than
629 .Fa maxsize .
630 Note:
631 .Fa sp
632 is the address of the string's pointer.
633 This routine returns one if it succeeds, zero otherwise.
634 .Pp
635 .It Xo
636 .Ft int
637 .Xc
638 .It Xo
639 .Fn xdr_u_char "XDR *xdrs" "unsigned char *ucp"
640 .Xc
641 .Pp
642 A filter primitive that translates between
643 .Vt unsigned
644 C characters and their external representations.
645 This routine returns one if it succeeds, zero otherwise.
646 .Pp
647 .It Xo
648 .Ft int
649 .Xc
650 .It Xo
651 .Fn xdr_u_hyper "XDR *xdrs" "u_quad_t *ullp"
652 .Xc
653 A filter primitive that translates between
654 .Vt unsigned
655 ANSI C
656 .Vt long long
657 integers and their external representations.
658 This routine returns one if it succeeds, zero otherwise.
659 .Pp
660 .It Xo
661 .Ft int
662 .Xc
663 .It Xo
664 .Fn xdr_u_int "XDR *xdrs" "unsigned *up"
665 .Xc
666 .Pp
667 A filter primitive that translates between C
668 .Vt unsigned
669 integers and their external representations.
670 This routine returns one if it succeeds, zero otherwise.
671 .Pp
672 .It Xo
673 .Ft int
674 .Xc
675 .It Xo
676 .Fn xdr_u_long "XDR *xdrs" "unsigned long *ulp"
677 .Xc
678 .Pp
679 A filter primitive that translates between C
680 .Vt "unsigned long"
681 integers and their external representations.
682 This routine returns one if it succeeds, zero otherwise.
683 .Pp
684 .It Xo
685 .Ft int
686 .Xc
687 .It Xo
688 .Fn xdr_u_longlong_t "XDR *xdrs" "u_quad_t *ullp"
689 .Xc
690 A filter primitive that translates between
691 .Vt unsigned
692 ANSI C
693 .Vt "long long"
694 integers and their external representations.
695 This routine returns one if it succeeds, zero otherwise.
696 .Pp
697 .It Xo
698 .Ft int
699 .Xc
700 .It Xo
701 .Fn xdr_u_int64_t "XDR *xdrs" "u_int64_t *llp"
702 .Xc
703 A filter primitive that translates between C
704 .Vt u_int64_t
705 integers and their external representations.
706 This routine returns one if it succeeds, zero otherwise.
707 .Pp
708 .It Xo
709 .Ft int
710 .Xc
711 .It Xo
712 .Fn xdr_u_short "XDR *xdrs" "unsigned short *usp"
713 .Xc
714 .Pp
715 A filter primitive that translates between C
716 .Vt "unsigned short"
717 integers and their external representations.
718 This routine returns one if it succeeds, zero otherwise.
719 .Pp
720 .It Xo
721 .Ft int
722 .Xc
723 .It Xo
724 .Fo xdr_union
725 .Fa "XDR *xdrs"
726 .Fa "enum_t *dscmp"
727 .Fa "char *unp"
728 .Fa "const struct xdr_discrim *choices"
729 .Fa "xdrproc_t defaultarm"
730 .Fc
731 .Xc
732 .Pp
733 A filter primitive that translates between a discriminated C
734 .Vt union
735 and its corresponding external representation.
736 It first
737 translates the discriminant of the union located at
738 .Fa dscmp .
739 This discriminant is always an
740 .Vt enum_t .
741 Next the union located at
742 .Fa unp
743 is translated.
744 The
745 .Fa choices
746 argument
747 is a pointer to an array of
748 .Vt xdr_discrim
749 structures.
750 Each structure contains an ordered pair of
751 .Bq Va value , proc .
752 If the union's discriminant is equal to the associated
753 .Va value ,
754 then the
755 .Fn proc
756 is called to translate the union.
757 The end of the
758 .Vt xdr_discrim
759 structure array is denoted by a routine of value
760 .Dv NULL .
761 If the discriminant is not found in the
762 .Fa choices
763 array, then the
764 .Fn defaultarm
765 procedure is called (if it is not
766 .Dv NULL ) .
767 Returns one if it succeeds, zero otherwise.
768 .Pp
769 .It Xo
770 .Ft int
771 .Xc
772 .It Xo
773 .Fo xdr_vector
774 .Fa "XDR *xdrs"
775 .Fa "char *arrp"
776 .Fa "u_int size"
777 .Fa "u_int elsize"
778 .Fa "xdrproc_t elproc"
779 .Fc
780 .Xc
781 .Pp
782 A filter primitive that translates between fixed-length
783 arrays
784 and their corresponding external representations.
785 The
786 .Fa arrp
787 argument
788 is the address of the pointer to the array, while
789 .Fa size
790 is the element count of the array.
791 The
792 .Fa elsize
793 argument
794 is the
795 .Ic sizeof
796 each of the array's elements, and
797 .Fa elproc
798 is an
799 .Tn XDR
800 filter that translates between
801 the array elements' C form, and their external
802 representation.
803 This routine returns one if it succeeds, zero otherwise.
804 .Pp
805 .It Xo
806 .Ft int
807 .Xc
808 .It Xo
809 .Fn xdr_void void
810 .Xc
811 .Pp
812 This routine always returns one.
813 It may be passed to
814 .Tn RPC
815 routines that require a function argument,
816 where nothing is to be done.
817 .Pp
818 .It Xo
819 .Ft int
820 .Xc
821 .It Xo
822 .Fn xdr_wrapstring "XDR *xdrs" "char **sp"
823 .Xc
824 .Pp
825 A primitive that calls
826 .Fn xdr_string xdrs sp MAXUN.UNSIGNED ;
827 where
828 .Dv MAXUN.UNSIGNED
829 is the maximum value of an unsigned integer.
830 The
831 .Fn xdr_wrapstring
832 function
833 is handy because the
834 .Tn RPC
835 package passes a maximum of two
836 .Tn XDR
837 routines as arguments, and
838 .Fn xdr_string ,
839 one of the most frequently used primitives, requires three.
840 Returns one if it succeeds, zero otherwise.
841 .El
842 .Sh SEE ALSO
843 .Xr rpc 3
844 .Rs
845 .%T "eXternal Data Representation Standard: Protocol Specification"
846 .Re
847 .Rs
848 .%T "eXternal Data Representation: Sun Technical Notes"
849 .Re
850 .Rs
851 .%T "XDR: External Data Representation Standard"
852 .%O RFC 1014
853 .%Q "Sun Microsystems, Inc., USC\-ISI"
854 .Re