xdr(3)
πΈ NAME πΈ
xdr β library routines for external data representation
π LIBRARY π
Standard C library (libc, -lc)
β¨ SYNOPSIS AND DESCRIPTION β¨
okay so bestie, welcome to xdr(3) from the Library Functions Manual. these routines let C programmers describe arbitrary data structures in a machine-independent way. Data for remote procedure calls gets transmitted using these routines. no cap.
The prototypes below are declared in <rpc/xdr.h> and they use these types:
typedef int bool_t;
typedef typeof(bool_t (XDR *, void *, ...)) *xdrproc_t;
For the declaration of the XDR type, see <rpc/xdr.h>.
xdr_array π¦
bool_t xdr_array(XDR *xdrs, char **arrp, unsigned int *sizep,
unsigned int maxsize, unsigned int elsize,
xdrproc_t elproc);
A filter primitive that translates between variable-length arrays and their corresponding external representations. The argument arrp is the address of the pointer to the array, while sizep is the address of the element count of the array; this element count cannot exceed maxsize. The argument elsize is the sizeof each of the array's elements, and elproc 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. periodt.
xdr_bool π
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.
xdr_bytes π
bool_t xdr_bytes(XDR *xdrs, char **sp, unsigned int *sizep,
unsigned int maxsize);
A filter primitive that translates between counted byte strings and their external representations. The argument sp is the address of the string pointer. The length of the string is located at address sizep; strings cannot be longer than maxsize. This routine returns one if it succeeds, zero otherwise.
xdr_char πΈ
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 consider xdr_bytes(), xdr_opaque(), or xdr_string(). iykyk.
xdr_destroy π
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. Using xdrs after invoking xdr_destroy() is undefined. don't do it bestie.
xdr_double β¨
bool_t xdr_double(XDR *xdrs, double *dp);
A filter primitive that translates between C double precision numbers and their external representations. This routine returns one if it succeeds, zero otherwise.
xdr_enum π
bool_t xdr_enum(XDR *xdrs, enum_t *ep);
A filter primitive that translates between C enums (actually integers) and their external representations. This routine returns one if it succeeds, zero otherwise.
xdr_float π¦
bool_t xdr_float(XDR *xdrs, float *fp);
A filter primitive that translates between C floats and their external representations. This routine returns one if it succeeds, zero otherwise.
xdr_free π§
void xdr_free(xdrproc_t proc, 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 is not freed, but what it points to is freed (recursively). okay?
xdr_getpos π
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.
xdr_inline π«
long *xdr_inline(XDR *xdrs, int len);
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 to long *.
Warning:xdr_inline()may returnNULL(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. vibe check: could be NULL!
xdr_int π
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.
xdr_long π
bool_t xdr_long(XDR *xdrs, long *lp);
A filter primitive that translates between C long integers and their external representations. This routine returns one if it succeeds, zero otherwise.
xdrmem_create π
void xdrmem_create(XDR *xdrs, char *addr, unsigned int size,
enum xdr_op op);
This routine initializes the XDR stream object pointed to by xdrs. The stream's data is written to, or read from, a chunk of memory at location addr whose length is no more than size bytes long. The op determines the direction of the XDR stream (either XDR_ENCODE, XDR_DECODE, or XDR_FREE).
xdr_opaque π
bool_t xdr_opaque(XDR *xdrs, char *cp, unsigned int cnt);
A filter primitive that translates between fixed size opaque data and its external representation. The argument cp is the address of the opaque object, and cnt is its size in bytes. This routine returns one if it succeeds, zero otherwise.
xdr_pointer π
bool_t xdr_pointer(XDR *xdrs, char **objpp,
unsigned int objsize, xdrproc_t xdrobj);
Like xdr_reference() except that it serializes null pointers, whereas xdr_reference() does not. Thus, xdr_pointer() can represent recursive data structures, such as binary trees or linked lists. iconic.
xdrrec_create π₯
void xdrrec_create(XDR *xdrs, unsigned int sendsize,
unsigned int recvsize, char *handle,
typeof(int (char *, char *, int)) *readit,
typeof(int (char *, char *, int)) *writeit);
This routine initializes the XDR stream object pointed to by xdrs. The stream's data is written to a buffer of size sendsize; a value of zero indicates the system should use a suitable default. The stream's data is read from a buffer of size recvsize; 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 calls read(2) and write(2), except that handle is passed to the former routines as the first argument. Note: the XDR stream's op 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. no cap, this is a real gotcha.
xdrrec_endofrecord π
bool_t xdrrec_endofrecord(XDR *xdrs, int sendnow);
This routine can be invoked only on streams created by xdrrec_create(). The data in the output buffer is marked as a completed record, and the output buffer is optionally written out if sendnow is nonzero. This routine returns one if it succeeds, zero otherwise.
xdrrec_eof π¦
bool_t xdrrec_eof(XDR *xdrs);
This routine can be invoked only on streams created by 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.
xdrrec_skiprecord π§
bool_t xdrrec_skiprecord(XDR *xdrs);
This routine can be invoked only on streams created by xdrrec_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.
xdr_reference π
bool_t xdr_reference(XDR *xdrs, char **pp, unsigned int size,
xdrproc_t proc);
A primitive that provides pointer chasing within structures. The argument pp is the address of the pointer; size is the sizeof the structure that *pp points to; and proc 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. Use xdr_pointer() instead. bestie, please.
xdr_setpos π
xdr_setpos(XDR *xdrs, unsigned int pos);
A macro that invokes the set position routine associated with the XDR stream xdrs. The argument pos is a position value obtained from xdr_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. so don't assume it'll work everywhere.
xdr_short πΈ
bool_t xdr_short(XDR *xdrs, short *sp);
A filter primitive that translates between C short integers and their external representations. This routine returns one if it succeeds, zero otherwise.
xdrstdio_create π
void xdrstdio_create(XDR *xdrs, FILE *file, enum xdr_op op);
This routine initializes the XDR stream object pointed to by xdrs. The XDR stream data is written to, or read from, the stdio stream file. The argument op determines the direction of the XDR stream (either XDR_ENCODE, XDR_DECODE, or XDR_FREE).
Warning: the destroy routine associated with such XDR streams callsfflush(3)on the file stream, but neverfclose(3). so don't expect it to close your file for you, okay?
xdr_string π
bool_t xdr_string(XDR *xdrs, char **sp, unsigned int maxsize);
A filter primitive that translates between C strings and their corresponding external representations. Strings cannot be longer than maxsize. Note: sp is the address of the string's pointer. This routine returns one if it succeeds, zero otherwise.
xdr_u_char π«
bool_t xdr_u_char(XDR *xdrs, unsigned char *ucp);
So like, right after that signature up there π β the one for the unsigned-char translator β here's the tea:
xdr_u_char()β lowkey the same deal but forunsigned C charactersand their external representations. Returns one if it wins, zero if it doesn't. That's it, that's the whole vibe. π«bool_t xdr_u_int(XDR *xdrs, unsigned int *up);
A filter primitive that's out here translating between C unsigned integers and their external representations. Returns one if it succeeds, zero otherwise. No in-between, no maybe. π―
bool_t xdr_u_long(XDR *xdrs, unsigned long *ulp);
Same energy, bigger numbers: a filter primitive translating between C unsigned long integers and their external representations. Returns one if it succeeds, zero otherwise. π
bool_t xdr_u_short(XDR *xdrs, unsigned short *usp);
And the short king version: a filter primitive translating between C unsigned short integers and their external representations. Returns one if it succeeds, zero otherwise. π
bool_t xdr_union(XDR *xdrs, enum_t *dscmp, char *unp, const struct xdr_discrim *choices, xdrproc_t defaultarm); /* may equal NULL */
Okay bestie this one's the main character of the whole list, so sit with me. π It's a filter primitive that translates between a discriminated C union and its corresponding external representation. Here's the order of operations:
- First it translates the discriminant of the union, which lives at
dscmp. That discriminant is always anenum_t, no exceptions, that's just the law. - Next the union at
unpgets translated. - The
choicesargument is a pointer to an array ofxdr_discrim()structures. Each one of those little guys holds an ordered pair of[value,proc]. So if the union's discriminant equals the associatedvalue, then thatprocgets called to translate the union. - The end of the
xdr_discrim()structure array is marked by a routine of valueNULLβ like a little "that's all folks" flag. π© - But what if the discriminant isn't in the
choicesarray at all?? Then thedefaultarmprocedure gets called, if it is notNULL(remember,defaultarmmay equalNULL).
Returns one if it succeeds, zero otherwise. Periodt.
bool_t xdr_vector(XDR *xdrs, char *arrp, unsigned int size, unsigned int elsize, xdrproc_t elproc);
Fixed-length arrays' best friend fr fr. This filter primitive translates between fixed-length arrays and their corresponding external representations. Break it down:
arrpis the address of the pointer to the array.sizeis the element count of the array.elsizeis thesizeofeach of the array's elements.elprocis an XDR filter that translates between the array elements' C form and their external representation.
Returns one if it succeeds, zero otherwise. π
bool_t xdr_void(void);
The chillest routine in the game. It always returns one. Like, always. Its whole purpose in life is that it may be passed to RPC routines that require a function argument where nothing is to be done. A true "I'm just here for moral support" icon. β¨
bool_t xdr_wrapstring(XDR *xdrs, char **sp);
A primitive that calls xdr_string(xdrs, sp,MAXUN.UNSIGNED ) β and yes, MAXUN.UNSIGNED is the maximum value of an unsigned integer. Why does this exist, you ask? Because xdr_wrapstring() is handy: the RPC package passes a maximum of two XDR routines as arguments, and xdr_string() β one of the most frequently used primitives β needs three. So this is the little wrapper that makes it fit. Returns one if it succeeds, zero otherwise. π«Ά
not me being genuinely obsessed with xdr_wrapstring() for solving a "too many arguments" problem by just... existing. iconic behavior, honestly.
π ATTRIBUTES π
For an explanation of the terms used in this section, see attributes(7).
So here's the vibe check on thread safety, bestie β every single one of these is MT-Safe. Yes, all of them. The whole squad. π
- Interface:
xdr_array(),xdr_bool(),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() - Attribute: Thread safety
- Value:
MT-Safe
π SEE ALSO π
And also the following manuals, because we stay educated πβ¨:
eXternal Data Representation Standard: Protocol SpecificationeXternal Data Representation: Sun Technical NotesXDR: External Data Representation Standard, RFC 1014, Sun Microsystems, Inc., USC-ISI.
okay that's the whole page bestie, you're officially XDR-pilled π§ Go translate something into an external representation and slay π
this lil writeup lives in Linux man-pages 6.20, dated 2025-09-21, and it's the xdr(3) page π bye ily π¦
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms