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