File indexing completed on 2025-01-18 10:13:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 #ifndef _TIRPC_XDR_H
0042 #define _TIRPC_XDR_H
0043 #include <stdio.h>
0044 #include <netinet/in.h>
0045
0046 #include <rpc/types.h>
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 enum xdr_op {
0084 XDR_ENCODE=0,
0085 XDR_DECODE=1,
0086 XDR_FREE=2
0087 };
0088
0089
0090
0091
0092 #define BYTES_PER_XDR_UNIT (4)
0093 #define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
0094 * BYTES_PER_XDR_UNIT)
0095
0096
0097
0098
0099
0100
0101
0102 typedef struct __rpc_xdr {
0103 enum xdr_op x_op;
0104 const struct xdr_ops {
0105
0106 bool_t (*x_getlong)(struct __rpc_xdr *, long *);
0107
0108 bool_t (*x_putlong)(struct __rpc_xdr *, const long *);
0109
0110 bool_t (*x_getbytes)(struct __rpc_xdr *, char *, u_int);
0111
0112 bool_t (*x_putbytes)(struct __rpc_xdr *, const char *, u_int);
0113
0114 u_int (*x_getpostn)(struct __rpc_xdr *);
0115
0116 bool_t (*x_setpostn)(struct __rpc_xdr *, u_int);
0117
0118 int32_t *(*x_inline)(struct __rpc_xdr *, u_int);
0119
0120 void (*x_destroy)(struct __rpc_xdr *);
0121 bool_t (*x_control)(struct __rpc_xdr *, int, void *);
0122 } *x_ops;
0123 char * x_public;
0124 void * x_private;
0125 char * x_base;
0126 u_int x_handy;
0127 } XDR;
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137 #ifdef _KERNEL
0138 typedef bool_t (*xdrproc_t)(XDR *, void *, u_int);
0139 #else
0140
0141
0142
0143 typedef bool_t (*xdrproc_t)(XDR *, ...);
0144 #endif
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155 #define XDR_GETLONG(xdrs, longp) \
0156 (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
0157 #define xdr_getlong(xdrs, longp) \
0158 (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
0159
0160 #define XDR_PUTLONG(xdrs, longp) \
0161 (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
0162 #define xdr_putlong(xdrs, longp) \
0163 (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
0164
0165 static __inline int
0166 xdr_getint32(XDR *xdrs, int32_t *ip)
0167 {
0168 long l;
0169
0170 if (!xdr_getlong(xdrs, &l))
0171 return (FALSE);
0172 *ip = (int32_t)l;
0173 return (TRUE);
0174 }
0175
0176 static __inline int
0177 xdr_putint32(XDR *xdrs, int32_t *ip)
0178 {
0179 long l;
0180
0181 l = (long)*ip;
0182 return xdr_putlong(xdrs, &l);
0183 }
0184
0185 #define XDR_GETINT32(xdrs, int32p) xdr_getint32(xdrs, int32p)
0186 #define XDR_PUTINT32(xdrs, int32p) xdr_putint32(xdrs, int32p)
0187
0188 #define XDR_GETBYTES(xdrs, addr, len) \
0189 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
0190 #define xdr_getbytes(xdrs, addr, len) \
0191 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
0192
0193 #define XDR_PUTBYTES(xdrs, addr, len) \
0194 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
0195 #define xdr_putbytes(xdrs, addr, len) \
0196 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
0197
0198 #define XDR_GETPOS(xdrs) \
0199 (*(xdrs)->x_ops->x_getpostn)(xdrs)
0200 #define xdr_getpos(xdrs) \
0201 (*(xdrs)->x_ops->x_getpostn)(xdrs)
0202
0203 #define XDR_SETPOS(xdrs, pos) \
0204 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
0205 #define xdr_setpos(xdrs, pos) \
0206 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
0207
0208 #define XDR_INLINE(xdrs, len) \
0209 (*(xdrs)->x_ops->x_inline)(xdrs, len)
0210 #define xdr_inline(xdrs, len) \
0211 (*(xdrs)->x_ops->x_inline)(xdrs, len)
0212
0213 #define XDR_DESTROY(xdrs) \
0214 if ((xdrs)->x_ops->x_destroy) \
0215 (*(xdrs)->x_ops->x_destroy)(xdrs)
0216 #define xdr_destroy(xdrs) \
0217 if ((xdrs)->x_ops->x_destroy) \
0218 (*(xdrs)->x_ops->x_destroy)(xdrs)
0219
0220 #define XDR_CONTROL(xdrs, req, op) \
0221 if ((xdrs)->x_ops->x_control) \
0222 (*(xdrs)->x_ops->x_control)(xdrs, req, op)
0223 #define xdr_control(xdrs, req, op) XDR_CONTROL(xdrs, req, op)
0224
0225 #define xdr_rpcvers(xdrs, versp) xdr_u_int32_t(xdrs, versp)
0226 #define xdr_rpcprog(xdrs, progp) xdr_u_int32_t(xdrs, progp)
0227 #define xdr_rpcproc(xdrs, procp) xdr_u_int32_t(xdrs, procp)
0228 #define xdr_rpcprot(xdrs, protp) xdr_u_int32_t(xdrs, protp)
0229 #define xdr_rpcport(xdrs, portp) xdr_u_int32_t(xdrs, portp)
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241 #define NULL_xdrproc_t ((xdrproc_t)0)
0242 struct xdr_discrim {
0243 int value;
0244 xdrproc_t proc;
0245 };
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262 #define IXDR_GET_INT32(buf) ((int32_t)ntohl((u_int32_t)*(buf)++))
0263 #define IXDR_PUT_INT32(buf, v) (*(buf)++ =(int32_t)htonl((u_int32_t)v))
0264 #define IXDR_GET_U_INT32(buf) ((u_int32_t)IXDR_GET_INT32(buf))
0265 #define IXDR_PUT_U_INT32(buf, v) IXDR_PUT_INT32((buf), ((int32_t)(v)))
0266
0267 #define IXDR_GET_LONG(buf) ((long)ntohl((u_int32_t)*(buf)++))
0268 #define IXDR_PUT_LONG(buf, v) (*(buf)++ =(int32_t)htonl((u_int32_t)v))
0269
0270 #define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf))
0271 #define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf))
0272 #define IXDR_GET_U_LONG(buf) ((u_long)IXDR_GET_LONG(buf))
0273 #define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf))
0274 #define IXDR_GET_U_SHORT(buf) ((u_short)IXDR_GET_LONG(buf))
0275
0276 #define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), (v))
0277 #define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), (v))
0278 #define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), (v))
0279 #define IXDR_PUT_SHORT(buf, v) IXDR_PUT_LONG((buf), (v))
0280 #define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_LONG((buf), (v))
0281
0282
0283
0284
0285 #ifdef __cplusplus
0286 extern "C" {
0287 #endif
0288 extern bool_t xdr_void(void);
0289 extern bool_t xdr_int(XDR *, int *);
0290 extern bool_t xdr_u_int(XDR *, u_int *);
0291 extern bool_t xdr_long(XDR *, long *);
0292 extern bool_t xdr_u_long(XDR *, u_long *);
0293 extern bool_t xdr_short(XDR *, short *);
0294 extern bool_t xdr_u_short(XDR *, u_short *);
0295 extern bool_t xdr_int8_t(XDR *, int8_t *);
0296 extern bool_t xdr_u_int8_t(XDR *, uint8_t *);
0297 extern bool_t xdr_uint8_t(XDR *, uint8_t *);
0298 extern bool_t xdr_int16_t(XDR *, int16_t *);
0299 extern bool_t xdr_u_int16_t(XDR *, u_int16_t *);
0300 extern bool_t xdr_uint16_t(XDR *, uint16_t *);
0301 extern bool_t xdr_int32_t(XDR *, int32_t *);
0302 extern bool_t xdr_u_int32_t(XDR *, u_int32_t *);
0303 extern bool_t xdr_uint32_t(XDR *, uint32_t *);
0304 extern bool_t xdr_int64_t(XDR *, int64_t *);
0305 extern bool_t xdr_u_int64_t(XDR *, u_int64_t *);
0306 extern bool_t xdr_uint64_t(XDR *, uint64_t *);
0307 extern bool_t xdr_quad_t(XDR *, int64_t *);
0308 extern bool_t xdr_u_quad_t(XDR *, u_int64_t *);
0309 extern bool_t xdr_bool(XDR *, bool_t *);
0310 extern bool_t xdr_enum(XDR *, enum_t *);
0311 extern bool_t xdr_array(XDR *, char **, u_int *, u_int, u_int, xdrproc_t);
0312 extern bool_t xdr_bytes(XDR *, char **, u_int *, u_int);
0313 extern bool_t xdr_opaque(XDR *, char *, u_int);
0314 extern bool_t xdr_string(XDR *, char **, u_int);
0315 extern bool_t xdr_union(XDR *, enum_t *, char *, const struct xdr_discrim *, xdrproc_t);
0316 extern bool_t xdr_char(XDR *, char *);
0317 extern bool_t xdr_u_char(XDR *, u_char *);
0318 extern bool_t xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t);
0319 extern bool_t xdr_float(XDR *, float *);
0320 extern bool_t xdr_double(XDR *, double *);
0321 extern bool_t xdr_quadruple(XDR *, long double *);
0322 extern bool_t xdr_reference(XDR *, char **, u_int, xdrproc_t);
0323 extern bool_t xdr_pointer(XDR *, char **, u_int, xdrproc_t);
0324 extern bool_t xdr_wrapstring(XDR *, char **);
0325 extern void xdr_free(xdrproc_t, void *);
0326 extern bool_t xdr_hyper(XDR *, quad_t *);
0327 extern bool_t xdr_u_hyper(XDR *, u_quad_t *);
0328 extern bool_t xdr_longlong_t(XDR *, quad_t *);
0329 extern bool_t xdr_u_longlong_t(XDR *, u_quad_t *);
0330 extern u_long xdr_sizeof(xdrproc_t, void *);
0331 #ifdef __cplusplus
0332 }
0333 #endif
0334
0335
0336
0337
0338
0339 #define MAX_NETOBJ_SZ 1024
0340 struct netobj {
0341 u_int n_len;
0342 char *n_bytes;
0343 };
0344 typedef struct netobj netobj;
0345 extern bool_t xdr_netobj(XDR *, struct netobj *);
0346
0347
0348
0349
0350
0351 #ifdef __cplusplus
0352 extern "C" {
0353 #endif
0354
0355 extern void xdrmem_create(XDR *, char *, u_int, enum xdr_op);
0356
0357
0358 extern void xdrstdio_create(XDR *, FILE *, enum xdr_op);
0359
0360
0361 extern void xdrrec_create(XDR *, u_int, u_int, void *,
0362 int (*)(void *, void *, int),
0363 int (*)(void *, void *, int));
0364
0365
0366 extern bool_t xdrrec_endofrecord(XDR *, int);
0367
0368
0369 extern bool_t xdrrec_skiprecord(XDR *);
0370
0371
0372 extern bool_t xdrrec_eof(XDR *);
0373 extern u_int xdrrec_readbytes(XDR *, caddr_t, u_int);
0374 #ifdef __cplusplus
0375 }
0376 #endif
0377
0378 #endif