Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


xdr(3) — Linux manual page

NAME |LIBRARY |SYNOPSIS AND DESCRIPTION |ATTRIBUTES |SEE ALSO |COLOPHON

xdr(3)                   Library Functions Manualxdr(3)

NAME        top

       xdr - library routines for external data representation

LIBRARY        top

       Standard C library (libc,-lc)

SYNOPSIS AND DESCRIPTION        top

       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<rpc/xdr.h> and make use of       the following types:typedef intbool_t;typedef typeof(bool_t (XDR *, void *, ...))  *xdrproc_t;       For the declaration of theXDR type, see<rpc/xdr.h>.bool_t xdr_array(XDR *xdrs, char **arrp, unsigned int *sizep,unsigned intmaxsize, unsigned intelsize,xdrproc_telproc);              A filter primitive that translates between variable-length              arrays and their corresponding external representations.              The argumentarrp is the address of the pointer to the              array, whilesizep is the address of the element count of              the array; this element count cannot exceedmaxsize.  The              argumentelsize is thesizeof each of the array's elements,              andelproc is an XDR filter that translates between the              array elements' C form, and their external representation.              This routine returns one if it succeeds, zero otherwise.bool_t xdr_bool(XDR *xdrs, bool_t *bp);              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.bool_t xdr_bytes(XDR *xdrs, char **sp, unsigned int *sizep,unsigned intmaxsize);              A filter primitive that translates between counted byte              strings and their external representations.  The argumentsp is the address of the string pointer.  The length of the              string is located at addresssizep; strings cannot be              longer thanmaxsize.  This routine returns one if it              succeeds, zero otherwise.bool_t xdr_char(XDR *xdrs, char *cp);              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 considerxdr_bytes(),xdr_opaque(), orxdr_string().void xdr_destroy(XDR *xdrs);              A macro that invokes the destroy routine associated with              the XDR stream,xdrs.  Destruction usually involves freeing              private data structures associated with the stream.  Usingxdrs after invokingxdr_destroy() is undefined.bool_t xdr_double(XDR *xdrs, double *dp);              A filter primitive that translates between Cdouble              precision numbers and their external representations.  This              routine returns one if it succeeds, zero otherwise.bool_t xdr_enum(XDR *xdrs, enum_t *ep);              A filter primitive that translates between Cenums              (actually integers) and their external representations.              This routine returns one if it succeeds, zero otherwise.bool_t xdr_float(XDR *xdrs, float *fp);              A filter primitive that translates between Cfloats and              their external representations.  This routine returns one              if it succeeds, zero otherwise.void xdr_free(xdrproc_tproc, char *objp);              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 isnot freed, but what it points tois              freed (recursively).unsigned int xdr_getpos(XDR *xdrs);              A macro that invokes the get-position routine associated              with the XDR stream,xdrs.  The routine returns an unsigned              integer, which indicates the position of the XDR byte              stream.  A desirable feature of XDR streams is that simple              arithmetic works with this number, although the XDR stream              instances need not guarantee this.long *xdr_inline(XDR *xdrs, intlen);              A macro that invokes the inline routine associated with the              XDR stream,xdrs.  The routine returns a pointer to a              contiguous piece of the stream's buffer;len is the byte              length of the desired buffer.  Note: pointer is cast tolong *.              Warning:xdr_inline() may return 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.bool_t xdr_int(XDR *xdrs, int *ip);              A filter primitive that translates between C integers and              their external representations.  This routine returns one              if it succeeds, zero otherwise.bool_t xdr_long(XDR *xdrs, long *lp);              A filter primitive that translates between Clong integers              and their external representations.  This routine returns              one if it succeeds, zero otherwise.void xdrmem_create(XDR *xdrs, char *addr, unsigned intsize,enum xdr_opop);              This routine initializes the XDR stream object pointed to              byxdrs.  The stream's data is written to, or read from, a              chunk of memory at locationaddr whose length is no more              thansize bytes long.  Theop determines the direction of              the XDR stream (eitherXDR_ENCODE,XDR_DECODE, orXDR_FREE).bool_t xdr_opaque(XDR *xdrs, char *cp, unsigned intcnt);              A filter primitive that translates between fixed size              opaque data and its external representation.  The argumentcp is the address of the opaque object, andcnt is its size              in bytes.  This routine returns one if it succeeds, zero              otherwise.bool_t xdr_pointer(XDR *xdrs, char **objpp,unsigned intobjsize, xdrproc_txdrobj);              Likexdr_reference() except that it serializes null              pointers, whereasxdr_reference() does not.  Thus,xdr_pointer() can represent recursive data structures, such              as binary trees or linked lists.void xdrrec_create(XDR *xdrs, unsigned intsendsize,unsigned intrecvsize, char *handle,typeof(int (char *, char *, int)) *readit,typeof(int (char *, char *, int)) *writeit);              This routine initializes the XDR stream object pointed to              byxdrs.  The stream's data is written to a buffer of sizesendsize; a value of zero indicates the system should use a              suitable default.  The stream's data is read from a buffer              of sizerecvsize; it too can be set to a suitable default              by passing a zero value.  When a stream's output buffer is              full,writeit is called.  Similarly, when a stream's input              buffer is empty,readit is called.  The behavior of these              two routines is similar to the system callsread(2) andwrite(2), except thathandle is passed to the former              routines as the first argument.  Note: the XDR stream'sop              field must be set by the caller.              Warning: to read from an XDR stream created by this API,              you'll need to callxdrrec_skiprecord() first before              calling any other XDR APIs.  This inserts additional bytes              in the stream to provide record boundary information.              Also, XDR streams created with differentxdr*_createAPIs              are not compatible for the same reason.bool_t xdrrec_endofrecord(XDR *xdrs, intsendnow);              This routine can be invoked only on streams created byxdrrec_create().  The data in the output buffer is marked              as a completed record, and the output buffer is optionally              written out ifsendnow is nonzero.  This routine returns              one if it succeeds, zero otherwise.bool_t xdrrec_eof(XDR *xdrs);              This routine can be invoked only on streams created byxdrrec_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.bool_t xdrrec_skiprecord(XDR *xdrs);              This routine can be invoked only on streams created byxdrrec_create().  It tells the 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.bool_t xdr_reference(XDR *xdrs, char **pp, unsigned intsize,xdrproc_tproc);              A primitive that provides pointer chasing within              structures.  The argumentpp is the address of the pointer;size is thesizeof the structure that*pp points to; andproc is an XDR procedure that filters the structure between              its C form and its external representation.  This routine              returns one if it succeeds, zero otherwise.              Warning: this routine does not understand null pointers.              Usexdr_pointer() instead.xdr_setpos(XDR *xdrs, unsigned intpos);              A macro that invokes the set position routine associated              with the XDR streamxdrs.  The argumentpos is a position              value obtained fromxdr_getpos().  This routine returns one              if the XDR stream could be repositioned, and zero              otherwise.              Warning: it is difficult to reposition some types of XDR              streams, so this routine may fail with one type of stream              and succeed with another.bool_t xdr_short(XDR *xdrs, short *sp);              A filter primitive that translates between Cshort integers              and their external representations.  This routine returns              one if it succeeds, zero otherwise.void xdrstdio_create(XDR *xdrs, FILE *file, enum xdr_opop);              This routine initializes the XDR stream object pointed to              byxdrs.  The XDR stream data is written to, or read from,              thestdio streamfile.  The argumentop determines the              direction of the XDR stream (eitherXDR_ENCODE,XDR_DECODE,              orXDR_FREE).              Warning: the destroy routine associated with such XDR              streams callsfflush(3) on thefile stream, but neverfclose(3).bool_t xdr_string(XDR *xdrs, char **sp, unsigned intmaxsize);              A filter primitive that translates between C strings and              their corresponding external representations.  Strings              cannot be longer thanmaxsize.  Note:sp is the address of              the string's pointer.  This routine returns one if it              succeeds, zero otherwise.bool_t xdr_u_char(XDR *xdrs, unsigned char *ucp);              A filter primitive that translates betweenunsigned C              characters and their external representations.  This              routine returns one if it succeeds, zero otherwise.bool_t xdr_u_int(XDR *xdrs, unsigned int *up);              A filter primitive that translates between Cunsigned              integers and their external representations.  This routine              returns one if it succeeds, zero otherwise.bool_t xdr_u_long(XDR *xdrs, unsigned long *ulp);              A filter primitive that translates between Cunsigned long              integers and their external representations.  This routine              returns one if it succeeds, zero otherwise.bool_t xdr_u_short(XDR *xdrs, unsigned short *usp);              A filter primitive that translates between Cunsigned short              integers and their external representations.  This routine              returns one if it succeeds, zero otherwise.bool_t xdr_union(XDR *xdrs, enum_t *dscmp, char *unp,const struct xdr_discrim *choices,xdrproc_tdefaultarm);     /* may equal NULL */              A filter primitive that translates between a discriminated              Cunion and its corresponding external representation.  It              first translates the discriminant of the union located atdscmp.  This discriminant is always anenum_t.  Next the              union located atunp is translated.  The argumentchoices              is a pointer to an array ofxdr_discrim() structures.  Each              structure contains an ordered pair of [value,proc].  If the              union's discriminant is equal to the associatedvalue, then              theproc is called to translate the union.  The end of thexdr_discrim() structure array is denoted by a routine of              value NULL.  If the discriminant is not found in thechoices array, then thedefaultarm procedure is called (if              it is not NULL).  Returns one if it succeeds, zero              otherwise.bool_t xdr_vector(XDR *xdrs, char *arrp, unsigned intsize,unsigned intelsize, xdrproc_telproc);              A filter primitive that translates between fixed-length              arrays and their corresponding external representations.              The argumentarrp is the address of the pointer to the              array, whilesize is the element count of the array.  The              argumentelsize is thesizeof each of the array's elements,              andelproc is an XDR filter that translates between the              array elements' C form, and their external representation.              This routine returns one if it succeeds, zero otherwise.bool_t xdr_void(void);              This routine always returns one.  It may be passed to RPC              routines that require a function argument, where nothing is              to be done.bool_t xdr_wrapstring(XDR *xdrs, char **sp);              A primitive that callsxdr_string(xdrs, sp,MAXUN.UNSIGNED);whereMAXUN.UNSIGNEDis the maximum value of an unsigned              integer.xdr_wrapstring() is handy because the RPC package              passes a maximum of two XDR routines as arguments, andxdr_string(), one of the most frequently used primitives,              requires three.  Returns one if it succeeds, zero              otherwise.

ATTRIBUTES        top

       For an explanation of the terms used in this section, seeattributes(7).       ┌──────────────────────────────────────┬───────────────┬─────────┐       │InterfaceAttributeValue│       ├──────────────────────────────────────┼───────────────┼─────────┤       │xdr_array(),xdr_bool(),             │ Thread safety │ MT-Safe │       │xdr_bytes(),xdr_char(),             │               │         │       │xdr_destroy(),xdr_double(),         │               │         │       │xdr_enum(),xdr_float(),xdr_free(), │               │         │       │xdr_getpos(),xdr_inline(),          │               │         │       │xdr_int(),xdr_long(),               │               │         │       │xdrmem_create(),xdr_opaque(),       │               │         │       │xdr_pointer(),xdrrec_create(),      │               │         │       │xdrrec_eof(),xdrrec_endofrecord(),  │               │         │       │xdrrec_skiprecord(),                 │               │         │       │xdr_reference(),xdr_setpos(),       │               │         │       │xdr_short(),xdrstdio_create(),      │               │         │       │xdr_string(),xdr_u_char(),          │               │         │       │xdr_u_int(),xdr_u_long(),           │               │         │       │xdr_u_short(),xdr_union(),          │               │         │       │xdr_vector(),xdr_void(),            │               │         │       │xdr_wrapstring()                     │               │         │       └──────────────────────────────────────┴───────────────┴─────────┘

SEE ALSO        top

rpc(3)       The following manuals:              eXternal Data Representation Standard: Protocol              Specification              eXternal Data Representation: Sun Technical NotesXDR: External Data Representation Standard, RFC 1014, Sun              Microsystems, Inc., USC-ISI.

COLOPHON        top

       This page is part of theman-pages (Linux kernel and C library       user-space interface documentation) project.  Information about       the project can be found at        ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report       for this manual page, see       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.       This page was obtained from the tarball man-pages-6.15.tar.gz       fetched from       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on       2025-08-11.  If you discover any rendering problems in this HTML       version of the page, or you believe there is a better or more up-       to-date source for the page, or you have corrections or       improvements to the information in this COLOPHON (which isnot       part of the original manual page), send a mail to       man-pages@man7.orgLinux man-pages 6.15            2025-05-17xdr(3)

Pages that refer to this page:rpc(3)


Copyright and license for this manual page


HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp