Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/ntirpc/rpc/xdr.h
$ cat -n /usr/include/ntirpc/rpc/xdr.h 1 /* $NetBSD: xdr.h,v 1.19 2000/07/17 05:00:45 matt Exp $ */ 2 3 /* 4 * Copyright (c) 2009, Sun Microsystems, Inc. 5 * Copyright (c) 2010-2018 Red Hat, Inc. and/or its affiliates. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * - Redistributions of source code must retain the above copyright notice, 11 * this list of conditions and the following disclaimer. 12 * - Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * - Neither the name of Sun Microsystems, Inc. nor the names of its 16 * contributors may be used to endorse or promote products derived 17 * from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 * from: @(#)xdr.h 1.19 87/04/22 SMI 32 * from: @(#)xdr.h 2.2 88/07/29 4.0 RPCSRC 33 * $FreeBSD: src/include/rpc/xdr.h,v 1.23 2003/03/07 13:19:40 nectar Exp $ 34 */ 35 36 /* 37 * xdr.h, External Data Representation Serialization Routines. 38 * 39 * Copyright (C) 1984, Sun Microsystems, Inc. 40 */ 41 42 #ifndef _TIRPC_XDR_H 43 #define _TIRPC_XDR_H 44 45 #include
46 #include
47 #include
48 #if !defined(_WIN32) 49 #include
50 #endif 51 #include
52 #include
53 54 /* 55 * XDR provides a conventional way for converting between C data 56 * types and an external bit-string representation. Library supplied 57 * routines provide for the conversion on built-in C data types. These 58 * routines and utility routines defined here are used to help implement 59 * a type encode/decode routine for each user-defined type. 60 * 61 * Each data type provides a single procedure which takes two arguments: 62 * 63 * bool 64 * xdrproc(xdrs, argresp) 65 * XDR *xdrs; 66 *
*argresp; 67 * 68 * xdrs is an instance of a XDR handle, to which or from which the data 69 * type is to be converted. argresp is a pointer to the structure to be 70 * converted. The XDR handle contains an operation field which indicates 71 * which of the operations (ENCODE, DECODE * or FREE) is to be performed. 72 * 73 * XDR_DECODE may allocate space if the pointer argresp is null. This 74 * data can be freed with the XDR_FREE operation. 75 * 76 * We write only one procedure per data type to make it easy 77 * to keep the encode and decode procedures for a data type consistent. 78 * In many cases the same code performs all operations on a user defined type, 79 * because all the hard work is done in the component type routines. 80 * decode as a series of calls on the nested data types. 81 */ 82 83 /* 84 * Xdr operations. XDR_ENCODE causes the type to be encoded into the 85 * stream. XDR_DECODE causes the type to be extracted from the stream. 86 * XDR_FREE can be used to release the space allocated by an XDR_DECODE 87 * request. 88 */ 89 enum xdr_op { 90 XDR_ENCODE = 0, 91 XDR_DECODE = 1, 92 XDR_FREE = 2 93 }; 94 95 /* 96 * This is the number of bytes per unit of external data. 97 */ 98 #define BYTES_PER_XDR_UNIT (4) 99 100 /* 101 * constants specific to the xdr "protocol" 102 */ 103 #define XDR_FALSE (0) 104 #define XDR_TRUE (1) 105 106 /* Taken verbatim from a system xdr.h, which carries a BSD-style 107 * license (Matt) */ 108 /* 109 * This only works if the above is a power of 2. But it's defined to be 110 * 4 by the appropriate RFCs. So it will work. And it's normally quicker 111 * than the old routine. 112 */ 113 #if 1 114 #define RNDUP(x) (((x) + BYTES_PER_XDR_UNIT - 1) & ~(BYTES_PER_XDR_UNIT - 1)) 115 #else /* this is the old routine */ 116 #define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \ 117 * BYTES_PER_XDR_UNIT) 118 #endif 119 120 /* XDR vector buffer types */ 121 typedef enum vio_type { 122 VIO_HEADER, /* header buffer before data */ 123 VIO_DATA, /* data buffer */ 124 VIO_TRAILER_LEN, /* length field for following TRAILER buffer */ 125 VIO_TRAILER, /* trailer buffer after data */ 126 } vio_type; 127 128 /* XDR buffer vector descriptors */ 129 typedef struct xdr_vio { 130 uint8_t *vio_base; 131 uint8_t *vio_head; /* minimum vio_tail (header offset) */ 132 uint8_t *vio_tail; /* end of the used part of the buffer */ 133 uint8_t *vio_wrap; /* maximum vio_tail */ 134 uint32_t vio_length; /* length of buffer, used for vector 135 pre-allocation */ 136 vio_type vio_type; /* type of buffer */ 137 } xdr_vio; 138 139 /* vio_wrap >= vio_tail >= vio_head >= vio_base */ 140 141 #define UIO_FLAG_NONE 0x0000 142 #define UIO_FLAG_BUFQ 0x0001 143 #define UIO_FLAG_FREE 0x0002 144 #define UIO_FLAG_GIFT 0x0004 145 #define UIO_FLAG_MORE 0x0008 146 #define UIO_FLAG_REALLOC 0x0010 147 #define UIO_FLAG_REFER 0x0020 148 149 struct xdr_uio; 150 typedef void (*xdr_uio_release)(struct xdr_uio *, u_int); 151 152 typedef struct xdr_uio { 153 struct xdr_uio *uio_refer; 154 xdr_uio_release uio_release; 155 void *uio_p1; 156 void *uio_p2; 157 void *uio_u1; 158 void *uio_u2; 159 160 size_t uio_count; /* count of entries in vio array, 161 * 0: not allocated */ 162 u_int uio_flags; 163 int32_t uio_references; 164 xdr_vio uio_vio[0]; /* appended vectors */ 165 } xdr_uio; 166 167 /* Op flags */ 168 #define XDR_PUTBUFS_FLAG_NONE 0x0000 169 #define XDR_PUTBUFS_FLAG_RDNLY 0x0001 170 171 #define XDR_FLAG_NONE 0x0000 172 #define XDR_FLAG_CKSUM 0x0001 173 #define XDR_FLAG_FREE 0x0002 174 #define XDR_FLAG_VIO 0x0004 175 176 /* 177 * The XDR handle. 178 * Contains operation which is being applied to the stream, 179 * an operations vector for the particular implementation (e.g. see xdr_mem.c), 180 * and two private fields for the use of the particular implementation. 181 * XXX: w/64-bit pointers, u_int not enough! 182 */ 183 typedef struct rpc_xdr { 184 const struct xdr_ops { 185 /* get 4 unsigned bytes from underlying stream */ 186 bool (*x_getunit)(struct rpc_xdr *, uint32_t *); 187 /* put 4 unsigned bytes to underlying stream */ 188 bool (*x_putunit)(struct rpc_xdr *, const uint32_t); 189 /* get some bytes from " */ 190 bool (*x_getbytes)(struct rpc_xdr *, char *, u_int); 191 /* put some bytes to " */ 192 bool (*x_putbytes)(struct rpc_xdr *, const char *, u_int); 193 /* returns bytes off from beginning */ 194 u_int (*x_getpostn)(struct rpc_xdr *); 195 /* lets you reposition the stream */ 196 bool (*x_setpostn)(struct rpc_xdr *, u_int); 197 /* free private resources of this xdr_stream */ 198 void (*x_destroy)(struct rpc_xdr *); 199 bool (*x_control)(struct rpc_xdr *, int, void *); 200 /* new vector and refcounted interfaces */ 201 bool (*x_getbufs)(struct rpc_xdr *, xdr_uio *, u_int); 202 bool (*x_putbufs)(struct rpc_xdr *, xdr_uio *, u_int); 203 /* Force a new buffer to start (or fail) */ 204 bool (*x_newbuf)(struct rpc_xdr *); 205 /* Return the count of buffers in the vector from pos */ 206 int (*x_iovcount)(struct rpc_xdr *, u_int, u_int); 207 /* Fill xdr_vio with buffers from pos */ 208 bool (*x_fillbufs)(struct rpc_xdr *, u_int , xdr_vio *, u_int); 209 /* Allocate bufs for headers and trailers and insert into vio */ 210 bool (*x_allochdrs)(struct rpc_xdr *, u_int , xdr_vio *, int); 211 } *x_ops; 212 void *x_public; /* users' data */ 213 void *x_private; /* pointer to private data */ 214 void *x_lib[2]; /* RPC library private */ 215 uint8_t *x_data; /* private used for position inline */ 216 void *x_base; /* private used for position info */ 217 struct xdr_vio x_v; /* private buffer vector */ 218 u_int x_handy; /* extra private word */ 219 u_int x_flags; /* shared flags */ 220 enum xdr_op x_op; /* operation; fast additional param */ 221 } XDR; 222 223 #define XDR_VIO(x) ((xdr_vio *)((x)->x_base)) 224 225 static inline size_t 226 xdr_size_inline(XDR *xdrs) 227 { 228 return ((uintptr_t)xdrs->x_v.vio_wrap - (uintptr_t)xdrs->x_data); 229 } 230 231 static inline size_t 232 xdr_tail_inline(XDR *xdrs) 233 { 234 return ((uintptr_t)xdrs->x_v.vio_tail - (uintptr_t)xdrs->x_data); 235 } 236 237 static inline void 238 xdr_tail_update(XDR *xdrs) 239 { 240 if ((uintptr_t)xdrs->x_v.vio_tail < (uintptr_t)xdrs->x_data) { 241 xdrs->x_v.vio_tail = xdrs->x_data; 242 XDR_VIO(xdrs)->vio_tail = xdrs->x_data; 243 } 244 } 245 246 /* 247 * A xdrproc_t exists for each data type which is to be encoded or decoded. 248 * 249 * The second argument to the xdrproc_t is a pointer to an opaque pointer. 250 * The opaque pointer generally points to a structure of the data type 251 * to be decoded. If this pointer is 0, then the type routines should 252 * allocate dynamic storage of the appropriate size and return it. 253 */ 254 typedef bool(*xdrproc_t) (XDR *, void *); 255 256 /* 257 * Operations defined on a XDR handle 258 * 259 * XDR *xdrs; 260 * long *longp; 261 * char * addr; 262 * u_int len; 263 * u_int pos; 264 */ 265 266 #define char_ptr(x) ((char*)(x)) 267 268 static inline bool 269 xdr_getlong(XDR *xdrs, long *lp) 270 { 271 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 272 uint32_t u; 273 bool b; 274 275 if (future <= xdrs->x_v.vio_tail) { 276 *lp = (long)ntohl(*((uint32_t *) (xdrs->x_data))); 277 xdrs->x_data = future; 278 return (true); 279 } 280 281 b = (*xdrs->x_ops->x_getunit)(xdrs, &u); 282 if (b) { 283 *lp = (int32_t)u; /* sign extends */ 284 } 285 return b; 286 } 287 288 static inline bool 289 xdr_putlong(XDR *xdrs, const long *lp) 290 { 291 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 292 293 if (future <= xdrs->x_v.vio_wrap) { 294 *((int32_t *) (xdrs->x_data)) = 295 (int32_t) htonl((int32_t) (*lp)); 296 xdrs->x_data = future; 297 return (true); 298 } 299 return (*xdrs->x_ops->x_putunit)(xdrs, (uint32_t) (*lp)); 300 } 301 302 #define XDR_GETLONG(xdrs, lp) xdr_getlong(xdrs, lp) 303 #define XDR_PUTLONG(xdrs, lp) xdr_putlong(xdrs, lp) 304 305 #define XDR_GETBYTES(xdrs, addr, len) \ 306 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) 307 #define xdr_getbytes(xdrs, addr, len) \ 308 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) 309 310 #define XDR_PUTBYTES(xdrs, addr, len) \ 311 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) 312 #define xdr_putbytes(xdrs, addr, len) \ 313 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) 314 315 #define XDR_GETBUFS(xdrs, uio, len, flags) \ 316 (*(xdrs)->x_ops->x_getbufs)(xdrs, uio, len, flags) 317 #define xdr_getbufs(xdrs, uio, len, flags) \ 318 (*(xdrs)->x_ops->x_getbufs)(xdrs, uio, len, flags) 319 320 #define XDR_PUTBUFS(xdrs, uio, flags) \ 321 (*(xdrs)->x_ops->x_putbufs)(xdrs, uio, flags) 322 #define xdr_putbufs(xdrs, uio, flags) \ 323 (*(xdrs)->x_ops->x_putbufs)(xdrs, uio, flags) 324 325 #define XDR_GETPOS(xdrs) \ 326 (*(xdrs)->x_ops->x_getpostn)(xdrs) 327 #define xdr_getpos(xdrs) \ 328 (*(xdrs)->x_ops->x_getpostn)(xdrs) 329 330 #define XDR_SETPOS(xdrs, pos) \ 331 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) 332 #define xdr_setpos(xdrs, pos) \ 333 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) 334 335 #define XDR_DESTROY(xdrs) \ 336 if ((xdrs)->x_ops->x_destroy) \ 337 (*(xdrs)->x_ops->x_destroy)(xdrs) 338 #define xdr_destroy(xdrs) \ 339 if ((xdrs)->x_ops->x_destroy) \ 340 (*(xdrs)->x_ops->x_destroy)(xdrs) 341 342 #define XDR_CONTROL(xdrs, req, op) \ 343 if ((xdrs)->x_ops->x_control) \ 344 (*(xdrs)->x_ops->x_control)(xdrs, req, op) 345 #define xdr_control(xdrs, req, op) XDR_CONTROL(xdrs, req, op) 346 347 #define XDR_NEWBUF(xdrs) \ 348 (*(xdrs)->x_ops->x_newbuf)(xdrs) 349 #define xdr_newbuf(xdrs, pos) XDR_NEWBUF(xdrs) 350 351 #define XDR_IOVCOUNT(xdrs, pos, len) \ 352 (*(xdrs)->x_ops->x_iovcount)(xdrs, pos, len) 353 #define xdr_iovcount(xdrs, pos, len) XDR_IOVCOUNT(xdrs, pos, len) 354 355 #define XDR_FILLBUFS(xdrs, pos, iov, len) \ 356 (*(xdrs)->x_ops->x_fillbufs)(xdrs, pos, iov, len) 357 #define xdr_fillbufs(xdrs, pos, iov, len) XDR_FILLBUFS(xdrs, pos, iov, len) 358 359 #define XDR_ALLOCHDRS(xdrs, pos, iov, iov_count) \ 360 (*(xdrs)->x_ops->x_allochdrs)(xdrs, pos, iov, iov_count) 361 #define xdr_allochdrs(xdrs, pos, iov, iov_count) \ 362 XDR_ALLOCHDRS(xdrs, pos, iov, iov_count) 363 364 /* 365 * Support struct for discriminated unions. 366 * You create an array of xdrdiscrim structures, terminated with 367 * an entry with a null procedure pointer. The xdr_union routine gets 368 * the discriminant value and then searches the array of structures 369 * for a matching value. If a match is found the associated xdr routine 370 * is called to handle that part of the union. If there is 371 * no match, then a default routine may be called. 372 * If there is no match and no default routine it is an error. 373 */ 374 #define NULL_xdrproc_t ((xdrproc_t)0) 375 struct xdr_discrim { 376 int value; 377 xdrproc_t proc; 378 }; 379 380 /* 381 * In-line routines for fast encode/decode of primitive data types. 382 * Caveat emptor: these use single memory cycles to get the 383 * data from the underlying buffer, and will fail to operate 384 * properly where the data is not aligned. The standard way to use 385 * these is to say: 386 * if ((buf = xdr_inline_decode(xdrs, count)) == NULL) 387 * return (FALSE); 388 * <<< IXDR_GET_* macro calls >>> 389 * if ((buf = xdr_inline_encode(xdrs, count)) == NULL) 390 * return (FALSE); 391 * <<< IXDR_PUT_* macro calls >>> 392 * where ``count'' is the number of bytes of data occupied 393 * by the primitive data types. 394 * 395 * N.B. and frozen for all time: each data type here uses 4 bytes 396 * of external representation. 397 */ 398 static inline int32_t * 399 xdr_inline_decode(XDR *xdrs, size_t count) 400 { 401 int32_t *buf = (int32_t *)xdrs->x_data; 402 uint8_t *future = xdrs->x_data + count; 403 404 /* re-consuming bytes in a stream 405 * (after SETPOS/rewind) */ 406 if (future <= xdrs->x_v.vio_tail) { 407 xdrs->x_data = future; 408 return (buf); 409 } 410 return (NULL); 411 } 412 413 static inline int32_t * 414 xdr_inline_encode(XDR *xdrs, size_t count) 415 { 416 int32_t *buf = (int32_t *)xdrs->x_data; 417 uint8_t *future = xdrs->x_data + count; 418 419 if (future <= xdrs->x_v.vio_wrap) { 420 xdrs->x_data = future; 421 xdr_tail_update(xdrs); 422 return (buf); 423 } 424 return (NULL); 425 } 426 427 #define IXDR_GET_INT32(buf) ((int32_t)ntohl((u_int32_t)*(buf)++)) 428 #define IXDR_PUT_INT32(buf, v) (*(buf)++ = (int32_t)htonl((u_int32_t)v)) 429 #define IXDR_GET_U_INT32(buf) ((u_int32_t)IXDR_GET_INT32(buf)) 430 #define IXDR_PUT_U_INT32(buf, v) IXDR_PUT_INT32((buf), ((int32_t)(v))) 431 432 #define IXDR_GET_LONG(buf) ((long)ntohl((u_int32_t)*(buf)++)) 433 #define IXDR_PUT_LONG(buf, v) (*(buf)++ = (int32_t)htonl((u_int32_t)v)) 434 435 #define IXDR_GET_BOOL(buf) ((bool)IXDR_GET_LONG(buf)) 436 #define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf)) 437 #define IXDR_GET_U_LONG(buf) ((u_long)IXDR_GET_LONG(buf)) 438 439 #define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), (v)) 440 #define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), (v)) 441 #define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), (v)) 442 443 /* 444 * In-line routines for vector encode/decode of primitive data types. 445 * Intermediate speed, avoids function calls in most cases, at the expense of 446 * checking the remaining space available for each item. 447 * 448 * Caveat emptor: these use single memory cycles to get the 449 * data from the underlying buffer, and will fail to operate 450 * properly where the data is not aligned. 451 * 452 * if (!FUNCTION(xdrs, &variable)) { 453 * print(warning); 454 * return (false); 455 * } 456 * 457 * N.B. and frozen for all time: each data type here uses 4 bytes 458 * of external representation. 459 */ 460 461 static inline bool 462 xdr_getuint32(XDR *xdrs, uint32_t *ip) 463 { 464 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 465 466 if (future <= xdrs->x_v.vio_tail) { 467 *ip = ntohl(*((uint32_t *) (xdrs->x_data))); 468 xdrs->x_data = future; 469 return (true); 470 } 471 return (*xdrs->x_ops->x_getunit)(xdrs, ip); 472 } 473 474 static inline bool 475 xdr_putuint32(XDR *xdrs, uint32_t v) 476 { 477 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 478 479 if (future <= xdrs->x_v.vio_wrap) { 480 *((int32_t *) (xdrs->x_data)) = htonl(v); 481 xdrs->x_data = future; 482 return (true); 483 } 484 return (*xdrs->x_ops->x_putunit)(xdrs, v); 485 } 486 487 #define XDR_GETUINT32(xdrs, uint32p) xdr_getuint32(xdrs, uint32p) 488 #define XDR_PUTUINT32(xdrs, uint32v) xdr_putuint32(xdrs, uint32v) 489 490 static inline bool 491 xdr_getint32(XDR *xdrs, int32_t *ip) 492 { 493 return xdr_getuint32(xdrs, (uint32_t *)ip); 494 } 495 496 static inline bool 497 xdr_putint32(XDR *xdrs, int32_t v) 498 { 499 return xdr_putuint32(xdrs, (uint32_t)v); 500 } 501 502 #define XDR_GETINT32(xdrs, int32p) xdr_getint32(xdrs, int32p) 503 #define XDR_PUTINT32(xdrs, int32v) xdr_putint32(xdrs, int32v) 504 505 static inline bool 506 xdr_getuint16(XDR *xdrs, uint16_t *ip) 507 { 508 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 509 uint32_t u; 510 511 if (future <= xdrs->x_v.vio_tail) { 512 *ip = (uint16_t)ntohl(*((uint32_t *) (xdrs->x_data))); 513 xdrs->x_data = future; 514 return (true); 515 } 516 if ((*xdrs->x_ops->x_getunit)(xdrs, &u)) { 517 *ip = (uint16_t) u; 518 return (true); 519 } 520 return (false); 521 } 522 523 static inline bool 524 xdr_putuint16(XDR *xdrs, uint32_t uint16v) 525 { 526 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 527 528 if (future <= xdrs->x_v.vio_wrap) { 529 *((int32_t *) (xdrs->x_data)) = htonl(uint16v); 530 xdrs->x_data = future; 531 return (true); 532 } 533 return (*xdrs->x_ops->x_putunit)(xdrs, (uint32_t)uint16v); 534 } 535 536 #define XDR_GETUINT16(xdrs, uint16p) xdr_getuint16(xdrs, uint16p) 537 #define XDR_PUTUINT16(xdrs, uint16v) xdr_putuint16(xdrs, uint16v) 538 539 static inline bool 540 xdr_getint16(XDR *xdrs, int16_t *ip) 541 { 542 return xdr_getuint16(xdrs, (uint16_t *)ip); 543 } 544 545 /* extend sign before storage */ 546 static inline bool 547 xdr_putint16(XDR *xdrs, int32_t int16v) 548 { 549 return xdr_putuint16(xdrs, (uint16_t)int16v); 550 } 551 552 #define XDR_GETINT16(xdrs, int16p) xdr_getint16(xdrs, int16p) 553 #define XDR_PUTINT16(xdrs, int16v) xdr_putint16(xdrs, int16v) 554 555 static inline bool 556 xdr_getuint8(XDR *xdrs, uint8_t *ip) 557 { 558 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 559 uint32_t u; 560 561 if (future <= xdrs->x_v.vio_tail) { 562 *ip = (uint8_t)ntohl(*((uint32_t *) (xdrs->x_data))); 563 xdrs->x_data = future; 564 return (true); 565 } 566 if ((*xdrs->x_ops->x_getunit)(xdrs, &u)) { 567 *ip = (uint8_t) u; 568 return (true); 569 } 570 return (false); 571 } 572 573 static inline bool 574 xdr_putuint8(XDR *xdrs, uint32_t uint8v) 575 { 576 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 577 578 if (future <= xdrs->x_v.vio_wrap) { 579 *((int32_t *) (xdrs->x_data)) = htonl(uint8v); 580 xdrs->x_data = future; 581 return (true); 582 } 583 return (*xdrs->x_ops->x_putunit)(xdrs, (uint32_t)uint8v); 584 } 585 586 #define XDR_GETUINT8(xdrs, uint8p) xdr_getuint8(xdrs, uint8p) 587 #define XDR_PUTUINT8(xdrs, uint8v) xdr_putuint8(xdrs, uint8v) 588 589 static inline bool 590 xdr_getint8(XDR *xdrs, int8_t *ip) 591 { 592 return xdr_getuint8(xdrs, (uint8_t *)ip); 593 } 594 595 /* extend sign before storage */ 596 static inline bool 597 xdr_putint8(XDR *xdrs, int32_t int8v) 598 { 599 return xdr_putuint8(xdrs, (uint8_t)int8v); 600 } 601 602 #define XDR_GETINT8(xdrs, int8p) xdr_getint8(xdrs, int8p) 603 #define XDR_PUTINT8(xdrs, int8v) xdr_putint8(xdrs, int8v) 604 605 static inline bool 606 xdr_getenum(XDR *xdrs, enum_t *ip) 607 { 608 return xdr_getint32(xdrs, (int32_t *)ip); 609 } 610 611 static inline bool 612 xdr_putenum(XDR *xdrs, enum_t enumv) 613 { 614 return xdr_putint32(xdrs, (int32_t)enumv); 615 } 616 617 #define XDR_GETENUM(xdrs, enump) xdr_getenum(xdrs, enump) 618 #define XDR_PUTENUM(xdrs, enumv) xdr_putenum(xdrs, enumv) 619 620 static inline bool 621 xdr_getbool(XDR *xdrs, bool_t *ip) 622 { 623 int32_t lv; 624 625 if (!xdr_getint32(xdrs, &lv)) 626 return (false); 627 *ip = lv ? XDR_TRUE : XDR_FALSE; 628 return (true); 629 } 630 631 static inline bool 632 xdr_putbool(XDR *xdrs, bool_t boolv) 633 { 634 return xdr_putint32(xdrs, boolv ? XDR_TRUE : XDR_FALSE); 635 } 636 637 #define XDR_GETBOOL(xdrs, boolp) xdr_getbool(xdrs, boolp) 638 #define XDR_PUTBOOL(xdrs, boolv) xdr_putbool(xdrs, boolv) 639 640 /* 641 * These are the "generic" xdr routines. 642 */ 643 __BEGIN_DECLS 644 extern XDR xdr_free_null_stream; 645 646 extern bool xdr_void(XDR *, void *); 647 extern bool xdr_int(XDR *, int *); 648 extern bool xdr_u_int(XDR *, u_int *); 649 extern bool xdr_long(XDR *, long *); 650 extern bool xdr_u_long(XDR *, u_long *); 651 extern bool xdr_float(XDR *, float *); 652 extern bool xdr_double(XDR *, double *); 653 extern bool xdr_reference(XDR *, void **, u_int, xdrproc_t); 654 extern bool xdr_pointer(XDR *, void **, u_int, xdrproc_t); 655 extern bool xdr_wrapstring(XDR *, char **); 656 extern bool xdr_longlong_t(XDR *, quad_t *); 657 extern bool xdr_u_longlong_t(XDR *, u_quad_t *); 658 659 __END_DECLS 660 661 /* 662 * Free a data structure using XDR 663 * Not a filter, but a convenient utility nonetheless 664 */ 665 static inline bool 666 xdr_nfree(xdrproc_t proc, void *objp) 667 { 668 return (*proc) (&xdr_free_null_stream, objp); 669 } 670 671 /* 672 * Common opaque bytes objects used by many rpc protocols; 673 * declared here due to commonality. 674 */ 675 #define MAX_NETOBJ_SZ 1024 676 struct netobj { 677 u_int n_len; 678 char *n_bytes; 679 }; 680 typedef struct netobj netobj; 681 extern bool xdr_nnetobj(XDR *, struct netobj *); 682 683 /* 684 * These are the public routines for the various implementations of 685 * xdr streams. 686 */ 687 __BEGIN_DECLS 688 /* XDR using memory buffers */ 689 extern void xdrmem_ncreate(XDR *, char *, u_int, enum xdr_op); 690 691 /* intrinsic checksum (be careful) */ 692 extern uint64_t xdrmem_cksum(XDR *, u_int); 693 694 __END_DECLS 695 /* For backward compatibility */ 696 #include
697 #endif /* !_TIRPC_XDR_H */
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™