/* * Create an xdr handle for xdrrec * xdrrec_create fills in xdrs. Sendsize and recvsize are * send and recv buffer sizes (0 => use default). * tcp_handle is an opaque handle that is passed as the first parameter to * the procedures readit and writeit. Readit and writeit are read and * write respectively. They are like the system * calls expect that they take an opaque handle rather than an fd. * * Parameters: * readit: like read, but pass it a tcp_handle, not sock * writeit: lite write, but pass it a tcp_handle, not sock */ void xdrrec_create(XDR *xdrs, u_int sendsize, u_int recvsize, void *tcp_handle, int (*readit)(void *, void *, int), int (*writeit)(void *, void *, int)) { RECSTREAM *rstrm = mem_alloc(sizeof(RECSTREAM)); if (rstrm == NULL) { warnx("xdrrec_create: out of memory"); /* * This is bad. Should rework xdrrec_create to * return a handle, and in this case return NULL */ return; } rstrm->sendsize = sendsize = fix_buf_size(sendsize); rstrm->out_base = mem_alloc(rstrm->sendsize); if (rstrm->out_base == NULL) { warnx("xdrrec_create: out of memory"); mem_free(rstrm, sizeof(RECSTREAM)); return; } rstrm->recvsize = recvsize = fix_buf_size(recvsize); rstrm->in_base = mem_alloc(recvsize); if (rstrm->in_base == NULL) { warnx("xdrrec_create: out of memory"); mem_free(rstrm->out_base, sendsize); mem_free(rstrm, sizeof(RECSTREAM)); return; } /* * now the rest ... */ xdrs->x_ops = &xdrrec_ops; xdrs->x_private = rstrm; rstrm->tcp_handle = tcp_handle; rstrm->readit = readit; rstrm->writeit = writeit; rstrm->out_finger = rstrm->out_boundry = rstrm->out_base; rstrm->frag_header = (u_int32_t *)(void *)rstrm->out_base; rstrm->out_finger += sizeof(u_int32_t); rstrm->out_boundry += sendsize; rstrm->frag_sent = FALSE; rstrm->in_size = recvsize; rstrm->in_boundry = rstrm->in_base; rstrm->in_finger = (rstrm->in_boundry += recvsize); rstrm->fbtbc = 0; rstrm->last_frag = TRUE; rstrm->in_haveheader = FALSE; rstrm->in_hdrlen = 0; rstrm->in_hdrp = (char *)(void *)&rstrm->in_header; rstrm->nonblock = FALSE; rstrm->in_reclen = 0; rstrm->in_received = 0; }
/* * Create an xdr handle for xdrrec * xdrrec_create fills in xdrs. Sendsize and recvsize are * send and recv buffer sizes (0 => use default). * tcp_handle is an opaque handle that is passed as the first parameter to * the procedures readit and writeit. Readit and writeit are read and * write respectively. They are like the system * calls expect that they take an opaque handle rather than an fd. */ void xdrrec_create( XDR *xdrs, u_int sendsize, u_int recvsize, caddr_t tcp_handle, int (*readit)(), /* like read, but pass it a tcp_handle, not sock */ int (*writeit)() /* like write, but pass it a tcp_handle, not sock */ ) { register RECSTREAM *rstrm = (RECSTREAM *)mem_alloc(sizeof(RECSTREAM)); if (rstrm == NULL) { (void)fprintf(stderr, "xdrrec_create: out of memory\n"); /* * This is bad. Should rework xdrrec_create to * return a handle, and in this case return NULL */ return; } /* * adjust sizes and allocate buffer quad byte aligned */ rstrm->sendsize = sendsize = fix_buf_size(sendsize); rstrm->recvsize = recvsize = fix_buf_size(recvsize); rstrm->the_buffer = mem_alloc(sendsize + recvsize + BYTES_PER_XDR_UNIT); if (rstrm->the_buffer == NULL) { (void)fprintf(stderr, "xdrrec_create: out of memory\n"); return; } for (rstrm->out_base = rstrm->the_buffer; /* Pointer arithmetic - long cast allowed... */ (u_long)rstrm->out_base % BYTES_PER_XDR_UNIT != 0; rstrm->out_base++); rstrm->in_base = rstrm->out_base + sendsize; /* * now the rest ... */ xdrs->x_ops = &xdrrec_ops; xdrs->x_private = (caddr_t)rstrm; rstrm->tcp_handle = tcp_handle; rstrm->readit = readit; rstrm->writeit = writeit; rstrm->out_finger = rstrm->out_boundry = rstrm->out_base; rstrm->frag_header = (uint32_t *)(void *)rstrm->out_base; rstrm->out_finger += BYTES_PER_XDR_UNIT; rstrm->out_boundry += sendsize; rstrm->frag_sent = FALSE; rstrm->in_size = recvsize; rstrm->in_boundry = rstrm->in_base; rstrm->in_finger = (rstrm->in_boundry += recvsize); rstrm->fbtbc = 0; rstrm->last_frag = TRUE; }
/* * Create an xdr handle for xdrrec * xdrrec_create fills in xdrs. Sendsize and recvsize are * send and recv buffer sizes (0 => use default). * tcp_handle is an opaque handle that is passed as the first parameter to * the procedures readit and writeit. Readit and writeit are read and * write respectively. They are like the system * calls expect that they take an opaque handle rather than an fd. */ void xdrrec_create (XDR *xdrs, unsigned int sendsize, unsigned int recvsize, char *tcp_handle, int (*readit) (char *, char *, int), int (*writeit) (char *, char *, int)) { register RECSTREAM *rstrm = (RECSTREAM *) mem_alloc(sizeof(RECSTREAM)); if (rstrm == NULL) { (void) fprintf(stderr, "xdrrec_create: out of memory\n"); /* * This is bad. Should rework xdrrec_create to * return a handle, and in this case return NULL */ return; } /* * adjust sizes and allocate buffer quad byte aligned */ rstrm->sendsize = sendsize = fix_buf_size(sendsize); rstrm->recvsize = recvsize = fix_buf_size(recvsize); rstrm->the_buffer = mem_alloc(sendsize + recvsize + BYTES_PER_XDR_UNIT); if (rstrm->the_buffer == NULL) { (void) fprintf(stderr, "xdrrec_create: out of memory\n"); return; } for (rstrm->out_base = rstrm->the_buffer; (unsigned long) rstrm->out_base % BYTES_PER_XDR_UNIT != 0; rstrm->out_base++); rstrm->in_base = rstrm->out_base + sendsize; /* * now the rest ... */ xdrs->x_ops = &xdrrec_ops; xdrs->x_private = (char*) rstrm; rstrm->tcp_handle = tcp_handle; rstrm->readit = readit; rstrm->writeit = writeit; rstrm->out_finger = rstrm->out_boundry = rstrm->out_base; rstrm->frag_header = (uint32_t *) rstrm->out_base; rstrm->out_finger += 4; rstrm->out_boundry += sendsize; rstrm->frag_sent = FALSE; rstrm->in_size = recvsize; rstrm->in_boundry = rstrm->in_base; rstrm->in_finger = (rstrm->in_boundry += recvsize); rstrm->fbtbc = 0; rstrm->last_frag = TRUE; }
/* * Create an xdr handle for xdrrec * xdr_inrec_create fills in xdrs. Sendsize and recvsize are * send and recv buffer sizes (0 => use default). * tcp_handle is an opaque handle that is passed as the first parameter to * the procedures readit and writeit. Readit and writeit are read and * write respectively. They are like the system * calls expect that they take an opaque handle rather than an fd. */ void xdr_inrec_create(XDR *xdrs, u_int recvsize, void *tcp_handle, /* like read, but pass it a tcp_handle, not sock */ int (*readit)(XDR *, void *, void *, int)) { RECSTREAM *rstrm = mem_alloc(sizeof(RECSTREAM)); if (rstrm == NULL) { __warnx(TIRPC_DEBUG_FLAG_XDRREC, "xdr_inrec_create: out of memory"); /* * This is bad. Should rework xdr_inrec_create to * return a handle, and in this case return NULL */ return; } rstrm->recvsize = recvsize = fix_buf_size(recvsize); rstrm->in_base = mem_alloc(recvsize); if (rstrm->in_base == NULL) { __warnx(TIRPC_DEBUG_FLAG_XDRREC, "xdr_inrec_create: out of memory"); mem_free(rstrm, sizeof(RECSTREAM)); return; } /* * now the rest ... */ xdrs->x_ops = &xdr_inrec_ops; xdrs->x_lib[0] = NULL; xdrs->x_lib[1] = NULL; xdrs->x_public = NULL; xdrs->x_private = rstrm; xdrs->x_flags = XDR_FLAG_CKSUM; rstrm->xdrs = xdrs; rstrm->tcp_handle = tcp_handle; rstrm->readit = readit; rstrm->in_size = recvsize; rstrm->in_boundry = rstrm->in_base; rstrm->in_finger = (rstrm->in_boundry += recvsize); rstrm->fbtbc = 0; rstrm->last_frag = TRUE; rstrm->in_haveheader = FALSE; rstrm->offset = 0; rstrm->cksum = 0; rstrm->cklen = 256; }
XDR_API void xdrrec_create(XDR *xdrs, const u_int sendsize, const u_int recvsize, const caddr_t tcp_handle, int (*readit) (void *, caddr_t, int), int (*writeit) (void *, caddr_t, int)) { RECSTREAM *rstrm = malloc(sizeof (RECSTREAM)); /* * TODO: Should still rework xdrrec_create to return a handle, * and in any malloc-failure case return NULL. */ if (rstrm == NULL) { #if HAVE_SYSLOG_H (void) syslog(LOG_ERR, mem_err_msg_rec); #else (void) fprintf(stderr, "%s\n", mem_err_msg_rec); #endif return; } /* * Adjust sizes and allocate buffers; malloc(3C) * provides a buffer suitably aligned for any use, so * there's no need for us to mess around with alignment. * * Since non-blocking connections may need to reallocate the input * buffer, we use separate malloc()s for input and output. */ rstrm->sendsize = fix_buf_size(sendsize); rstrm->recvsize = fix_buf_size(recvsize); rstrm->out_base = malloc(rstrm->sendsize); if (rstrm->out_base == NULL) { #if HAVE_SYSLOG_H (void) syslog(LOG_ERR, mem_err_msg_rec); #else (void) fprintf(stderr, "%s\n", mem_err_msg_rec); #endif free(rstrm); return; } rstrm->in_base = malloc(rstrm->recvsize); if (rstrm->in_base == NULL) { #if HAVE_SYSLOG_H (void) syslog(LOG_ERR, mem_err_msg_rec); #else (void) fprintf(stderr, "%s\n", mem_err_msg_rec); #endif free(rstrm->out_base); free(rstrm); return; } /* * now the rest ... */ xdrs->x_ops = xdrrec_ops(); xdrs->x_private = (caddr_t)rstrm; rstrm->tcp_handle = tcp_handle; rstrm->readit = readit; rstrm->writeit = writeit; rstrm->out_finger = rstrm->out_boundry = rstrm->out_base; /* LINTED pointer cast */ rstrm->frag_header = (uint32_t *)rstrm->out_base; rstrm->out_finger += sizeof (u_int); rstrm->out_boundry += rstrm->sendsize; rstrm->frag_sent = FALSE; rstrm->in_boundry = rstrm->in_base; rstrm->in_finger = (rstrm->in_boundry += rstrm->recvsize); rstrm->fbtbc = 0; rstrm->last_frag = TRUE; rstrm->firsttime = 0; rstrm->in_nonblock = 0; rstrm->in_needpoll = 1; rstrm->in_maxrecsz = 0; rstrm->in_nextrec = rstrm->in_base; rstrm->in_nextrecsz = 0; }
/* * Create an xdr handle for xdrrec * xdrrec_create fills in xdrs. Sendsize and recvsize are * send and recv buffer sizes (0 => use default). * tcp_handle is an opaque handle that is passed as the first parameter to * the procedures readit and writeit. Readit and writeit are read and * write respectively. They are like the system * calls expect that they take an opaque handle rather than an fd. */ void xdrrec_create( register XDR *xdrs, register unsigned sendsize, register unsigned recvsize, char* tcp_handle, int (*readit)( /* like read, but pass it a tcp_handle, not sock */ void* handle, char* buf, int len), int (*writeit)( /* like write, but pass it a tcp_handle, not sock */ void* handle, char* buf, int len)) { register RECSTREAM *rstrm = (RECSTREAM *)mem_alloc(sizeof(RECSTREAM)); if (rstrm == NULL) { (void)fprintf(stderr, "xdrrec_create: out of memory\n"); /* * This is bad. Should rework xdrrec_create to * return a handle, and in this case return NULL */ return; } /* * adjust sizes and allocate buffer quad-byte aligned. */ rstrm->sendsize = sendsize = fix_buf_size(sendsize); rstrm->recvsize = recvsize = fix_buf_size(recvsize); rstrm->the_buffer = mem_alloc(sendsize + recvsize + BYTES_PER_XDR_UNIT); if (rstrm->the_buffer == NULL) { (void)fprintf(stderr, "xdrrec_create: out of memory\n"); mem_free(rstrm, sizeof(*rstrm)); return; } rstrm->out_base = rstrm->the_buffer; { int rem = (int)((uintptr_t)rstrm->the_buffer % BYTES_PER_XDR_UNIT); if (rem != 0) rstrm->out_base += BYTES_PER_XDR_UNIT - rem; } rstrm->in_base = rstrm->out_base + sendsize; /* * now the rest ... */ xdrs->x_ops = &xdrrec_ops; xdrs->x_private = (char*)rstrm; rstrm->tcp_handle = tcp_handle; rstrm->readit = readit; rstrm->writeit = writeit; rstrm->frag_header = (uint32_t*)rstrm->out_base; rstrm->out_boundry = rstrm->out_base + sendsize; rstrm->out_finger = rstrm->out_base + sizeof(uint32_t); rstrm->frag_sent = FALSE; rstrm->in_size = recvsize; rstrm->in_boundry = rstrm->in_base + recvsize; rstrm->in_finger = rstrm->in_boundry; rstrm->fbtbc = 0; rstrm->last_frag = TRUE; }
/* * Create an xdr handle for xdrrec * xdrrec_create fills in xdrs. Sendsize and recvsize are * send and recv buffer sizes (0 => use default). * tcp_handle is an opaque handle that is passed as the first parameter to * the procedures readit and writeit. Readit and writeit are read and * write respectively. They are like the system * calls expect that they take an opaque handle rather than an fd. */ void xdrrec_create(XDR *xdrs, u_int sendsize, u_int recvsize, void *tcp_handle, /* like read, but pass it a tcp_handle, not sock */ int (*readit) (XDR *, void *, void *, int), /* like write, but pass it a tcp_handle, not sock */ int (*writeit) (XDR *, void *, void *, int)) { RECSTREAM *rstrm = mem_alloc(sizeof(RECSTREAM)); if (rstrm == NULL) { __warnx(TIRPC_DEBUG_FLAG_XDRREC, "xdrrec_create: out of memory"); /* * This is bad. Should rework xdrrec_create to * return a handle, and in this case return NULL */ return; } rstrm->sendsize = sendsize = fix_buf_size(sendsize); rstrm->out_base = mem_alloc(rstrm->sendsize); if (rstrm->out_base == NULL) { __warnx(TIRPC_DEBUG_FLAG_XDRREC, "xdrrec_create: out of memory"); mem_free(rstrm, sizeof(RECSTREAM)); return; } rstrm->recvsize = recvsize = fix_buf_size(recvsize); rstrm->in_base = mem_alloc(recvsize); if (rstrm->in_base == NULL) { __warnx(TIRPC_DEBUG_FLAG_XDRREC, "xdrrec_create: out of memory"); mem_free(rstrm->out_base, sendsize); mem_free(rstrm, sizeof(RECSTREAM)); return; } /* * now the rest ... */ xdrs->x_ops = &xdrrec_ops; xdrs->x_lib[0] = NULL; xdrs->x_lib[1] = NULL; xdrs->x_public = NULL; xdrs->x_private = rstrm; rstrm->xdrs = xdrs; rstrm->tcp_handle = tcp_handle; rstrm->readit = readit; rstrm->writeit = writeit; rstrm->out_finger = rstrm->out_boundry = rstrm->out_base; rstrm->frag_header = (u_int32_t *) (void *)rstrm->out_base; rstrm->out_finger += sizeof(u_int32_t); rstrm->out_boundry += sendsize; rstrm->frag_sent = false; rstrm->in_size = recvsize; rstrm->in_boundry = rstrm->in_base; rstrm->in_finger = (rstrm->in_boundry += recvsize); rstrm->fbtbc = 0; rstrm->last_frag = true; rstrm->in_haveheader = false; rstrm->in_hdrlen = 0; rstrm->in_hdrp = (char *)(void *)&rstrm->in_header; rstrm->nonblock = false; rstrm->in_reclen = 0; rstrm->in_received = 0; }