1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
|
.\" $OpenBSD: xdr.3,v 1.3 1996/08/19 08:32:00 tholo Exp $
.\"
.TH XDR 3N "16 February 1988"
.SH NAME
xdr \- library routines for external data representation
.SH SYNOPSIS AND DESCRIPTION
.LP
These routines allow C programmers to describe
arbitrary data structures in a machine-independent fashion.
Data for remote procedure calls are transmitted using these
routines.
.LP
.ft B
.nf
.sp .5
xdr_array(xdrs, arrp, sizep, maxsize, elsize, elproc)
\s-1XDR\s0 *xdrs;
char **arrp;
u_int *sizep, maxsize, elsize;
xdrproc_t elproc;
.fi
.ft R
.IP
A filter primitive that translates between variable-length
arrays
and their corresponding external representations. The
parameter
.I arrp
is the address of the pointer to the array, while
.I sizep
is the address of the element count of the array;
this element count cannot exceed
.IR maxsize .
The parameter
.I elsize
is the
.I sizeof
each of the array's elements, and
.I elproc
is an
.SM XDR
filter that translates between
the array elements' C form, and their external
representation.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 8
.LP
.ft B
.nf
.sp .5
xdr_bool(xdrs, bp)
\s-1XDR\s0 *xdrs;
bool_t *bp;
.fi
.ft R
.IP
A filter primitive that translates between booleans (C
integers)
and their external representations. When encoding data, this
filter produces values of either one or zero.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 10
.LP
.ft B
.nf
.sp .5
xdr_bytes(xdrs, sp, sizep, maxsize)
\s-1XDR\s0 *xdrs;
char **sp;
u_int *sizep, maxsize;
.fi
.ft R
.IP
A filter primitive that translates between counted byte
strings and their external representations.
The parameter
.I sp
is the address of the string pointer. The length of the
string is located at address
.IR sizep ;
strings cannot be longer than
.IR maxsize .
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 7
.LP
.ft B
.nf
.sp .5
xdr_char(xdrs, cp)
\s-1XDR\s0 *xdrs;
char *cp;
.fi
.ft R
.IP
A filter primitive that translates between C characters
and their external representations.
This routine returns one if it succeeds, zero otherwise.
Note: encoded characters are not packed, and occupy 4 bytes
each. For arrays of characters, it is worthwhile to
consider
.BR xdr_bytes(\|) ,
.B xdr_opaque(\|)
or
.BR xdr_string(\|) .
.br
.if t .ne 8
.LP
.ft B
.nf
.sp .5
void
xdr_destroy(xdrs)
\s-1XDR\s0 *xdrs;
.fi
.ft R
.IP
A macro that invokes the destroy routine associated with the
.SM XDR
stream,
.IR xdrs .
Destruction usually involves freeing private data structures
associated with the stream. Using
.I xdrs
after invoking
.B xdr_destroy(\|)
is undefined.
.br
.if t .ne 7
.LP
.ft B
.nf
.sp .5
xdr_double(xdrs, dp)
\s-1XDR\s0 *xdrs;
double *dp;
.fi
.ft R
.IP
A filter primitive that translates between C
.B double
precision numbers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 7
.LP
.ft B
.nf
.sp .5
xdr_enum(xdrs, ep)
\s-1XDR\s0 *xdrs;
enum_t *ep;
.fi
.ft R
.IP
A filter primitive that translates between C
.BR enum s
(actually integers) and their external representations.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 8
.LP
.ft B
.nf
.sp .5
xdr_float(xdrs, fp)
\s-1XDR\s0 *xdrs;
float *fp;
.fi
.ft R
.IP
A filter primitive that translates between C
.BR float s
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 9
.LP
.ft B
.nf
.sp .5
void
xdr_free(proc, objp)
xdrproc_t proc;
char *objp;
.fi
.ft R
.IP
Generic freeing routine. The first argument is the
.SM XDR
routine for the object being freed. The second argument
is a pointer to the object itself. Note: the pointer passed
to this routine is
.I not
freed, but what it points to
.I is
freed (recursively).
.br
.if t .ne 8
.LP
.ft B
.nf
.sp .5
u_int
xdr_getpos(xdrs)
\s-1XDR\s0 *xdrs;
.fi
.ft R
.IP
A macro that invokes the get-position routine
associated with the
.SM XDR
stream,
.IR xdrs .
The routine returns an unsigned integer,
which indicates the position of the
.SM XDR
byte stream.
A desirable feature of
.SM XDR
streams is that simple arithmetic works with this number,
although the
.SM XDR
stream instances need not guarantee this.
.br
.if t .ne 4
.LP
.ft B
.nf
.sp .5
.br
long *
xdr_inline(xdrs, len)
\s-1XDR\s0 *xdrs;
int len;
.fi
.ft R
.IP
A macro that invokes the in-line routine associated with the
.SM XDR
stream,
.IR xdrs .
The routine returns a pointer
to a contiguous piece of the stream's buffer;
.I len
is the byte length of the desired buffer.
Note: pointer is cast to
.BR "long *" .
.IP
Warning:
.B xdr_inline(\|)
may return
.SM NULL
(0)
if it cannot allocate a contiguous piece of a buffer.
Therefore the behavior may vary among stream instances;
it exists for the sake of efficiency.
.br
.if t .ne 7
.LP
.ft B
.nf
.sp .5
xdr_int(xdrs, ip)
\s-1XDR\s0 *xdrs;
int *ip;
.fi
.ft R
.IP
A filter primitive that translates between C integers
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 7
.LP
.ft B
.nf
.sp .5
xdr_long(xdrs, lp)
\s-1XDR\s0 *xdrs;
long *lp;
.fi
.ft R
.IP
A filter primitive that translates between C
.B long
integers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 12
.LP
.ft B
.nf
.sp .5
void
xdrmem_create(xdrs, addr, size, op)
\s-1XDR\s0 *xdrs;
char *addr;
u_int size;
enum xdr_op op;
.fi
.ft R
.IP
This routine initializes the
.SM XDR
stream object pointed to by
.IR xdrs .
The stream's data is written to, or read from,
a chunk of memory at location
.I addr
whose length is no more than
.I size
bytes long. The
.I op
determines the direction of the
.SM XDR
stream
(either
.BR \s-1XDR_ENCODE\s0 ,
.BR \s-1XDR_DECODE\s0 ,
or
.BR \s-1XDR_FREE\s0 ).
.br
.if t .ne 10
.LP
.ft B
.nf
.sp .5
xdr_opaque(xdrs, cp, cnt)
\s-1XDR\s0 *xdrs;
char *cp;
u_int cnt;
.fi
.ft R
.IP
A filter primitive that translates between fixed size opaque
data
and its external representation.
The parameter
.I cp
is the address of the opaque object, and
.I cnt
is its size in bytes.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 10
.LP
.ft B
.nf
.sp .5
xdr_pointer(xdrs, objpp, objsize, xdrobj)
\s-1XDR\s0 *xdrs;
char **objpp;
u_int objsize;
xdrproc_t xdrobj;
.fi
.ft R
.IP
Like
.B xdr_reference(\|)
execpt that it serializes
.SM NULL
pointers, whereas
.B xdr_reference(\|)
does not. Thus,
.B xdr_pointer(\|)
can represent
recursive data structures, such as binary trees or
linked lists.
.br
.if t .ne 15
.LP
.ft B
.nf
.sp .5
void
xdrrec_create(xdrs, sendsize, recvsize, handle, readit, writeit)
\s-1XDR\s0 *xdrs;
u_int sendsize, recvsize;
char *handle;
int (*readit) (\|), (*writeit) (\|);
.fi
.ft R
.IP
This routine initializes the
.SM XDR
stream object pointed to by
.IR xdrs .
The stream's data is written to a buffer of size
.IR sendsize ;
a value of zero indicates the system should use a suitable
default. The stream's data is read from a buffer of size
.IR recvsize ;
it too can be set to a suitable default by passing a zero
value.
When a stream's output buffer is full,
.I writeit
is called. Similarly, when a stream's input buffer is empty,
.I readit
is called. The behavior of these two routines is similar to
the
system calls
.B read
and
.BR write ,
except that
.I handle
is passed to the former routines as the first parameter.
Note: the
.SM XDR
stream's
.I op
field must be set by the caller.
.IP
Warning: this
.SM XDR
stream implements an intermediate record stream.
Therefore there are additional bytes in the stream
to provide record boundary information.
.br
.if t .ne 9
.LP
.ft B
.nf
.sp .5
xdrrec_endofrecord(xdrs, sendnow)
\s-1XDR\s0 *xdrs;
int sendnow;
.fi
.ft R
.IP
This routine can be invoked only on
streams created by
.BR xdrrec_create(\|) .
The data in the output buffer is marked as a completed
record,
and the output buffer is optionally written out if
.I sendnow
is non-zero. This routine returns one if it succeeds, zero
otherwise.
.br
.if t .ne 8
.LP
.ft B
.nf
.sp .5
xdrrec_eof(xdrs)
\s-1XDR\s0 *xdrs;
int empty;
.fi
.ft R
.IP
This routine can be invoked only on
streams created by
.BR xdrrec_create(\|) .
After consuming the rest of the current record in the stream,
this routine returns one if the stream has no more input,
zero otherwise.
.br
.if t .ne 3
.LP
.ft B
.nf
.sp .5
xdrrec_skiprecord(xdrs)
\s-1XDR\s0 *xdrs;
.fi
.ft R
.IP
This routine can be invoked only on
streams created by
.BR xdrrec_create(\|) .
It tells the
.SM XDR
implementation that the rest of the current record
in the stream's input buffer should be discarded.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 11
.LP
.ft B
.nf
.sp .5
xdr_reference(xdrs, pp, size, proc)
\s-1XDR\s0 *xdrs;
char **pp;
u_int size;
xdrproc_t proc;
.fi
.ft R
.IP
A primitive that provides pointer chasing within structures.
The parameter
.I pp
is the address of the pointer;
.I size
is the
.I sizeof
the structure that
.I *pp
points to; and
.I proc
is an
.SM XDR
procedure that filters the structure
between its C form and its external representation.
This routine returns one if it succeeds, zero otherwise.
.IP
Warning: this routine does not understand
.SM NULL
pointers. Use
.B xdr_pointer(\|)
instead.
.br
.if t .ne 10
.LP
.ft B
.nf
.sp .5
xdr_setpos(xdrs, pos)
\s-1XDR\s0 *xdrs;
u_int pos;
.fi
.ft R
.IP
A macro that invokes the set position routine associated with
the
.SM XDR
stream
.IR xdrs .
The parameter
.I pos
is a position value obtained from
.BR xdr_getpos(\|) .
This routine returns one if the
.SM XDR
stream could be repositioned,
and zero otherwise.
.IP
Warning: it is difficult to reposition some types of
.SM XDR
streams, so this routine may fail with one
type of stream and succeed with another.
.br
.if t .ne 8
.LP
.ft B
.nf
.sp .5
xdr_short(xdrs, sp)
\s-1XDR\s0 *xdrs;
short *sp;
.fi
.ft R
.IP
A filter primitive that translates between C
.B short
integers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 10
.LP
.ft B
.nf
.sp .5
void
xdrstdio_create(xdrs, file, op)
\s-1XDR\s0 *xdrs;
\s-1FILE\s0 *file;
enum xdr_op op;
.fi
.ft R
.IP
This routine initializes the
.SM XDR
stream object pointed to by
.IR xdrs .
The
.SM XDR
stream data is written to, or read from, the Standard
.B I/O
stream
.IR file .
The parameter
.I op
determines the direction of the
.SM XDR
stream (either
.BR \s-1XDR_ENCODE\s0 ,
.BR \s-1XDR_DECODE\s0 ,
or
.BR \s-1XDR_FREE\s0 ).
.IP
Warning: the destroy routine associated with such
.SM XDR
streams calls
.B fflush(\|)
on the
.I file
stream, but never
.BR fclose(\|) .
.br
.if t .ne 9
.LP
.ft B
.nf
.sp .5
xdr_string(xdrs, sp, maxsize)
\s-1XDR\s0
*xdrs;
char **sp;
u_int maxsize;
.fi
.ft R
.IP
A filter primitive that translates between C strings and
their
corresponding external representations.
Strings cannot be longer than
.IR maxsize .
Note:
.I sp
is the address of the string's pointer.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 8
.LP
.ft B
.nf
.sp .5
xdr_u_char(xdrs, ucp)
\s-1XDR\s0 *xdrs;
unsigned char *ucp;
.fi
.ft R
.IP
A filter primitive that translates between
.B unsigned
C characters and their external representations.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 9
.LP
.ft B
.nf
.sp .5
xdr_u_int(xdrs, up)
\s-1XDR\s0 *xdrs;
unsigned *up;
.fi
.ft R
.IP
A filter primitive that translates between C
.B unsigned
integers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 7
.LP
.ft B
.nf
.sp .5
xdr_u_long(xdrs, ulp)
\s-1XDR\s0 *xdrs;
unsigned long *ulp;
.fi
.ft R
.IP
A filter primitive that translates between C
.B "unsigned long"
integers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 7
.LP
.ft B
.nf
.sp .5
xdr_u_short(xdrs, usp)
\s-1XDR\s0 *xdrs;
unsigned short *usp;
.fi
.ft R
.IP
A filter primitive that translates between C
.B "unsigned short"
integers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 16
.LP
.ft B
.nf
.sp .5
xdr_union(xdrs, dscmp, unp, choices, dfault)
\s-1XDR\s0 *xdrs;
int *dscmp;
char *unp;
struct xdr_discrim *choices;
bool_t (*defaultarm) (\|); /* may equal \s-1NULL\s0 */
.fi
.ft R
.IP
A filter primitive that translates between a discriminated C
.B union
and its corresponding external representation. It first
translates the discriminant of the union located at
.IR dscmp .
This discriminant is always an
.BR enum_t .
Next the union located at
.I unp
is translated. The parameter
.I choices
is a pointer to an array of
.B xdr_discrim(\|)
structures. Each structure contains an ordered pair of
.RI [ value , proc ].
If the union's discriminant is equal to the associated
.IR value ,
then the
.I proc
is called to translate the union. The end of the
.B xdr_discrim(\|)
structure array is denoted by a routine of value
.SM NULL\s0.
If the discriminant is not found in the
.I choices
array, then the
.I defaultarm
procedure is called (if it is not
.SM NULL\s0).
Returns one if it succeeds, zero otherwise.
.br
.if t .ne 6
.LP
.ft B
.nf
.sp .5
xdr_vector(xdrs, arrp, size, elsize, elproc)
\s-1XDR\s0 *xdrs;
char *arrp;
u_int size, elsize;
xdrproc_t elproc;
.fi
.ft R
.IP
A filter primitive that translates between fixed-length
arrays
and their corresponding external representations. The
parameter
.I arrp
is the address of the pointer to the array, while
.I size
is is the element count of the array. The parameter
.I elsize
is the
.I sizeof
each of the array's elements, and
.I elproc
is an
.SM XDR
filter that translates between
the array elements' C form, and their external
representation.
This routine returns one if it succeeds, zero otherwise.
.br
.if t .ne 5
.LP
.ft B
.nf
.sp .5
xdr_void(\|)
.fi
.ft R
.IP
This routine always returns one.
It may be passed to
.SM RPC
routines that require a function parameter,
where nothing is to be done.
.br
.if t .ne 10
.LP
.ft B
.nf
.sp .5
xdr_wrapstring(xdrs, sp)
\s-1XDR\s0 *xdrs;
char **sp;
.fi
.ft R
.IP
A primitive that calls
.B "xdr_string(xdrs, sp,\s-1MAXUN.UNSIGNED\s0 );"
where
.B
.SM MAXUN.UNSIGNED
is the maximum value of an unsigned integer.
.B xdr_wrapstring(\|)
is handy because the
.SM RPC
package passes a maximum of two
.SM XDR
routines as parameters, and
.BR xdr_string(\|) ,
one of the most frequently used primitives, requires three.
Returns one if it succeeds, zero otherwise.
.SH SEE ALSO
.BR rpc (3N)
.LP
The following manuals:
.RS
.ft I
eXternal Data Representation Standard: Protocol Specification
.br
eXternal Data Representation: Sun Technical Notes
.ft R
.br
.IR "\s-1XDR\s0: External Data Representation Standard" ,
.SM RFC1014, Sun Microsystems, Inc.,
.SM USC-ISI\s0.
|