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