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