man-pages/man3/xdr.3

552 lines
14 KiB
Groff
Raw Normal View History

.\" This page was taken from the 4.4BSD-Lite CDROM (BSD license)
.\"
2004-11-03 13:51:07 +00:00
.\" @(#)xdr.3n 2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI
.\"
.\" 2007-12-30, mtk, Convert function prototypes to modern C syntax
.\"
.TH XDR 3 2007-12-30 "" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.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.
The prototypes below are declared in
.I <rpc/xdr.h>
and make use of the following types:
.in +4n
2008-01-01 07:52:35 +00:00
.nf
typedef int \fIbool_t\fP;
typedef bool_t (*\fIxdrproc_t\fP) (XDR *, void *,...);
.fi
2008-01-01 07:52:35 +00:00
.in
.LP
For the declaration of the
.I XDR
type, see
.IR <rpc/xdr.h> .
2004-11-03 13:51:07 +00:00
.LP
.nf
.BI "bool_t xdr_array(XDR *" xdrs ", char **" arrp ", unsigned int *" sizep ,
.BI " unsigned int " maxsize ", unsigned int " elsize ,
.BI " xdrproc_t " elproc );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between variable-length arrays
and their corresponding external representations.
The argument
2004-11-03 13:51:07 +00:00
.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 argument
2004-11-03 13:51:07 +00:00
.I elsize
is the
.I sizeof
each of the array's elements, and
.I elproc
is an XDR filter that translates between
2004-11-03 13:51:07 +00:00
the array elements' C form, and their external
representation.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_bool(XDR *" xdrs ", bool_t *" bp );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between booleans (C
integers)
and their external representations.
When encoding data, this
2004-11-03 13:51:07 +00:00
filter produces values of either one or zero.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_bytes(XDR *" xdrs ", char **" sp ", unsigned int *" sizep ,
.BI " unsigned int " maxsize );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between counted byte
strings and their external representations.
The argument
2004-11-03 13:51:07 +00:00
.I sp
is the address of the string pointer.
The length of the
2004-11-03 13:51:07 +00:00
string is located at address
.IR sizep ;
strings cannot be longer than
.IR maxsize .
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_char(XDR *" xdrs ", char *" cp );
2004-11-03 13:51:07 +00:00
.fi
.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
2004-11-03 13:51:07 +00:00
consider
.BR xdr_bytes (),
.BR xdr_opaque ()
2004-11-03 13:51:07 +00:00
or
.BR xdr_string ().
2004-11-03 13:51:07 +00:00
.LP
.nf
.BI "void xdr_destroy(XDR *" xdrs );
2004-11-03 13:51:07 +00:00
.fi
.IP
A macro that invokes the destroy routine associated with the XDR stream,
2004-11-03 13:51:07 +00:00
.IR xdrs .
Destruction usually involves freeing private data structures
associated with the stream.
Using
2004-11-03 13:51:07 +00:00
.I xdrs
after invoking
.BR xdr_destroy ()
2004-11-03 13:51:07 +00:00
is undefined.
.LP
.nf
.BI "bool_t xdr_double(XDR *" xdrs ", double *" dp );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between C
2006-02-09 20:24:53 +00:00
.I double
2004-11-03 13:51:07 +00:00
precision numbers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_enum(XDR *" xdrs ", enum_t *" ep );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between C
2007-06-23 07:56:56 +00:00
.IR enum s
2004-11-03 13:51:07 +00:00
(actually integers) and their external representations.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_float(XDR *" xdrs ", float *" fp );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between C
2007-06-23 07:56:56 +00:00
.IR float s
2004-11-03 13:51:07 +00:00
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "void xdr_free(xdrproc_t " proc ", char *" objp );
2004-11-03 13:51:07 +00:00
.fi
.IP
Generic freeing routine.
The first argument is the 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
2004-11-03 13:51:07 +00:00
.I not
freed, but what it points to
.I is
freed (recursively).
.LP
.nf
.BI "unsigned int xdr_getpos(XDR *" xdrs );
2004-11-03 13:51:07 +00:00
.fi
.IP
A macro that invokes the get-position routine
associated with the XDR stream,
2004-11-03 13:51:07 +00:00
.IR xdrs .
The routine returns an unsigned integer,
which indicates the position of the XDR byte stream.
A desirable feature of XDR
2004-11-03 13:51:07 +00:00
streams is that simple arithmetic works with this number,
although the XDR stream instances need not guarantee this.
2004-11-03 13:51:07 +00:00
.LP
.nf
.BI "long *xdr_inline(XDR *" xdrs ", int " len );
2004-11-03 13:51:07 +00:00
.fi
.IP
A macro that invokes the inline routine associated with the XDR stream,
2004-11-03 13:51:07 +00:00
.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
2006-02-09 20:24:53 +00:00
.IR "long *" .
2004-11-03 13:51:07 +00:00
.IP
Warning:
.BR xdr_inline ()
may return NULL (0)
2004-11-03 13:51:07 +00:00
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.
.LP
.nf
.BI "bool_t xdr_int(XDR *" xdrs ", int *" ip );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between C integers
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_long(XDR *" xdrs ", long *" lp );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between C
2006-02-09 20:24:53 +00:00
.I long
2004-11-03 13:51:07 +00:00
integers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "void xdrmem_create(XDR *" xdrs ", char *" addr ", unsigned int " size ,
.BI " enum xdr_op " op );
2004-11-03 13:51:07 +00:00
.fi
.IP
This routine initializes the XDR stream object pointed to by
2004-11-03 13:51:07 +00:00
.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
2004-11-03 13:51:07 +00:00
.I op
determines the direction of the XDR stream (either
2007-12-16 15:39:37 +00:00
.BR XDR_ENCODE ,
.BR XDR_DECODE ,
2004-11-03 13:51:07 +00:00
or
2007-12-16 15:39:37 +00:00
.BR XDR_FREE ).
2004-11-03 13:51:07 +00:00
.LP
.nf
.BI "bool_t xdr_opaque(XDR *" xdrs ", char *" cp ", unsigned int " cnt );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between fixed size opaque data
and its external representation.
The argument
2004-11-03 13:51:07 +00:00
.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.
.LP
.nf
.BI "bool_t xdr_pointer(XDR *" xdrs ", char **" objpp ,
.BI " unsigned int " objsize ", xdrproc_t " xdrobj );
2004-11-03 13:51:07 +00:00
.fi
.IP
Like
.BR xdr_reference ()
except that it serializes NULL pointers, whereas
.BR xdr_reference ()
does not.
Thus,
.BR xdr_pointer ()
2004-11-03 13:51:07 +00:00
can represent
recursive data structures, such as binary trees or
linked lists.
.LP
.nf
.BI "void xdrrec_create(XDR *" xdrs ", unsigned int " sendsize ,
.BI " unsigned int " recvsize ", char *" handle ,
.BI " int (*" readit ") (char *, char *, int),"
.BI " int (*" writeit ") (char *, char *, int));"
2004-11-03 13:51:07 +00:00
.fi
.IP
This routine initializes the XDR stream object pointed to by
2004-11-03 13:51:07 +00:00
.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
2004-11-03 13:51:07 +00:00
.IR recvsize ;
it too can be set to a suitable default by passing a zero value.
2004-11-03 13:51:07 +00:00
When a stream's output buffer is full,
.I writeit
is called.
Similarly, when a stream's input buffer is empty,
2004-11-03 13:51:07 +00:00
.I readit
is called.
The behavior of these two routines is similar to
the system calls
.BR read (2)
2004-11-03 13:51:07 +00:00
and
.BR write (2),
2004-11-03 13:51:07 +00:00
except that
.I handle
is passed to the former routines as the first argument.
Note: the XDR stream's
2004-11-03 13:51:07 +00:00
.I op
field must be set by the caller.
.IP
Warning: this XDR stream implements an intermediate record stream.
2004-11-03 13:51:07 +00:00
Therefore there are additional bytes in the stream
to provide record boundary information.
.LP
.nf
.BI "bool_t xdrrec_endofrecord(XDR *" xdrs ", int " sendnow );
2004-11-03 13:51:07 +00:00
.fi
.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,
2004-11-03 13:51:07 +00:00
and the output buffer is optionally written out if
.I sendnow
intro.1, time.1, adjtimex.2, capget.2, eventfd.2, fcntl.2, getrlimit.2, getsockopt.2, gettimeofday.2, intro.2, ioctl_list.2, ioperm.2, mlock.2, pivot_root.2, poll.2, prctl.2, ptrace.2, sched_setscheduler.2, select_tut.2, semget.2, sigaltstack.2, signalfd.2, sysctl.2, timer_settime.2, timerfd_create.2, wait.2, CPU_SET.3, argz_add.3, assert_perror.3, atexit.3, backtrace.3, bcmp.3, clearenv.3, ctime.3, dl_iterate_phdr.3, dlopen.3, ecvt.3, errno.3, error.3, ether_aton.3, exit.3, fenv.3, ferror.3, finite.3, flockfile.3, fnmatch.3, fpathconf.3, fpclassify.3, ftime.3, ftok.3, ftw.3, fwide.3, getaddrinfo.3, gethostbyname.3, getlogin.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getrpcent.3, getservent.3, glob.3, hsearch.3, inet.3, isalpha.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, longjmp.3, lsearch.3, malloc.3, matherr.3, mblen.3, mbsinit.3, mbtowc.3, on_exit.3, printf.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_equal.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, ptsname.3, putenv.3, putgrent.3, raise.3, rcmd.3, regex.3, rexec.3, rpc.3, rpmatch.3, rtnetlink.3, scandir.3, sem_init.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, signbit.3, stdio_ext.3, strtod.3, strtol.3, strtoul.3, system.3, termios.3, timeradd.3, tzset.3, ualarm.3, wctomb.3, xdr.3, st.4, tty_ioctl.4, core.5, elf.5, proc.5, bootparam.7, capabilities.7, icmp.7, ip.7, ipv6.7, math_error.7, mdoc.samples.7, mq_overview.7, pthreads.7, raw.7, regex.7, socket.7, tcp.7, tzselect.8: Global fix: s/non-zero/nonzero/ The tendency in English, as prescribed in style guides like Chicago MoS, is towards removing hyphens after prefixes like "non-" etc. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:40:55 +00:00
is nonzero.
This routine returns one if it succeeds, zero otherwise.
2004-11-03 13:51:07 +00:00
.LP
.nf
.BI "bool_t xdrrec_eof(XDR *" xdrs );
2004-11-03 13:51:07 +00:00
.fi
.IP
This routine can be invoked only on streams created by
.BR xdrrec_create ().
2004-11-03 13:51:07 +00:00
After consuming the rest of the current record in the stream,
this routine returns one if the stream has no more input,
zero otherwise.
.LP
.nf
.BI "bool_t xdrrec_skiprecord(XDR *" xdrs );
2004-11-03 13:51:07 +00:00
.fi
.IP
This routine can be invoked only on
streams created by
.BR xdrrec_create ().
It tells the XDR implementation that the rest of the current record
2004-11-03 13:51:07 +00:00
in the stream's input buffer should be discarded.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_reference(XDR *" xdrs ", char **" pp ", unsigned int " size ,
.BI " xdrproc_t " proc );
2004-11-03 13:51:07 +00:00
.fi
.IP
A primitive that provides pointer chasing within structures.
The argument
2004-11-03 13:51:07 +00:00
.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 XDR procedure that filters the structure
2004-11-03 13:51:07 +00:00
between its C form and its external representation.
This routine returns one if it succeeds, zero otherwise.
.IP
Warning: this routine does not understand NULL pointers.
Use
.BR xdr_pointer ()
2004-11-03 13:51:07 +00:00
instead.
.LP
.nf
.BI "xdr_setpos(XDR *" xdrs ", unsigned int " pos );
2004-11-03 13:51:07 +00:00
.fi
.IP
A macro that invokes the set position routine associated with
the XDR stream
2004-11-03 13:51:07 +00:00
.IR xdrs .
The argument
2004-11-03 13:51:07 +00:00
.I pos
is a position value obtained from
.BR xdr_getpos ().
This routine returns one if the XDR stream could be repositioned,
2004-11-03 13:51:07 +00:00
and zero otherwise.
.IP
Warning: it is difficult to reposition some types of XDR
2004-11-03 13:51:07 +00:00
streams, so this routine may fail with one
type of stream and succeed with another.
.LP
.nf
.BI "bool_t xdr_short(XDR *" xdrs ", short *" sp );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between C
2007-06-23 07:56:56 +00:00
.I short
2004-11-03 13:51:07 +00:00
integers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "void xdrstdio_create(XDR *" xdrs ", FILE *" file ", enum xdr_op " op );
2004-11-03 13:51:07 +00:00
.fi
.IP
This routine initializes the XDR stream object pointed to by
2004-11-03 13:51:07 +00:00
.IR xdrs .
The XDR stream data is written to, or read from, the
2007-06-23 08:19:17 +00:00
.I stdio
2004-11-03 13:51:07 +00:00
stream
.IR file .
The argument
2004-11-03 13:51:07 +00:00
.I op
determines the direction of the XDR stream (either
2007-12-16 15:39:37 +00:00
.BR XDR_ENCODE ,
.BR XDR_DECODE ,
2004-11-03 13:51:07 +00:00
or
2007-12-16 15:39:37 +00:00
.BR XDR_FREE ).
2004-11-03 13:51:07 +00:00
.IP
Warning: the destroy routine associated with such XDR streams calls
.BR fflush (3)
2004-11-03 13:51:07 +00:00
on the
.I file
stream, but never
.BR fclose (3).
2004-11-03 13:51:07 +00:00
.LP
.nf
.BI "bool_t xdr_string(XDR *" xdrs ", char **" sp ", unsigned int " maxsize );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between C strings and
their corresponding external representations.
2004-11-03 13:51:07 +00:00
Strings cannot be longer than
.IR maxsize .
Note:
2004-11-03 13:51:07 +00:00
.I sp
is the address of the string's pointer.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_u_char(XDR *" xdrs ", unsigned char *" ucp );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between
2006-02-09 20:24:53 +00:00
.I unsigned
2004-11-03 13:51:07 +00:00
C characters and their external representations.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_u_int(XDR *" xdrs ", unsigned *" up );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between C
2006-02-09 20:24:53 +00:00
.I unsigned
2004-11-03 13:51:07 +00:00
integers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_u_long(XDR *" xdrs ", unsigned long *" ulp );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between C
2006-02-09 20:24:53 +00:00
.I "unsigned long"
2004-11-03 13:51:07 +00:00
integers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_u_short(XDR *" xdrs ", unsigned short *" usp );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between C
2006-02-09 20:24:53 +00:00
.I "unsigned short"
2004-11-03 13:51:07 +00:00
integers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_union(XDR *" xdrs ", int *" dscmp ", char *" unp ,
.BI " struct xdr_discrim *" choices ,
.BI " xdrproc_t " defaultarm "); /* may equal NULL */"
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between a discriminated C
2007-06-23 07:56:56 +00:00
.I union
and its corresponding external representation.
It first
2004-11-03 13:51:07 +00:00
translates the discriminant of the union located at
.IR dscmp .
This discriminant is always an
2007-06-23 07:56:56 +00:00
.IR enum_t .
2004-11-03 13:51:07 +00:00
Next the union located at
.I unp
is translated.
The argument
2004-11-03 13:51:07 +00:00
.I choices
is a pointer to an array of
.BR xdr_discrim ()
structures.
Each structure contains an ordered pair of
2004-11-03 13:51:07 +00:00
.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
.BR xdr_discrim ()
structure array is denoted by a routine of value NULL.
2004-11-03 13:51:07 +00:00
If the discriminant is not found in the
.I choices
array, then the
.I defaultarm
procedure is called (if it is not NULL).
2004-11-03 13:51:07 +00:00
Returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_vector(XDR *" xdrs ", char *" arrp ", unsigned int " size ,
.BI " unsigned int " elsize ", xdrproc_t " elproc );
2004-11-03 13:51:07 +00:00
.fi
.IP
A filter primitive that translates between fixed-length arrays
and their corresponding external representations.
The argument
2004-11-03 13:51:07 +00:00
.I arrp
is the address of the pointer to the array, while
.I size
2007-09-06 18:26:32 +00:00
is the element count of the array.
The argument
2004-11-03 13:51:07 +00:00
.I elsize
is the
.I sizeof
each of the array's elements, and
.I elproc
is an XDR filter that translates between
2004-11-03 13:51:07 +00:00
the array elements' C form, and their external
representation.
This routine returns one if it succeeds, zero otherwise.
.LP
.nf
.BI "bool_t xdr_void(void);"
2004-11-03 13:51:07 +00:00
.fi
.IP
This routine always returns one.
It may be passed to RPC routines that require a function argument,
2004-11-03 13:51:07 +00:00
where nothing is to be done.
.LP
.nf
.BI "bool_t xdr_wrapstring(XDR *" xdrs ", char **" sp );
2004-11-03 13:51:07 +00:00
.fi
.IP
A primitive that calls
2007-12-16 15:39:37 +00:00
.B "xdr_string(xdrs, sp,MAXUN.UNSIGNED );"
2004-11-03 13:51:07 +00:00
where
2007-12-24 16:10:29 +00:00
.B MAXUN.UNSIGNED
2004-11-03 13:51:07 +00:00
is the maximum value of an unsigned integer.
.BR xdr_wrapstring ()
is handy because the RPC package passes a maximum of two XDR
routines as arguments, and
.BR xdr_string (),
2004-11-03 13:51:07 +00:00
one of the most frequently used primitives, requires three.
Returns one if it succeeds, zero otherwise.
.SH "SEE ALSO"
.BR rpc (3)
2004-11-03 13:51:07 +00:00
.LP
The following manuals:
.RS
eXternal Data Representation Standard: Protocol Specification
.br
eXternal Data Representation: Sun Technical Notes
.br
2007-12-16 15:39:37 +00:00
.IR "XDR: External Data Representation Standard" ,
2007-12-24 16:10:29 +00:00
RFC\ 1014, Sun Microsystems, Inc.,
USC-ISI.
2007-12-17 09:22:40 +00:00
.RE