OSDN Git Service

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