1XDR(3)                     Linux Programmer's Manual                    XDR(3)
2
3
4

NAME

6       xdr - library routines for external data representation
7

SYNOPSIS AND DESCRIPTION

9       These  routines  allow  C programmers to describe arbitrary data struc‐
10       tures in a machine-independent  fashion.   Data  for  remote  procedure
11       calls are transmitted using these routines.
12
13       The  prototypes  below  are declared in <rpc/xdr.h> and make use of the
14       following types:
15
16           typedef int bool_t;
17
18           typedef bool_t (*xdrproc_t) (XDR *, void *,...);
19
20       For the declaration of the XDR type, see <rpc/xdr.h>.
21
22       bool_t xdr_array(XDR *xdrs, char **arrp, unsigned int *sizep,
23                        unsigned int maxsize, unsigned int elsize,
24                        xdrproc_t elproc);
25
26              A  filter  primitive  that  translates  between  variable-length
27              arrays  and  their  corresponding external representations.  The
28              argument arrp is the address of the pointer to the array,  while
29              sizep  is  the  address  of the element count of the array; this
30              element count cannot exceed maxsize.  The argument elsize is the
31              sizeof each of the array's elements, and elproc is an XDR filter
32              that translates between the array elements' C  form,  and  their
33              external  representation.   This  routine returns one if it suc‐
34              ceeds, zero otherwise.
35
36       bool_t xdr_bool(XDR *xdrs, bool_t *bp);
37
38              A filter primitive that translates between booleans (C integers)
39              and  their  external  representations.  When encoding data, this
40              filter produces values of either  one  or  zero.   This  routine
41              returns one if it succeeds, zero otherwise.
42
43       bool_t xdr_bytes(XDR *xdrs, char **sp, unsigned int *sizep,
44                        unsigned int maxsize);
45
46              A  filter primitive that translates between counted byte strings
47              and their external representations.   The  argument  sp  is  the
48              address  of  the  string  pointer.   The length of the string is
49              located at address sizep; strings cannot be longer than maxsize.
50              This routine returns one if it succeeds, zero otherwise.
51
52       bool_t xdr_char(XDR *xdrs, char *cp);
53
54              A  filter  primitive  that  translates  between C characters and
55              their external representations.  This routine returns one if  it
56              succeeds,  zero  otherwise.   Note:  encoded  characters are not
57              packed, and occupy 4 bytes each.  For arrays of  characters,  it
58              is   worthwhile   to   consider   xdr_bytes(),  xdr_opaque()  or
59              xdr_string().
60
61       void xdr_destroy(XDR *xdrs);
62
63              A macro that invokes the destroy routine associated with the XDR
64              stream, xdrs.  Destruction usually involves freeing private data
65              structures associated with the stream.  Using xdrs after  invok‐
66              ing xdr_destroy() is undefined.
67
68       bool_t xdr_double(XDR *xdrs, double *dp);
69
70              A  filter  primitive  that translates between C double precision
71              numbers  and  their  external  representations.   This   routine
72              returns one if it succeeds, zero otherwise.
73
74       bool_t xdr_enum(XDR *xdrs, enum_t *ep);
75
76              A  filter  primitive  that  translates between C enums (actually
77              integers) and  their  external  representations.   This  routine
78              returns one if it succeeds, zero otherwise.
79
80       bool_t xdr_float(XDR *xdrs, float *fp);
81
82              A  filter  primitive  that translates between C floats and their
83              external representations.  This routine returns one if  it  suc‐
84              ceeds, zero otherwise.
85
86       void xdr_free(xdrproc_t proc, char *objp);
87
88              Generic  freeing routine.  The first argument is the XDR routine
89              for the object being freed.  The second argument is a pointer to
90              the  object itself.  Note: the pointer passed to this routine is
91              not freed, but what it points to is freed (recursively).
92
93       unsigned int xdr_getpos(XDR *xdrs);
94
95              A macro that invokes the get-position  routine  associated  with
96              the  XDR stream, xdrs.  The routine returns an unsigned integer,
97              which indicates the position of the XDR byte stream.   A  desir‐
98              able feature of XDR streams is that simple arithmetic works with
99              this number, although the XDR stream instances need not  guaran‐
100              tee this.
101
102       long *xdr_inline(XDR *xdrs, int len);
103
104              A  macro that invokes the inline routine associated with the XDR
105              stream, xdrs.  The routine returns a  pointer  to  a  contiguous
106              piece  of  the  stream's  buffer;  len is the byte length of the
107              desired buffer.  Note: pointer is cast to long *.
108
109              Warning: xdr_inline() may return NULL (0) if it cannot  allocate
110              a contiguous piece of a buffer.  Therefore the behavior may vary
111              among stream instances; it exists for the sake of efficiency.
112
113       bool_t xdr_int(XDR *xdrs, int *ip);
114
115              A filter primitive that translates between C integers and  their
116              external  representations.   This routine returns one if it suc‐
117              ceeds, zero otherwise.
118
119       bool_t xdr_long(XDR *xdrs, long *lp);
120
121              A filter primitive that translates between C long  integers  and
122              their  external representations.  This routine returns one if it
123              succeeds, zero otherwise.
124
125       void xdrmem_create(XDR *xdrs, char *addr, unsigned int size,
126                          enum xdr_op op);
127
128              This routine initializes the XDR stream  object  pointed  to  by
129              xdrs.  The stream's data is written to, or read from, a chunk of
130              memory at location addr whose length is no more than size  bytes
131              long.  The op determines the direction of the XDR stream (either
132              XDR_ENCODE, XDR_DECODE, or XDR_FREE).
133
134       bool_t xdr_opaque(XDR *xdrs, char *cp, unsigned int cnt);
135
136              A filter primitive that translates  between  fixed  size  opaque
137              data  and  its  external representation.  The argument cp is the
138              address of the opaque object, and cnt  is  its  size  in  bytes.
139              This routine returns one if it succeeds, zero otherwise.
140
141       bool_t xdr_pointer(XDR *xdrs, char **objpp,
142                          unsigned int objsize, xdrproc_t xdrobj);
143
144              Like  xdr_reference()  except  that it serializes NULL pointers,
145              whereas xdr_reference() does not.  Thus, xdr_pointer() can  rep‐
146              resent recursive data structures, such as binary trees or linked
147              lists.
148
149       void xdrrec_create(XDR *xdrs, unsigned int sendsize,
150                          unsigned int recvsize, char *handle,
151                          int (*readit) (char *, char *, int),
152                          int (*writeit) (char *, char *, int));
153
154              This routine initializes the XDR stream  object  pointed  to  by
155              xdrs.   The  stream's  data is written to a buffer of size send‐
156              size; a value of zero indicates the system should use a suitable
157              default.   The stream's data is read from a buffer of size recv‐
158              size; it too can be set to a suitable default by passing a  zero
159              value.   When  a  stream's  output  buffer  is  full, writeit is
160              called.  Similarly, when a stream's input buffer is empty,  rea‐
161              dit is called.  The behavior of these two routines is similar to
162              the system calls read(2) and write(2),  except  that  handle  is
163              passed  to the former routines as the first argument.  Note: the
164              XDR stream's op field must be set by the caller.
165
166              Warning: this  XDR  stream  implements  an  intermediate  record
167              stream.   Therefore  there are additional bytes in the stream to
168              provide record boundary information.
169
170       bool_t xdrrec_endofrecord(XDR *xdrs, int sendnow);
171
172              This routine can be invoked only  on  streams  created  by  xdr‐
173              rec_create().  The data in the output buffer is marked as a com‐
174              pleted record, and the output buffer is optionally  written  out
175              if  sendnow  is  non-zero.   This routine returns one if it suc‐
176              ceeds, zero otherwise.
177
178       bool_t xdrrec_eof(XDR *xdrs);
179
180              This routine can be invoked only  on  streams  created  by  xdr‐
181              rec_create().  After consuming the rest of the current record in
182              the stream, this routine returns one if the stream has  no  more
183              input, zero otherwise.
184
185       bool_t xdrrec_skiprecord(XDR *xdrs);
186
187              This  routine  can  be  invoked  only on streams created by xdr‐
188              rec_create().  It tells the XDR implementation that the rest  of
189              the  current  record in the stream's input buffer should be dis‐
190              carded.  This routine returns one if it  succeeds,  zero  other‐
191              wise.
192
193       bool_t xdr_reference(XDR *xdrs, char **pp, unsigned int size,
194                            xdrproc_t proc);
195
196              A  primitive  that  provides  pointer chasing within structures.
197              The argument pp is the address  of  the  pointer;  size  is  the
198              sizeof the structure that *pp points to; and proc is an XDR pro‐
199              cedure that filters the structure between its  C  form  and  its
200              external  representation.   This  routine returns one if it suc‐
201              ceeds, zero otherwise.
202
203              Warning: this routine does not understand  NULL  pointers.   Use
204              xdr_pointer() instead.
205
206       xdr_setpos(XDR *xdrs, unsigned int pos);
207
208              A  macro  that  invokes the set position routine associated with
209              the XDR stream xdrs.  The  argument  pos  is  a  position  value
210              obtained from xdr_getpos().  This routine returns one if the XDR
211              stream could be repositioned, and zero otherwise.
212
213              Warning: it  is  difficult  to  reposition  some  types  of  XDR
214              streams,  so  this  routine may fail with one type of stream and
215              succeed with another.
216
217       bool_t xdr_short(XDR *xdrs, short *sp);
218
219              A filter primitive that translates between C short integers  and
220              their  external representations.  This routine returns one if it
221              succeeds, zero otherwise.
222
223       void xdrstdio_create(XDR *xdrs, FILE *file, enum xdr_op op);
224
225              This routine initializes the XDR stream  object  pointed  to  by
226              xdrs.   The  XDR  stream  data  is written to, or read from, the
227              stdio stream file.  The argument op determines the direction  of
228              the XDR stream (either XDR_ENCODE, XDR_DECODE, or XDR_FREE).
229
230              Warning:  the  destroy  routine associated with such XDR streams
231              calls fflush(3) on the file stream, but never fclose(3).
232
233       bool_t xdr_string(XDR *xdrs, char **sp, unsigned int maxsize);
234
235              A filter primitive that translates between C strings  and  their
236              corresponding   external  representations.   Strings  cannot  be
237              longer than maxsize.  Note: sp is the address  of  the  string's
238              pointer.   This  routine returns one if it succeeds, zero other‐
239              wise.
240
241       bool_t xdr_u_char(XDR *xdrs, unsigned char *ucp);
242
243              A filter primitive that translates between unsigned C characters
244              and their external representations.  This routine returns one if
245              it succeeds, zero otherwise.
246
247       bool_t xdr_u_int(XDR *xdrs, unsigned *up);
248
249              A filter primitive that translates between C  unsigned  integers
250              and their external representations.  This routine returns one if
251              it succeeds, zero otherwise.
252
253       bool_t xdr_u_long(XDR *xdrs, unsigned long *ulp);
254
255              A filter primitive that translates between C unsigned long inte‐
256              gers  and  their external representations.  This routine returns
257              one if it succeeds, zero otherwise.
258
259       bool_t xdr_u_short(XDR *xdrs, unsigned short *usp);
260
261              A filter primitive that  translates  between  C  unsigned  short
262              integers  and  their  external  representations.   This  routine
263              returns one if it succeeds, zero otherwise.
264
265       bool_t xdr_union(XDR *xdrs, int *dscmp, char *unp,
266                        struct xdr_discrim *choices,
267                        xdrproc_t defaultarm);     /* may equal NULL */
268
269              A filter primitive that translates  between  a  discriminated  C
270              union  and  its corresponding external representation.  It first
271              translates the discriminant of the union located at dscmp.  This
272              discriminant is always an enum_t.  Next the union located at unp
273              is translated.  The argument choices is a pointer to an array of
274              xdr_discrim()  structures.   Each  structure contains an ordered
275              pair of [value,proc].  If the union's discriminant is  equal  to
276              the  associated  value, then the proc is called to translate the
277              union.  The end of the xdr_discrim() structure array is  denoted
278              by a routine of value NULL.  If the discriminant is not found in
279              the choices array, then the defaultarm procedure is  called  (if
280              it is not NULL).  Returns one if it succeeds, zero otherwise.
281
282       bool_t xdr_vector(XDR *xdrs, char *arrp, unsigned int size,
283                         unsigned int elsize, xdrproc_t elproc);
284
285              A  filter  primitive that translates between fixed-length arrays
286              and their corresponding external representations.  The  argument
287              arrp  is  the address of the pointer to the array, while size is
288              the element count of the array.   The  argument  elsize  is  the
289              sizeof each of the array's elements, and elproc is an XDR filter
290              that translates between the array elements' C  form,  and  their
291              external  representation.   This  routine returns one if it suc‐
292              ceeds, zero otherwise.
293
294       bool_t xdr_void(void);
295
296              This routine always returns one.  It may be passed to  RPC  rou‐
297              tines  that  require a function argument, where nothing is to be
298              done.
299
300       bool_t xdr_wrapstring(XDR *xdrs, char **sp);
301
302              A primitive that  calls  xdr_string(xdrs,  sp,MAXUN.UNSIGNED  );
303              where  MAXUN.UNSIGNED  is the maximum value of an unsigned inte‐
304              ger.  xdr_wrapstring() is handy because the RPC package passes a
305              maximum  of two XDR routines as arguments, and xdr_string(), one
306              of the most frequently used primitives, requires three.  Returns
307              one if it succeeds, zero otherwise.
308

SEE ALSO

310       rpc(3)
311
312       The following manuals:
313              eXternal Data Representation Standard: Protocol Specification
314              eXternal Data Representation: Sun Technical Notes
315              XDR:   External  Data  Representation  Standard,  RFC 1014,  Sun
316              Microsystems, Inc., USC-ISI.
317

COLOPHON

319       This page is part of release 3.22 of the Linux  man-pages  project.   A
320       description  of  the project, and information about reporting bugs, can
321       be found at http://www.kernel.org/doc/man-pages/.
322
323
324
325                                  2007-12-30                            XDR(3)
Impressum