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