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 #ifdef _KERNEL 255 typedef bool(*xdrproc_t) (XDR *, void *, u_int); 256 #else 257 /* 258 * XXX can't actually prototype it, because some take three args!!! 259 */ 260 typedef bool(*xdrproc_t) (XDR *, ...); 261 #endif 262 263 /* 264 * Operations defined on a XDR handle 265 * 266 * XDR *xdrs; 267 * long *longp; 268 * char * addr; 269 * u_int len; 270 * u_int pos; 271 */ 272 273 #define char_ptr(x) ((char*)(x)) 274 275 static inline bool 276 xdr_getlong(XDR *xdrs, long *lp) 277 { 278 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 279 uint32_t u; 280 bool b; 281 282 if (future <= xdrs->x_v.vio_tail) { 283 *lp = (long)ntohl(*((uint32_t *) (xdrs->x_data))); 284 xdrs->x_data = future; 285 return (true); 286 } 287 288 b = (*xdrs->x_ops->x_getunit)(xdrs, &u); 289 if (b) { 290 *lp = (int32_t)u; /* sign extends */ 291 } 292 return b; 293 } 294 295 static inline bool 296 xdr_putlong(XDR *xdrs, const long *lp) 297 { 298 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 299 300 if (future <= xdrs->x_v.vio_wrap) { 301 *((int32_t *) (xdrs->x_data)) = 302 (int32_t) htonl((int32_t) (*lp)); 303 xdrs->x_data = future; 304 return (true); 305 } 306 return (*xdrs->x_ops->x_putunit)(xdrs, (uint32_t) (*lp)); 307 } 308 309 #define XDR_GETLONG(xdrs, lp) xdr_getlong(xdrs, lp) 310 #define XDR_PUTLONG(xdrs, lp) xdr_putlong(xdrs, lp) 311 312 #define XDR_GETBYTES(xdrs, addr, len) \ 313 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) 314 #define xdr_getbytes(xdrs, addr, len) \ 315 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) 316 317 #define XDR_PUTBYTES(xdrs, addr, len) \ 318 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) 319 #define xdr_putbytes(xdrs, addr, len) \ 320 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) 321 322 #define XDR_GETBUFS(xdrs, uio, len, flags) \ 323 (*(xdrs)->x_ops->x_getbufs)(xdrs, uio, len, flags) 324 #define xdr_getbufs(xdrs, uio, len, flags) \ 325 (*(xdrs)->x_ops->x_getbufs)(xdrs, uio, len, flags) 326 327 #define XDR_PUTBUFS(xdrs, uio, flags) \ 328 (*(xdrs)->x_ops->x_putbufs)(xdrs, uio, flags) 329 #define xdr_putbufs(xdrs, uio, flags) \ 330 (*(xdrs)->x_ops->x_putbufs)(xdrs, uio, flags) 331 332 #define XDR_GETPOS(xdrs) \ 333 (*(xdrs)->x_ops->x_getpostn)(xdrs) 334 #define xdr_getpos(xdrs) \ 335 (*(xdrs)->x_ops->x_getpostn)(xdrs) 336 337 #define XDR_SETPOS(xdrs, pos) \ 338 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) 339 #define xdr_setpos(xdrs, pos) \ 340 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) 341 342 #define XDR_DESTROY(xdrs) \ 343 if ((xdrs)->x_ops->x_destroy) \ 344 (*(xdrs)->x_ops->x_destroy)(xdrs) 345 #define xdr_destroy(xdrs) \ 346 if ((xdrs)->x_ops->x_destroy) \ 347 (*(xdrs)->x_ops->x_destroy)(xdrs) 348 349 #define XDR_CONTROL(xdrs, req, op) \ 350 if ((xdrs)->x_ops->x_control) \ 351 (*(xdrs)->x_ops->x_control)(xdrs, req, op) 352 #define xdr_control(xdrs, req, op) XDR_CONTROL(xdrs, req, op) 353 354 #define XDR_NEWBUF(xdrs) \ 355 (*(xdrs)->x_ops->x_newbuf)(xdrs) 356 #define xdr_newbuf(xdrs, pos) XDR_NEWBUF(xdrs) 357 358 #define XDR_IOVCOUNT(xdrs, pos, len) \ 359 (*(xdrs)->x_ops->x_iovcount)(xdrs, pos, len) 360 #define xdr_iovcount(xdrs, pos, len) XDR_IOVCOUNT(xdrs, pos, len) 361 362 #define XDR_FILLBUFS(xdrs, pos, iov, len) \ 363 (*(xdrs)->x_ops->x_fillbufs)(xdrs, pos, iov, len) 364 #define xdr_fillbufs(xdrs, pos, iov, len) XDR_FILLBUFS(xdrs, pos, iov, len) 365 366 #define XDR_ALLOCHDRS(xdrs, pos, iov, iov_count) \ 367 (*(xdrs)->x_ops->x_allochdrs)(xdrs, pos, iov, iov_count) 368 #define xdr_allochdrs(xdrs, pos, iov, iov_count) \ 369 XDR_ALLOCHDRS(xdrs, pos, iov, iov_count) 370 371 /* 372 * Support struct for discriminated unions. 373 * You create an array of xdrdiscrim structures, terminated with 374 * an entry with a null procedure pointer. The xdr_union routine gets 375 * the discriminant value and then searches the array of structures 376 * for a matching value. If a match is found the associated xdr routine 377 * is called to handle that part of the union. If there is 378 * no match, then a default routine may be called. 379 * If there is no match and no default routine it is an error. 380 */ 381 #define NULL_xdrproc_t ((xdrproc_t)0) 382 struct xdr_discrim { 383 int value; 384 xdrproc_t proc; 385 }; 386 387 /* 388 * In-line routines for fast encode/decode of primitive data types. 389 * Caveat emptor: these use single memory cycles to get the 390 * data from the underlying buffer, and will fail to operate 391 * properly where the data is not aligned. The standard way to use 392 * these is to say: 393 * if ((buf = xdr_inline_decode(xdrs, count)) == NULL) 394 * return (FALSE); 395 * <<< IXDR_GET_* macro calls >>> 396 * if ((buf = xdr_inline_encode(xdrs, count)) == NULL) 397 * return (FALSE); 398 * <<< IXDR_PUT_* macro calls >>> 399 * where ``count'' is the number of bytes of data occupied 400 * by the primitive data types. 401 * 402 * N.B. and frozen for all time: each data type here uses 4 bytes 403 * of external representation. 404 */ 405 static inline int32_t * 406 xdr_inline_decode(XDR *xdrs, size_t count) 407 { 408 int32_t *buf = (int32_t *)xdrs->x_data; 409 uint8_t *future = xdrs->x_data + count; 410 411 /* re-consuming bytes in a stream 412 * (after SETPOS/rewind) */ 413 if (future <= xdrs->x_v.vio_tail) { 414 xdrs->x_data = future; 415 return (buf); 416 } 417 return (NULL); 418 } 419 420 static inline int32_t * 421 xdr_inline_encode(XDR *xdrs, size_t count) 422 { 423 int32_t *buf = (int32_t *)xdrs->x_data; 424 uint8_t *future = xdrs->x_data + count; 425 426 if (future <= xdrs->x_v.vio_wrap) { 427 xdrs->x_data = future; 428 xdr_tail_update(xdrs); 429 return (buf); 430 } 431 return (NULL); 432 } 433 434 #define IXDR_GET_INT32(buf) ((int32_t)ntohl((u_int32_t)*(buf)++)) 435 #define IXDR_PUT_INT32(buf, v) (*(buf)++ = (int32_t)htonl((u_int32_t)v)) 436 #define IXDR_GET_U_INT32(buf) ((u_int32_t)IXDR_GET_INT32(buf)) 437 #define IXDR_PUT_U_INT32(buf, v) IXDR_PUT_INT32((buf), ((int32_t)(v))) 438 439 #define IXDR_GET_LONG(buf) ((long)ntohl((u_int32_t)*(buf)++)) 440 #define IXDR_PUT_LONG(buf, v) (*(buf)++ = (int32_t)htonl((u_int32_t)v)) 441 442 #define IXDR_GET_BOOL(buf) ((bool)IXDR_GET_LONG(buf)) 443 #define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf)) 444 #define IXDR_GET_U_LONG(buf) ((u_long)IXDR_GET_LONG(buf)) 445 446 #define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), (v)) 447 #define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), (v)) 448 #define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), (v)) 449 450 /* 451 * In-line routines for vector encode/decode of primitive data types. 452 * Intermediate speed, avoids function calls in most cases, at the expense of 453 * checking the remaining space available for each item. 454 * 455 * Caveat emptor: these use single memory cycles to get the 456 * data from the underlying buffer, and will fail to operate 457 * properly where the data is not aligned. 458 * 459 * if (!FUNCTION(xdrs, &variable)) { 460 * print(warning); 461 * return (false); 462 * } 463 * 464 * N.B. and frozen for all time: each data type here uses 4 bytes 465 * of external representation. 466 */ 467 468 static inline bool 469 xdr_getuint32(XDR *xdrs, uint32_t *ip) 470 { 471 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 472 473 if (future <= xdrs->x_v.vio_tail) { 474 *ip = ntohl(*((uint32_t *) (xdrs->x_data))); 475 xdrs->x_data = future; 476 return (true); 477 } 478 return (*xdrs->x_ops->x_getunit)(xdrs, ip); 479 } 480 481 static inline bool 482 xdr_putuint32(XDR *xdrs, uint32_t v) 483 { 484 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 485 486 if (future <= xdrs->x_v.vio_wrap) { 487 *((int32_t *) (xdrs->x_data)) = htonl(v); 488 xdrs->x_data = future; 489 return (true); 490 } 491 return (*xdrs->x_ops->x_putunit)(xdrs, v); 492 } 493 494 #define XDR_GETUINT32(xdrs, uint32p) xdr_getuint32(xdrs, uint32p) 495 #define XDR_PUTUINT32(xdrs, uint32v) xdr_putuint32(xdrs, uint32v) 496 497 static inline bool 498 xdr_getint32(XDR *xdrs, int32_t *ip) 499 { 500 return xdr_getuint32(xdrs, (uint32_t *)ip); 501 } 502 503 static inline bool 504 xdr_putint32(XDR *xdrs, int32_t v) 505 { 506 return xdr_putuint32(xdrs, v); 507 } 508 509 #define XDR_GETINT32(xdrs, int32p) xdr_getint32(xdrs, int32p) 510 #define XDR_PUTINT32(xdrs, int32v) xdr_putint32(xdrs, int32v) 511 512 static inline bool 513 xdr_getuint16(XDR *xdrs, uint16_t *ip) 514 { 515 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 516 uint32_t u; 517 518 if (future <= xdrs->x_v.vio_tail) { 519 *ip = (uint16_t)ntohl(*((uint32_t *) (xdrs->x_data))); 520 xdrs->x_data = future; 521 return (true); 522 } 523 if ((*xdrs->x_ops->x_getunit)(xdrs, &u)) { 524 *ip = (uint16_t) u; 525 return (true); 526 } 527 return (false); 528 } 529 530 static inline bool 531 xdr_putuint16(XDR *xdrs, uint32_t uint16v) 532 { 533 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 534 535 if (future <= xdrs->x_v.vio_wrap) { 536 *((int32_t *) (xdrs->x_data)) = htonl(uint16v); 537 xdrs->x_data = future; 538 return (true); 539 } 540 return (*xdrs->x_ops->x_putunit)(xdrs, (uint32_t)uint16v); 541 } 542 543 #define XDR_GETUINT16(xdrs, uint16p) xdr_getuint16(xdrs, uint16p) 544 #define XDR_PUTUINT16(xdrs, uint16v) xdr_putuint16(xdrs, uint16v) 545 546 static inline bool 547 xdr_getint16(XDR *xdrs, int16_t *ip) 548 { 549 return xdr_getuint16(xdrs, (uint16_t *)ip); 550 } 551 552 /* extend sign before storage */ 553 static inline bool 554 xdr_putint16(XDR *xdrs, int32_t int16v) 555 { 556 return xdr_putuint16(xdrs, int16v); 557 } 558 559 #define XDR_GETINT16(xdrs, int16p) xdr_getint16(xdrs, int16p) 560 #define XDR_PUTINT16(xdrs, int16v) xdr_putint16(xdrs, int16v) 561 562 static inline bool 563 xdr_getuint8(XDR *xdrs, uint8_t *ip) 564 { 565 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 566 uint32_t u; 567 568 if (future <= xdrs->x_v.vio_tail) { 569 *ip = (uint8_t)ntohl(*((uint32_t *) (xdrs->x_data))); 570 xdrs->x_data = future; 571 return (true); 572 } 573 if ((*xdrs->x_ops->x_getunit)(xdrs, &u)) { 574 *ip = (uint8_t) u; 575 return (true); 576 } 577 return (false); 578 } 579 580 static inline bool 581 xdr_putuint8(XDR *xdrs, uint32_t uint8v) 582 { 583 uint8_t *future = xdrs->x_data + sizeof(uint32_t); 584 585 if (future <= xdrs->x_v.vio_wrap) { 586 *((int32_t *) (xdrs->x_data)) = htonl(uint8v); 587 xdrs->x_data = future; 588 return (true); 589 } 590 return (*xdrs->x_ops->x_putunit)(xdrs, (uint32_t)uint8v); 591 } 592 593 #define XDR_GETUINT8(xdrs, uint8p) xdr_getuint8(xdrs, uint8p) 594 #define XDR_PUTUINT8(xdrs, uint8v) xdr_putuint8(xdrs, uint8v) 595 596 static inline bool 597 xdr_getint8(XDR *xdrs, int8_t *ip) 598 { 599 return xdr_getuint8(xdrs, (uint8_t *)ip); 600 } 601 602 /* extend sign before storage */ 603 static inline bool 604 xdr_putint8(XDR *xdrs, int32_t int8v) 605 { 606 return xdr_putuint8(xdrs, int8v); 607 } 608 609 #define XDR_GETINT8(xdrs, int8p) xdr_getint8(xdrs, int8p) 610 #define XDR_PUTINT8(xdrs, int8v) xdr_putint8(xdrs, int8v) 611 612 static inline bool 613 xdr_getenum(XDR *xdrs, enum_t *ip) 614 { 615 return xdr_getuint32(xdrs, (uint32_t *)ip); 616 } 617 618 static inline bool 619 xdr_putenum(XDR *xdrs, enum_t enumv) 620 { 621 return xdr_putuint16(xdrs, (uint32_t)enumv); 622 } 623 624 #define XDR_GETENUM(xdrs, enump) xdr_getenum(xdrs, enump) 625 #define XDR_PUTENUM(xdrs, enumv) xdr_putenum(xdrs, enumv) 626 627 static inline bool 628 xdr_getbool(XDR *xdrs, bool_t *ip) 629 { 630 uint32_t lv; 631 632 if (!xdr_getuint32(xdrs, &lv)) 633 return (false); 634 *ip = lv ? XDR_TRUE : XDR_FALSE; 635 return (true); 636 } 637 638 static inline bool 639 xdr_putbool(XDR *xdrs, bool_t boolv) 640 { 641 return xdr_putuint16(xdrs, boolv ? XDR_TRUE : XDR_FALSE); 642 } 643 644 #define XDR_GETBOOL(xdrs, boolp) xdr_getbool(xdrs, boolp) 645 #define XDR_PUTBOOL(xdrs, boolv) xdr_putbool(xdrs, boolv) 646 647 /* 648 * These are the "generic" xdr routines. 649 */ 650 __BEGIN_DECLS 651 extern XDR xdr_free_null_stream; 652 653 extern bool xdr_void(void); 654 extern bool xdr_int(XDR *, int *); 655 extern bool xdr_u_int(XDR *, u_int *); 656 extern bool xdr_long(XDR *, long *); 657 extern bool xdr_u_long(XDR *, u_long *); 658 extern bool xdr_float(XDR *, float *); 659 extern bool xdr_double(XDR *, double *); 660 extern bool xdr_reference(XDR *, void **, u_int, xdrproc_t); 661 extern bool xdr_pointer(XDR *, void **, u_int, xdrproc_t); 662 extern bool xdr_wrapstring(XDR *, char **); 663 extern bool xdr_longlong_t(XDR *, quad_t *); 664 extern bool xdr_u_longlong_t(XDR *, u_quad_t *); 665 666 __END_DECLS 667 668 /* 669 * Free a data structure using XDR 670 * Not a filter, but a convenient utility nonetheless 671 */ 672 static inline bool 673 xdr_nfree(xdrproc_t proc, void *objp) 674 { 675 return (*proc) (&xdr_free_null_stream, objp); 676 } 677 678 /* 679 * Common opaque bytes objects used by many rpc protocols; 680 * declared here due to commonality. 681 */ 682 #define MAX_NETOBJ_SZ 1024 683 struct netobj { 684 u_int n_len; 685 char *n_bytes; 686 }; 687 typedef struct netobj netobj; 688 extern bool xdr_nnetobj(XDR *, struct netobj *); 689 690 /* 691 * These are the public routines for the various implementations of 692 * xdr streams. 693 */ 694 __BEGIN_DECLS 695 /* XDR using memory buffers */ 696 extern void xdrmem_ncreate(XDR *, char *, u_int, enum xdr_op); 697 698 /* intrinsic checksum (be careful) */ 699 extern uint64_t xdrmem_cksum(XDR *, u_int); 700 701 __END_DECLS 702 /* For backward compatibility */ 703 #include
704 #endif /* !_TIRPC_XDR_H */
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2024 MyWebUniversity.com ™