BSD 4_3_Net_2 release
[unix-history] / usr / src / lib / librpc / man / man3 / xdr.3n
CommitLineData
af359dea
C
1.\" @(#)xdr.3n 2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI
2.TH XDR 3N "16 February 1988"
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
103.BR xdr_bytes(\|) ,
104.B xdr_opaque(\|)
105or
106.BR xdr_string(\|) .
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
127.B xdr_destroy(\|)
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
142.B double
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
249.BR "long *" .
250.IP
251Warning:
252.B xdr_inline(\|)
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
287.B long
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
338data
339and its external representation.
340The parameter
341.I cp
342is the address of the opaque object, and
343.I cnt
344is its size in bytes.
345This routine returns one if it succeeds, zero otherwise.
346.br
347.if t .ne 10
348.LP
349.ft B
350.nf
351.sp .5
352xdr_pointer(xdrs, objpp, objsize, xdrobj)
353\s-1XDR\s0 *xdrs;
354char **objpp;
355u_int objsize;
356xdrproc_t xdrobj;
357.fi
358.ft R
359.IP
360Like
361.B xdr_reference(\|)
362execpt that it serializes
363.SM NULL
364pointers, whereas
365.B xdr_reference(\|)
366does not. Thus,
367.B xdr_pointer(\|)
368can represent
369recursive data structures, such as binary trees or
370linked lists.
371.br
372.if t .ne 15
373.LP
374.ft B
375.nf
376.sp .5
377void
378xdrrec_create(xdrs, sendsize, recvsize, handle, readit, writeit)
379\s-1XDR\s0 *xdrs;
380u_int sendsize, recvsize;
381char *handle;
382int (*readit) (\|), (*writeit) (\|);
383.fi
384.ft R
385.IP
386This routine initializes the
387.SM XDR
388stream object pointed to by
389.IR xdrs .
390The stream's data is written to a buffer of size
391.IR sendsize ;
392a value of zero indicates the system should use a suitable
393default. The stream's data is read from a buffer of size
394.IR recvsize ;
395it too can be set to a suitable default by passing a zero
396value.
397When a stream's output buffer is full,
398.I writeit
399is called. Similarly, when a stream's input buffer is empty,
400.I readit
401is called. The behavior of these two routines is similar to
402the
403system calls
404.B read
405and
406.BR write ,
407except that
408.I handle
409is passed to the former routines as the first parameter.
410Note: the
411.SM XDR
412stream's
413.I op
414field must be set by the caller.
415.IP
416Warning: this
417.SM XDR
418stream implements an intermediate record stream.
419Therefore there are additional bytes in the stream
420to provide record boundary information.
421.br
422.if t .ne 9
423.LP
424.ft B
425.nf
426.sp .5
427xdrrec_endofrecord(xdrs, sendnow)
428\s-1XDR\s0 *xdrs;
429int sendnow;
430.fi
431.ft R
432.IP
433This routine can be invoked only on
434streams created by
435.BR xdrrec_create(\|) .
436The data in the output buffer is marked as a completed
437record,
438and the output buffer is optionally written out if
439.I sendnow
440is non-zero. This routine returns one if it succeeds, zero
441otherwise.
442.br
443.if t .ne 8
444.LP
445.ft B
446.nf
447.sp .5
448xdrrec_eof(xdrs)
449\s-1XDR\s0 *xdrs;
450int empty;
451.fi
452.ft R
453.IP
454This routine can be invoked only on
455streams created by
456.BR xdrrec_create(\|) .
457After consuming the rest of the current record in the stream,
458this routine returns one if the stream has no more input,
459zero otherwise.
460.br
461.if t .ne 3
462.LP
463.ft B
464.nf
465.sp .5
466xdrrec_skiprecord(xdrs)
467\s-1XDR\s0 *xdrs;
468.fi
469.ft R
470.IP
471This routine can be invoked only on
472streams created by
473.BR xdrrec_create(\|) .
474It tells the
475.SM XDR
476implementation that the rest of the current record
477in the stream's input buffer should be discarded.
478This routine returns one if it succeeds, zero otherwise.
479.br
480.if t .ne 11
481.LP
482.ft B
483.nf
484.sp .5
485xdr_reference(xdrs, pp, size, proc)
486\s-1XDR\s0 *xdrs;
487char **pp;
488u_int size;
489xdrproc_t proc;
490.fi
491.ft R
492.IP
493A primitive that provides pointer chasing within structures.
494The parameter
495.I pp
496is the address of the pointer;
497.I size
498is the
499.I sizeof
500the structure that
501.I *pp
502points to; and
503.I proc
504is an
505.SM XDR
506procedure that filters the structure
507between its C form and its external representation.
508This routine returns one if it succeeds, zero otherwise.
509.IP
510Warning: this routine does not understand
511.SM NULL
512pointers. Use
513.B xdr_pointer(\|)
514instead.
515.br
516.if t .ne 10
517.LP
518.ft B
519.nf
520.sp .5
521xdr_setpos(xdrs, pos)
522\s-1XDR\s0 *xdrs;
523u_int pos;
524.fi
525.ft R
526.IP
527A macro that invokes the set position routine associated with
528the
529.SM XDR
530stream
531.IR xdrs .
532The parameter
533.I pos
534is a position value obtained from
535.BR xdr_getpos(\|) .
536This routine returns one if the
537.SM XDR
538stream could be repositioned,
539and zero otherwise.
540.IP
541Warning: it is difficult to reposition some types of
542.SM XDR
543streams, so this routine may fail with one
544type of stream and succeed with another.
545.br
546.if t .ne 8
547.LP
548.ft B
549.nf
550.sp .5
551xdr_short(xdrs, sp)
552\s-1XDR\s0 *xdrs;
553short *sp;
554.fi
555.ft R
556.IP
557A filter primitive that translates between C
558.B short
559integers and their external representations.
560This routine returns one if it succeeds, zero otherwise.
561.br
562.if t .ne 10
563.LP
564.ft B
565.nf
566.sp .5
567void
568xdrstdio_create(xdrs, file, op)
569\s-1XDR\s0 *xdrs;
570\s-1FILE\s0 *file;
571enum xdr_op op;
572.fi
573.ft R
574.IP
575This routine initializes the
576.SM XDR
577stream object pointed to by
578.IR xdrs .
579The
580.SM XDR
581stream data is written to, or read from, the Standard
582.B I/O
583stream
584.IR file .
585The parameter
586.I op
587determines the direction of the
588.SM XDR
589stream (either
590.BR \s-1XDR_ENCODE\s0 ,
591.BR \s-1XDR_DECODE\s0 ,
592or
593.BR \s-1XDR_FREE\s0 ).
594.IP
595Warning: the destroy routine associated with such
596.SM XDR
597streams calls
598.B fflush(\|)
599on the
600.I file
601stream, but never
602.BR fclose(\|) .
603.br
604.if t .ne 9
605.LP
606.ft B
607.nf
608.sp .5
609xdr_string(xdrs, sp, maxsize)
610\s-1XDR\s0
611*xdrs;
612char **sp;
613u_int maxsize;
614.fi
615.ft R
616.IP
617A filter primitive that translates between C strings and
618their
619corresponding external representations.
620Strings cannot be longer than
621.IR maxsize .
622Note:
623.I sp
624is the address of the string's pointer.
625This routine returns one if it succeeds, zero otherwise.
626.br
627.if t .ne 8
628.LP
629.ft B
630.nf
631.sp .5
632xdr_u_char(xdrs, ucp)
633\s-1XDR\s0 *xdrs;
634unsigned char *ucp;
635.fi
636.ft R
637.IP
638A filter primitive that translates between
639.B unsigned
640C characters and their external representations.
641This routine returns one if it succeeds, zero otherwise.
642.br
643.if t .ne 9
644.LP
645.ft B
646.nf
647.sp .5
648xdr_u_int(xdrs, up)
649\s-1XDR\s0 *xdrs;
650unsigned *up;
651.fi
652.ft R
653.IP
654A filter primitive that translates between C
655.B unsigned
656integers and their external representations.
657This routine returns one if it succeeds, zero otherwise.
658.br
659.if t .ne 7
660.LP
661.ft B
662.nf
663.sp .5
664xdr_u_long(xdrs, ulp)
665\s-1XDR\s0 *xdrs;
666unsigned long *ulp;
667.fi
668.ft R
669.IP
670A filter primitive that translates between C
671.B "unsigned long"
672integers and their external representations.
673This routine returns one if it succeeds, zero otherwise.
674.br
675.if t .ne 7
676.LP
677.ft B
678.nf
679.sp .5
680xdr_u_short(xdrs, usp)
681\s-1XDR\s0 *xdrs;
682unsigned short *usp;
683.fi
684.ft R
685.IP
686A filter primitive that translates between C
687.B "unsigned short"
688integers and their external representations.
689This routine returns one if it succeeds, zero otherwise.
690.br
691.if t .ne 16
692.LP
693.ft B
694.nf
695.sp .5
696xdr_union(xdrs, dscmp, unp, choices, dfault)
697\s-1XDR\s0 *xdrs;
698int *dscmp;
699char *unp;
700struct xdr_discrim *choices;
701bool_t (*defaultarm) (\|); /* may equal \s-1NULL\s0 */
702.fi
703.ft R
704.IP
705A filter primitive that translates between a discriminated C
706.B union
707and its corresponding external representation. It first
708translates the discriminant of the union located at
709.IR dscmp .
710This discriminant is always an
711.BR enum_t .
712Next the union located at
713.I unp
714is translated. The parameter
715.I choices
716is a pointer to an array of
717.B xdr_discrim(\|)
718structures. Each structure contains an ordered pair of
719.RI [ value , proc ].
720If the union's discriminant is equal to the associated
721.IR value ,
722then the
723.I proc
724is called to translate the union. The end of the
725.B xdr_discrim(\|)
726structure array is denoted by a routine of value
727.SM NULL\s0.
728If the discriminant is not found in the
729.I choices
730array, then the
731.I defaultarm
732procedure is called (if it is not
733.SM NULL\s0).
734Returns one if it succeeds, zero otherwise.
735.br
736.if t .ne 6
737.LP
738.ft B
739.nf
740.sp .5
741xdr_vector(xdrs, arrp, size, elsize, elproc)
742\s-1XDR\s0 *xdrs;
743char *arrp;
744u_int size, elsize;
745xdrproc_t elproc;
746.fi
747.ft R
748.IP
749A filter primitive that translates between fixed-length
750arrays
751and their corresponding external representations. The
752parameter
753.I arrp
754is the address of the pointer to the array, while
755.I size
756is is the element count of the array. The parameter
757.I elsize
758is the
759.I sizeof
760each of the array's elements, and
761.I elproc
762is an
763.SM XDR
764filter that translates between
765the array elements' C form, and their external
766representation.
767This routine returns one if it succeeds, zero otherwise.
768.br
769.if t .ne 5
770.LP
771.ft B
772.nf
773.sp .5
774xdr_void(\|)
775.fi
776.ft R
777.IP
778This routine always returns one.
779It may be passed to
780.SM RPC
781routines that require a function parameter,
782where nothing is to be done.
783.br
784.if t .ne 10
785.LP
786.ft B
787.nf
788.sp .5
789xdr_wrapstring(xdrs, sp)
790\s-1XDR\s0 *xdrs;
791char **sp;
792.fi
793.ft R
794.IP
795A primitive that calls
796.B "xdr_string(xdrs, sp,\s-1MAXUN.UNSIGNED\s0 );"
797where
798.B
799.SM MAXUN.UNSIGNED
800is the maximum value of an unsigned integer.
801.B xdr_wrapstring(\|)
802is handy because the
803.SM RPC
804package passes a maximum of two
805.SM XDR
806routines as parameters, and
807.BR xdr_string(\|) ,
808one of the most frequently used primitives, requires three.
809Returns one if it succeeds, zero otherwise.
810.SH SEE ALSO
811.BR rpc (3N)
812.LP
813The following manuals:
814.RS
815.ft I
816eXternal Data Representation Standard: Protocol Specification
817.br
818eXternal Data Representation: Sun Technical Notes
819.ft R
820.br
821.IR "\s-1XDR\s0: External Data Representation Standard" ,
822.SM RFC1014, Sun Microsystems, Inc.,
823.SM USC-ISI\s0.