1xdr(3)                     Library Functions Manual                     xdr(3)
2
3
4

NAME

6       xdr - library routines for external data representation
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS AND DESCRIPTION

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

ATTRIBUTES

316       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
317       tributes(7).
318
319       ┌────────────────────────────────────────────┬───────────────┬─────────┐
320Interface                                   Attribute     Value   
321       ├────────────────────────────────────────────┼───────────────┼─────────┤
322xdr_array(), xdr_bool(), xdr_bytes(),       │ Thread safety │ MT-Safe │
323xdr_char(), xdr_destroy(), xdr_double(),    │               │         │
324xdr_enum(), xdr_float(), xdr_free(),        │               │         │
325xdr_getpos(), xdr_inline(), xdr_int(),      │               │         │
326xdr_long(), xdrmem_create(), xdr_opaque(),  │               │         │
327xdr_pointer(), xdrrec_create(),             │               │         │
328xdrrec_eof(), xdrrec_endofrecord(),         │               │         │
329xdrrec_skiprecord(), xdr_reference(),       │               │         │
330xdr_setpos(), xdr_short(),                  │               │         │
331xdrstdio_create(), xdr_string(),            │               │         │
332xdr_u_char(), xdr_u_int(), xdr_u_long(),    │               │         │
333xdr_u_short(), xdr_union(), xdr_vector(),   │               │         │
334xdr_void(), xdr_wrapstring()                │               │         │
335       └────────────────────────────────────────────┴───────────────┴─────────┘
336

SEE ALSO

338       rpc(3)
339
340       The following manuals:
341              eXternal Data Representation Standard: Protocol Specification
342              eXternal Data Representation: Sun Technical Notes
343              XDR:   External  Data  Representation  Standard,  RFC 1014,  Sun
344              Microsystems, Inc., USC-ISI.
345
346
347
348Linux man-pages 6.05              2023-07-20                            xdr(3)
Impressum