]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/xdr.3
minor rewording
[thirdparty/man-pages.git] / man3 / xdr.3
CommitLineData
cc3832e9
MK
1.\" This page was taken from the 4.4BSD-Lite CDROM (BSD license)
2.\"
fea681da 3.\" @(#)xdr.3n 2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI
e7c7da90
MK
4.\"
5.\" 2007-12-30, mtk, Convert function prototypes to modern C syntax
6.\"
5b20a7a2 7.TH XDR 3 2007-12-30 "" "Linux Programmer's Manual"
fea681da
MK
8.SH NAME
9xdr \- library routines for external data representation
10.SH "SYNOPSIS AND DESCRIPTION"
11.LP
12These routines allow C programmers to describe
13arbitrary data structures in a machine-independent fashion.
14Data for remote procedure calls are transmitted using these
15routines.
5b20a7a2
MK
16
17The prototypes below are declared in
18.I <rpc/xdr.h>
19and make use of the following types:
20.in +4n
78729a5d 21.nf
5b20a7a2
MK
22
23typedef int \fIbool_t\fP;
24
25typedef bool_t (*\fIxdrproc_t\fP) (XDR *, void *,...);
26.fi
78729a5d 27.in
5b20a7a2
MK
28.LP
29For the declaration of the
30.I XDR
31type, see
32.IR <rpc/xdr.h> .
fea681da 33.LP
fea681da 34.nf
5b20a7a2
MK
35.BI "bool_t xdr_array(XDR *" xdrs ", char **" arrp ", unsigned int *" sizep ,
36.BI " unsigned int " maxsize ", unsigned int " elsize ,
37.BI " xdrproc_t " elproc );
fea681da 38.fi
fea681da 39.IP
5b20a7a2 40A filter primitive that translates between variable-length arrays
c13182ef
MK
41and their corresponding external representations.
42The parameter
fea681da
MK
43.I arrp
44is the address of the pointer to the array, while
45.I sizep
46is the address of the element count of the array;
47this element count cannot exceed
48.IR maxsize .
49The parameter
50.I elsize
51is the
52.I sizeof
53each of the array's elements, and
54.I elproc
5b20a7a2 55is an XDR filter that translates between
fea681da
MK
56the array elements' C form, and their external
57representation.
58This routine returns one if it succeeds, zero otherwise.
fea681da 59.LP
fea681da 60.nf
5b20a7a2 61.BI "bool_t xdr_bool(XDR *" xdrs ", bool_t *" bp );
fea681da 62.fi
fea681da
MK
63.IP
64A filter primitive that translates between booleans (C
65integers)
c13182ef
MK
66and their external representations.
67When encoding data, this
fea681da
MK
68filter produces values of either one or zero.
69This routine returns one if it succeeds, zero otherwise.
fea681da 70.LP
fea681da 71.nf
5b20a7a2
MK
72.BI "bool_t xdr_bytes(XDR *" xdrs ", char **" sp ", unsigned int *" sizep ,
73.BI " unsigned int " maxsize );
fea681da 74.fi
fea681da
MK
75.IP
76A filter primitive that translates between counted byte
77strings and their external representations.
78The parameter
79.I sp
c13182ef
MK
80is the address of the string pointer.
81The length of the
fea681da
MK
82string is located at address
83.IR sizep ;
84strings cannot be longer than
85.IR maxsize .
86This routine returns one if it succeeds, zero otherwise.
fea681da 87.LP
fea681da 88.nf
5b20a7a2 89.BI "bool_t xdr_char(XDR *" xdrs ", char *" cp );
fea681da 90.fi
fea681da
MK
91.IP
92A filter primitive that translates between C characters
93and their external representations.
94This routine returns one if it succeeds, zero otherwise.
c13182ef
MK
95Note: encoded characters are not packed, and occupy 4 bytes each.
96For arrays of characters, it is worthwhile to
fea681da 97consider
63aa9df0
MK
98.BR xdr_bytes (),
99.BR xdr_opaque ()
fea681da 100or
63aa9df0 101.BR xdr_string ().
fea681da 102.LP
fea681da 103.nf
5b20a7a2 104.BI "void xdr_destroy(XDR *" xdrs );
fea681da 105.fi
fea681da 106.IP
5b20a7a2 107A macro that invokes the destroy routine associated with the XDR stream,
fea681da
MK
108.IR xdrs .
109Destruction usually involves freeing private data structures
c13182ef
MK
110associated with the stream.
111Using
fea681da
MK
112.I xdrs
113after invoking
63aa9df0 114.BR xdr_destroy ()
fea681da 115is undefined.
fea681da 116.LP
fea681da 117.nf
5b20a7a2 118.BI "bool_t xdr_double(XDR *" xdrs ", double *" dp );
fea681da 119.fi
fea681da
MK
120.IP
121A filter primitive that translates between C
9ff08aad 122.I double
fea681da
MK
123precision numbers and their external representations.
124This routine returns one if it succeeds, zero otherwise.
fea681da 125.LP
fea681da 126.nf
5b20a7a2 127.BI "bool_t xdr_enum(XDR *" xdrs ", enum_t *" ep );
fea681da 128.fi
fea681da
MK
129.IP
130A filter primitive that translates between C
f19a0f03 131.IR enum s
fea681da
MK
132(actually integers) and their external representations.
133This routine returns one if it succeeds, zero otherwise.
fea681da 134.LP
fea681da 135.nf
5b20a7a2 136.BI "bool_t xdr_float(XDR *" xdrs ", float *" fp );
fea681da 137.fi
fea681da
MK
138.IP
139A filter primitive that translates between C
f19a0f03 140.IR float s
fea681da
MK
141and their external representations.
142This routine returns one if it succeeds, zero otherwise.
fea681da 143.LP
fea681da 144.nf
5b20a7a2 145.BI "void xdr_free(xdrproc_t " proc ", char *" objp );
fea681da 146.fi
fea681da 147.IP
c13182ef 148Generic freeing routine.
5b20a7a2
MK
149The first argument is the XDR routine for the object being freed.
150The second argument is a pointer to the object itself.
151Note: the pointer passed to this routine is
fea681da
MK
152.I not
153freed, but what it points to
154.I is
155freed (recursively).
fea681da 156.LP
fea681da 157.nf
5b20a7a2 158.BI "unsigned int xdr_getpos(XDR *" xdrs );
fea681da 159.fi
fea681da
MK
160.IP
161A macro that invokes the get-position routine
5b20a7a2 162associated with the XDR stream,
fea681da
MK
163.IR xdrs .
164The routine returns an unsigned integer,
5b20a7a2
MK
165which indicates the position of the XDR byte stream.
166A desirable feature of XDR
fea681da 167streams is that simple arithmetic works with this number,
5b20a7a2 168although the XDR stream instances need not guarantee this.
fea681da 169.LP
fea681da 170.nf
5b20a7a2 171.BI "long *xdr_inline(XDR *" xdrs ", int " len );
fea681da 172.fi
fea681da 173.IP
5b20a7a2 174A macro that invokes the in-line routine associated with the XDR stream,
fea681da
MK
175.IR xdrs .
176The routine returns a pointer
177to a contiguous piece of the stream's buffer;
178.I len
179is the byte length of the desired buffer.
180Note: pointer is cast to
9ff08aad 181.IR "long *" .
fea681da
MK
182.IP
183Warning:
63aa9df0 184.BR xdr_inline ()
5b20a7a2 185may return NULL (0)
fea681da
MK
186if it cannot allocate a contiguous piece of a buffer.
187Therefore the behavior may vary among stream instances;
188it exists for the sake of efficiency.
fea681da 189.LP
fea681da 190.nf
5b20a7a2 191.BI "bool_t xdr_int(XDR *" xdrs ", int *" ip );
fea681da 192.fi
fea681da
MK
193.IP
194A filter primitive that translates between C integers
195and their external representations.
196This routine returns one if it succeeds, zero otherwise.
fea681da 197.LP
fea681da 198.nf
5b20a7a2 199.BI "bool_t xdr_long(XDR *" xdrs ", long *" lp );
fea681da 200.fi
fea681da
MK
201.IP
202A filter primitive that translates between C
9ff08aad 203.I long
fea681da
MK
204integers and their external representations.
205This routine returns one if it succeeds, zero otherwise.
fea681da 206.LP
fea681da 207.nf
5b20a7a2
MK
208.BI "void xdrmem_create(XDR *" xdrs ", char *" addr ", unsigned int " size ,
209.BI " enum xdr_op " op );
fea681da 210.fi
fea681da 211.IP
5b20a7a2 212This routine initializes the XDR stream object pointed to by
fea681da
MK
213.IR xdrs .
214The stream's data is written to, or read from,
215a chunk of memory at location
216.I addr
217whose length is no more than
218.I size
c13182ef
MK
219bytes long.
220The
fea681da 221.I op
5b20a7a2 222determines the direction of the XDR stream (either
066cb3d6
MK
223.BR XDR_ENCODE ,
224.BR XDR_DECODE ,
fea681da 225or
066cb3d6 226.BR XDR_FREE ).
fea681da 227.LP
fea681da 228.nf
5b20a7a2 229.BI "bool_t xdr_opaque(XDR *" xdrs ", char *" cp ", unsigned int " cnt );
fea681da 230.fi
fea681da
MK
231.IP
232A filter primitive that translates between fixed size opaque data
233and its external representation.
234The parameter
235.I cp
236is the address of the opaque object, and
237.I cnt
238is its size in bytes.
239This routine returns one if it succeeds, zero otherwise.
fea681da 240.LP
fea681da 241.nf
5b20a7a2
MK
242.BI "bool_t xdr_pointer(XDR *" xdrs ", char **" objpp ,
243.BI " unsigned int " objsize ", xdrproc_t " xdrobj );
fea681da 244.fi
fea681da
MK
245.IP
246Like
63aa9df0 247.BR xdr_reference ()
5b20a7a2 248except that it serializes NULL pointers, whereas
63aa9df0 249.BR xdr_reference ()
c13182ef
MK
250does not.
251Thus,
63aa9df0 252.BR xdr_pointer ()
fea681da
MK
253can represent
254recursive data structures, such as binary trees or
255linked lists.
fea681da 256.LP
fea681da 257.nf
5b20a7a2
MK
258.BI "void xdrrec_create(XDR *" xdrs ", unsigned int " sendsize ,
259.BI " unsigned int " recvsize ", char *" handle ,
260.BI " int (*" readit ") (char *, char *, int),"
261.BI " int (*" writeit ") (char *, char *, int));"
fea681da 262.fi
fea681da 263.IP
5b20a7a2 264This routine initializes the XDR stream object pointed to by
fea681da
MK
265.IR xdrs .
266The stream's data is written to a buffer of size
267.IR sendsize ;
5b20a7a2 268a value of zero indicates the system should use a suitable default.
c13182ef 269The stream's data is read from a buffer of size
fea681da 270.IR recvsize ;
5b20a7a2 271it too can be set to a suitable default by passing a zero value.
fea681da
MK
272When a stream's output buffer is full,
273.I writeit
c13182ef
MK
274is called.
275Similarly, when a stream's input buffer is empty,
fea681da 276.I readit
c13182ef
MK
277is called.
278The behavior of these two routines is similar to
fb186734
MK
279the system calls
280.BR read (2)
fea681da 281and
fb186734 282.BR write (2),
fea681da
MK
283except that
284.I handle
285is passed to the former routines as the first parameter.
5b20a7a2 286Note: the XDR stream's
fea681da
MK
287.I op
288field must be set by the caller.
289.IP
5b20a7a2 290Warning: this XDR stream implements an intermediate record stream.
fea681da
MK
291Therefore there are additional bytes in the stream
292to provide record boundary information.
fea681da 293.LP
fea681da 294.nf
5b20a7a2 295.BI "bool_t xdrrec_endofrecord(XDR *" xdrs ", int " sendnow );
fea681da 296.fi
fea681da 297.IP
5b20a7a2 298This routine can be invoked only on streams created by
63aa9df0 299.BR xdrrec_create ().
5b20a7a2 300The data in the output buffer is marked as a completed record,
fea681da
MK
301and the output buffer is optionally written out if
302.I sendnow
eba72288 303is non-zero.
c13182ef 304This routine returns one if it succeeds, zero otherwise.
fea681da 305.LP
fea681da 306.nf
5b20a7a2 307.BI "bool_t xdrrec_eof(XDR *" xdrs );
fea681da 308.fi
fea681da 309.IP
5b20a7a2 310This routine can be invoked only on streams created by
63aa9df0 311.BR xdrrec_create ().
fea681da
MK
312After consuming the rest of the current record in the stream,
313this routine returns one if the stream has no more input,
314zero otherwise.
fea681da 315.LP
fea681da 316.nf
5b20a7a2 317.BI "bool_t xdrrec_skiprecord(XDR *" xdrs );
fea681da 318.fi
fea681da
MK
319.IP
320This routine can be invoked only on
321streams created by
63aa9df0 322.BR xdrrec_create ().
5b20a7a2 323It tells the XDR implementation that the rest of the current record
fea681da
MK
324in the stream's input buffer should be discarded.
325This routine returns one if it succeeds, zero otherwise.
fea681da 326.LP
fea681da 327.nf
5b20a7a2
MK
328.BI "bool_t xdr_reference(XDR *" xdrs ", char **" pp ", unsigned int " size ,
329.BI " xdrproc_t " proc );
fea681da 330.fi
fea681da
MK
331.IP
332A primitive that provides pointer chasing within structures.
333The parameter
334.I pp
335is the address of the pointer;
336.I size
337is the
338.I sizeof
339the structure that
340.I *pp
341points to; and
342.I proc
5b20a7a2 343is an XDR procedure that filters the structure
fea681da
MK
344between its C form and its external representation.
345This routine returns one if it succeeds, zero otherwise.
346.IP
5b20a7a2 347Warning: this routine does not understand NULL pointers.
c13182ef 348Use
63aa9df0 349.BR xdr_pointer ()
fea681da 350instead.
fea681da 351.LP
fea681da 352.nf
5b20a7a2 353.BI "xdr_setpos(XDR *" xdrs ", unsigned int " pos );
fea681da 354.fi
fea681da
MK
355.IP
356A macro that invokes the set position routine associated with
5b20a7a2 357the XDR stream
fea681da
MK
358.IR xdrs .
359The parameter
360.I pos
361is a position value obtained from
63aa9df0 362.BR xdr_getpos ().
5b20a7a2 363This routine returns one if the XDR stream could be repositioned,
fea681da
MK
364and zero otherwise.
365.IP
5b20a7a2 366Warning: it is difficult to reposition some types of XDR
fea681da
MK
367streams, so this routine may fail with one
368type of stream and succeed with another.
fea681da 369.LP
fea681da 370.nf
5b20a7a2 371.BI "bool_t xdr_short(XDR *" xdrs ", short *" sp );
fea681da 372.fi
fea681da
MK
373.IP
374A filter primitive that translates between C
f19a0f03 375.I short
fea681da
MK
376integers and their external representations.
377This routine returns one if it succeeds, zero otherwise.
fea681da 378.LP
fea681da 379.nf
5b20a7a2 380.BI "void xdrstdio_create(XDR *" xdrs ", FILE *" file ", enum xdr_op " op );
fea681da 381.fi
fea681da 382.IP
5b20a7a2 383This routine initializes the XDR stream object pointed to by
fea681da 384.IR xdrs .
5b20a7a2 385The XDR stream data is written to, or read from, the
eee0a2ec 386.I stdio
fea681da
MK
387stream
388.IR file .
389The parameter
390.I op
5b20a7a2 391determines the direction of the XDR stream (either
066cb3d6
MK
392.BR XDR_ENCODE ,
393.BR XDR_DECODE ,
fea681da 394or
066cb3d6 395.BR XDR_FREE ).
fea681da 396.IP
5b20a7a2 397Warning: the destroy routine associated with such XDR streams calls
fb186734 398.BR fflush (3)
fea681da
MK
399on the
400.I file
401stream, but never
fb186734 402.BR fclose (3).
fea681da 403.LP
fea681da 404.nf
5b20a7a2 405.BI "bool_t xdr_string(XDR *" xdrs ", char **" sp ", unsigned int " maxsize );
fea681da 406.fi
fea681da
MK
407.IP
408A filter primitive that translates between C strings and
5b20a7a2 409their corresponding external representations.
fea681da
MK
410Strings cannot be longer than
411.IR maxsize .
c13182ef 412Note:
fea681da
MK
413.I sp
414is the address of the string's pointer.
415This routine returns one if it succeeds, zero otherwise.
fea681da 416.LP
fea681da 417.nf
5b20a7a2 418.BI "bool_t xdr_u_char(XDR *" xdrs ", unsigned char *" ucp );
fea681da 419.fi
fea681da
MK
420.IP
421A filter primitive that translates between
9ff08aad 422.I unsigned
fea681da
MK
423C characters and their external representations.
424This routine returns one if it succeeds, zero otherwise.
fea681da 425.LP
fea681da 426.nf
5b20a7a2 427.BI "bool_t xdr_u_int(XDR *" xdrs ", unsigned *" up );
fea681da 428.fi
fea681da
MK
429.IP
430A filter primitive that translates between C
9ff08aad 431.I unsigned
fea681da
MK
432integers and their external representations.
433This routine returns one if it succeeds, zero otherwise.
fea681da 434.LP
fea681da 435.nf
5b20a7a2 436.BI "bool_t xdr_u_long(XDR *" xdrs ", unsigned long *" ulp );
fea681da 437.fi
fea681da
MK
438.IP
439A filter primitive that translates between C
9ff08aad 440.I "unsigned long"
fea681da
MK
441integers and their external representations.
442This routine returns one if it succeeds, zero otherwise.
fea681da 443.LP
fea681da 444.nf
5b20a7a2 445.BI "bool_t xdr_u_short(XDR *" xdrs ", unsigned short *" usp );
fea681da 446.fi
fea681da
MK
447.IP
448A filter primitive that translates between C
9ff08aad 449.I "unsigned short"
fea681da
MK
450integers and their external representations.
451This routine returns one if it succeeds, zero otherwise.
fea681da 452.LP
fea681da 453.nf
5b20a7a2
MK
454.BI "bool_t xdr_union(XDR *" xdrs ", int *" dscmp ", char *" unp ,
455.BI " struct xdr_discrim *" choices ,
456.BI " xdrproc_t " defaultarm "); /* may equal NULL */"
fea681da 457.fi
fea681da
MK
458.IP
459A filter primitive that translates between a discriminated C
f19a0f03 460.I union
c13182ef
MK
461and its corresponding external representation.
462It first
fea681da
MK
463translates the discriminant of the union located at
464.IR dscmp .
465This discriminant is always an
f19a0f03 466.IR enum_t .
fea681da
MK
467Next the union located at
468.I unp
c13182ef
MK
469is translated.
470The parameter
fea681da
MK
471.I choices
472is a pointer to an array of
63aa9df0 473.BR xdr_discrim ()
c13182ef
MK
474structures.
475Each structure contains an ordered pair of
fea681da
MK
476.RI [ value , proc ].
477If the union's discriminant is equal to the associated
478.IR value ,
479then the
480.I proc
c13182ef
MK
481is called to translate the union.
482The end of the
63aa9df0 483.BR xdr_discrim ()
5b20a7a2 484structure array is denoted by a routine of value NULL.
fea681da
MK
485If the discriminant is not found in the
486.I choices
487array, then the
488.I defaultarm
5b20a7a2 489procedure is called (if it is not NULL).
fea681da 490Returns one if it succeeds, zero otherwise.
fea681da 491.LP
fea681da 492.nf
5b20a7a2
MK
493.BI "bool_t xdr_vector(XDR *" xdrs ", char *" arrp ", unsigned int " size ,
494.BI " unsigned int " elsize ", xdrproc_t " elproc );
fea681da 495.fi
fea681da 496.IP
5b20a7a2 497A filter primitive that translates between fixed-length arrays
c13182ef
MK
498and their corresponding external representations.
499The parameter
fea681da
MK
500.I arrp
501is the address of the pointer to the array, while
502.I size
c3c1773e 503is the element count of the array.
c13182ef 504The parameter
fea681da
MK
505.I elsize
506is the
507.I sizeof
508each of the array's elements, and
509.I elproc
5b20a7a2 510is an XDR filter that translates between
fea681da
MK
511the array elements' C form, and their external
512representation.
513This routine returns one if it succeeds, zero otherwise.
fea681da 514.LP
fea681da 515.nf
5b20a7a2 516.BI "bool_t xdr_void(void);"
fea681da 517.fi
fea681da
MK
518.IP
519This routine always returns one.
5b20a7a2 520It may be passed to RPC routines that require a function parameter,
fea681da 521where nothing is to be done.
fea681da 522.LP
fea681da 523.nf
5b20a7a2 524.BI "bool_t xdr_wrapstring(XDR *" xdrs ", char **" sp );
fea681da 525.fi
fea681da
MK
526.IP
527A primitive that calls
066cb3d6 528.B "xdr_string(xdrs, sp,MAXUN.UNSIGNED );"
fea681da 529where
d2d293ba 530.B MAXUN.UNSIGNED
fea681da 531is the maximum value of an unsigned integer.
63aa9df0 532.BR xdr_wrapstring ()
5b20a7a2 533is handy because the RPC package passes a maximum of two XDR
fea681da 534routines as parameters, and
63aa9df0 535.BR xdr_string (),
fea681da
MK
536one of the most frequently used primitives, requires three.
537Returns one if it succeeds, zero otherwise.
538.SH "SEE ALSO"
539.BR rpc (3)
540.LP
541The following manuals:
542.RS
fea681da
MK
543eXternal Data Representation Standard: Protocol Specification
544.br
545eXternal Data Representation: Sun Technical Notes
fea681da 546.br
066cb3d6 547.IR "XDR: External Data Representation Standard" ,
d2d293ba
MK
548RFC\ 1014, Sun Microsystems, Inc.,
549USC-ISI.
5d78bcdd 550.RE