1 /* $NetBSD: clnt_vc.c,v 1.4 2000/07/14 08:40:42 fvdl Exp $ */
4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 * unrestricted use provided that this legend is included on all tape
6 * media and as a part of the software program in whole or part. Users
7 * may copy or modify Sun RPC without charge, but are not authorized
8 * to license or distribute it to anyone else except as part of a product or
9 * program developed by the user.
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
15 * Sun RPC is provided with no support and without any obligation on the
16 * part of Sun Microsystems, Inc. to assist in its use, correction,
17 * modification or enhancement.
19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 * OR ANY PART THEREOF.
23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 * or profits or other special, indirect and consequential damages, even if
25 * Sun has been advised of the possibility of such damages.
27 * Sun Microsystems, Inc.
29 * Mountain View, California 94043
32 #if defined(LIBC_SCCS) && !defined(lint)
33 static char *sccsid2 = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";
34 static char *sccsid = "@(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC";
35 static char sccsid3[] = "@(#)clnt_vc.c 1.19 89/03/16 Copyr 1988 Sun Micro";
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
41 * clnt_tcp.c, Implements a TCP/IP based, client side RPC.
43 * Copyright (C) 1984, Sun Microsystems, Inc.
45 * TCP based RPC supports 'batched calls'.
46 * A sequence of calls may be batched-up in a send buffer. The rpc call
47 * return immediately to the client even though the call was not necessarily
48 * sent. The batching occurs if the results' xdr routine is NULL (0) AND
49 * the rpc timeout value is zero (see clnt.h, rpc).
51 * Clients should NOT casually batch calls that in fact return results; that is,
52 * the server side should be aware that a call is batched and not produce any
53 * return message. Batched calls that produce many result messages can
54 * deadlock (netlock) the client and the server....
56 * Now go hang yourself.
59 #include "namespace.h"
60 #include "reentrant.h"
61 #include <sys/types.h>
63 #include <sys/syslog.h>
64 #include <sys/socket.h>
68 #include <arpa/inet.h>
80 #include "un-namespace.h"
84 #define MCALL_MSG_SIZE 24
88 struct cmsgcred cmcred;
91 static enum clnt_stat clnt_vc_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
92 xdrproc_t, void *, struct timeval);
93 static void clnt_vc_geterr(CLIENT *, struct rpc_err *);
94 static bool_t clnt_vc_freeres(CLIENT *, xdrproc_t, void *);
95 static void clnt_vc_abort(CLIENT *);
96 static bool_t clnt_vc_control(CLIENT *, u_int, void *);
97 static void clnt_vc_destroy(CLIENT *);
98 static struct clnt_ops *clnt_vc_ops(void);
99 static bool_t time_not_ok(struct timeval *);
100 static int read_vc(void *, void *, int);
101 static int write_vc(void *, void *, int);
102 static int __msgwrite(int, void *, size_t);
103 static int __msgread(int, void *, size_t);
106 int ct_fd; /* connection's fd */
107 bool_t ct_closeit; /* close it on destroy */
108 struct timeval ct_wait; /* wait interval in milliseconds */
109 bool_t ct_waitset; /* wait set by clnt_control? */
110 struct netbuf ct_addr; /* remote addr */
111 struct rpc_err ct_error;
113 char ct_mcallc[MCALL_MSG_SIZE]; /* marshalled callmsg */
116 u_int ct_mpos; /* pos after marshal */
117 XDR ct_xdrs; /* XDR stream */
121 * This machinery implements per-fd locks for MT-safety. It is not
122 * sufficient to do per-CLIENT handle locks for MT-safety because a
123 * user may create more than one CLIENT handle with the same fd behind
124 * it. Therfore, we allocate an array of flags (vc_fd_locks), protected
125 * by the clnt_fd_lock mutex, and an array (vc_cv) of condition variables
126 * similarly protected. Vc_fd_lock[fd] == 1 => a call is activte on some
127 * CLIENT handle created for that fd.
128 * The current implementation holds locks across the entire RPC and reply.
129 * Yes, this is silly, and as soon as this code is proven to work, this
130 * should be the first thing fixed. One step at a time.
132 static int *vc_fd_locks;
133 static cond_t *vc_cv;
134 #define release_fd_lock(fd, mask) { \
135 mutex_lock(&clnt_fd_lock); \
136 vc_fd_locks[fd] = 0; \
137 mutex_unlock(&clnt_fd_lock); \
138 thr_sigsetmask(SIG_SETMASK, &(mask), (sigset_t *) NULL); \
139 cond_signal(&vc_cv[fd]); \
142 static const char clnt_vc_errstr[] = "%s : %s";
143 static const char clnt_vc_str[] = "clnt_vc_create";
144 static const char clnt_read_vc_str[] = "read_vc";
145 static const char __no_mem_str[] = "out of memory";
148 * Create a client handle for a connection.
149 * Default options are set, which the user can change using clnt_control()'s.
150 * The rpc/vc package does buffering similar to stdio, so the client
151 * must pick send and receive buffer sizes, 0 => use the default.
152 * NB: fd is copied into a private area.
153 * NB: The rpch->cl_auth is set null authentication. Caller may wish to
154 * set this something more useful.
156 * fd should be an open socket
159 clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
160 int fd; /* open file descriptor */
161 const struct netbuf *raddr; /* servers address */
162 const rpcprog_t prog; /* program number */
163 const rpcvers_t vers; /* version number */
164 u_int sendsz; /* buffer recv size */
165 u_int recvsz; /* buffer send size */
167 CLIENT *cl; /* client handle */
168 struct ct_data *ct = NULL; /* client handle */
170 struct rpc_msg call_msg;
171 static u_int32_t disrupt;
174 struct sockaddr_storage ss;
176 struct __rpc_sockinfo si;
179 disrupt = (u_int32_t)(long)raddr;
181 cl = (CLIENT *)mem_alloc(sizeof (*cl));
182 ct = (struct ct_data *)mem_alloc(sizeof (*ct));
183 if ((cl == (CLIENT *)NULL) || (ct == (struct ct_data *)NULL)) {
184 (void) syslog(LOG_ERR, clnt_vc_errstr,
185 clnt_vc_str, __no_mem_str);
186 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
187 rpc_createerr.cf_error.re_errno = errno;
190 ct->ct_addr.buf = NULL;
191 sigfillset(&newmask);
192 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
193 mutex_lock(&clnt_fd_lock);
194 if (vc_fd_locks == (int *) NULL) {
195 int cv_allocsz, fd_allocsz;
196 int dtbsize = __rpc_dtbsize();
198 fd_allocsz = dtbsize * sizeof (int);
199 vc_fd_locks = (int *) mem_alloc(fd_allocsz);
200 if (vc_fd_locks == (int *) NULL) {
201 mutex_unlock(&clnt_fd_lock);
202 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
205 memset(vc_fd_locks, '\0', fd_allocsz);
207 assert(vc_cv == (cond_t *) NULL);
208 cv_allocsz = dtbsize * sizeof (cond_t);
209 vc_cv = (cond_t *) mem_alloc(cv_allocsz);
210 if (vc_cv == (cond_t *) NULL) {
211 mem_free(vc_fd_locks, fd_allocsz);
212 vc_fd_locks = (int *) NULL;
213 mutex_unlock(&clnt_fd_lock);
214 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
219 for (i = 0; i < dtbsize; i++)
220 cond_init(&vc_cv[i], 0, (void *) 0);
223 assert(vc_cv != (cond_t *) NULL);
226 * XXX - fvdl connecting while holding a mutex?
229 if (_getpeername(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) {
230 if (errno != ENOTCONN) {
231 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
232 rpc_createerr.cf_error.re_errno = errno;
233 mutex_unlock(&clnt_fd_lock);
234 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
237 if (_connect(fd, (struct sockaddr *)raddr->buf, raddr->len) < 0){
238 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
239 rpc_createerr.cf_error.re_errno = errno;
240 mutex_unlock(&clnt_fd_lock);
241 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
245 mutex_unlock(&clnt_fd_lock);
246 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
247 if (!__rpc_fd2sockinfo(fd, &si))
250 ct->ct_closeit = FALSE;
253 * Set up private data struct
256 ct->ct_wait.tv_usec = 0;
257 ct->ct_waitset = FALSE;
258 ct->ct_addr.buf = malloc(raddr->maxlen);
259 if (ct->ct_addr.buf == NULL)
261 memcpy(ct->ct_addr.buf, raddr->buf, raddr->len);
262 ct->ct_addr.len = raddr->maxlen;
263 ct->ct_addr.maxlen = raddr->maxlen;
266 * Initialize call message
268 (void)gettimeofday(&now, NULL);
269 call_msg.rm_xid = ((u_int32_t)++disrupt) ^ __RPC_GETXID(&now);
270 call_msg.rm_direction = CALL;
271 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
272 call_msg.rm_call.cb_prog = (u_int32_t)prog;
273 call_msg.rm_call.cb_vers = (u_int32_t)vers;
276 * pre-serialize the static part of the call msg and stash it away
278 xdrmem_create(&(ct->ct_xdrs), ct->ct_u.ct_mcallc, MCALL_MSG_SIZE,
280 if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
281 if (ct->ct_closeit) {
286 ct->ct_mpos = XDR_GETPOS(&(ct->ct_xdrs));
287 XDR_DESTROY(&(ct->ct_xdrs));
290 * Create a client handle which uses xdrrec for serialization
291 * and authnone for authentication.
293 cl->cl_ops = clnt_vc_ops();
295 cl->cl_auth = authnone_create();
296 sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
297 recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
298 xdrrec_create(&(ct->ct_xdrs), sendsz, recvsz,
299 cl->cl_private, read_vc, write_vc);
306 mem_free(ct->ct_addr.buf, ct->ct_addr.len);
307 mem_free(ct, sizeof (struct ct_data));
310 mem_free(cl, sizeof (CLIENT));
312 return ((CLIENT *)NULL);
315 static enum clnt_stat
316 clnt_vc_call(cl, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout)
321 xdrproc_t xdr_results;
323 struct timeval timeout;
325 struct ct_data *ct = (struct ct_data *) cl->cl_private;
326 XDR *xdrs = &(ct->ct_xdrs);
327 struct rpc_msg reply_msg;
329 u_int32_t *msg_x_id = &ct->ct_u.ct_mcalli; /* yuk */
332 sigset_t mask, newmask;
337 sigfillset(&newmask);
338 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
339 mutex_lock(&clnt_fd_lock);
340 while (vc_fd_locks[ct->ct_fd])
341 cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
346 vc_fd_locks[ct->ct_fd] = rpc_lock_value;
347 mutex_unlock(&clnt_fd_lock);
348 if (!ct->ct_waitset) {
349 /* If time is not within limits, we ignore it. */
350 if (time_not_ok(&timeout) == FALSE)
351 ct->ct_wait = timeout;
355 (xdr_results == NULL && timeout.tv_sec == 0
356 && timeout.tv_usec == 0) ? FALSE : TRUE;
359 xdrs->x_op = XDR_ENCODE;
360 ct->ct_error.re_status = RPC_SUCCESS;
361 x_id = ntohl(--(*msg_x_id));
363 if ((! XDR_PUTBYTES(xdrs, ct->ct_u.ct_mcallc, ct->ct_mpos)) ||
364 (! XDR_PUTINT32(xdrs, &proc)) ||
365 (! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
366 (! (*xdr_args)(xdrs, args_ptr))) {
367 if (ct->ct_error.re_status == RPC_SUCCESS)
368 ct->ct_error.re_status = RPC_CANTENCODEARGS;
369 (void)xdrrec_endofrecord(xdrs, TRUE);
370 release_fd_lock(ct->ct_fd, mask);
371 return (ct->ct_error.re_status);
373 if (! xdrrec_endofrecord(xdrs, shipnow)) {
374 release_fd_lock(ct->ct_fd, mask);
375 return (ct->ct_error.re_status = RPC_CANTSEND);
378 release_fd_lock(ct->ct_fd, mask);
379 return (RPC_SUCCESS);
382 * Hack to provide rpc-based message passing
384 if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
385 release_fd_lock(ct->ct_fd, mask);
386 return(ct->ct_error.re_status = RPC_TIMEDOUT);
391 * Keep receiving until we get a valid transaction id
393 xdrs->x_op = XDR_DECODE;
395 reply_msg.acpted_rply.ar_verf = _null_auth;
396 reply_msg.acpted_rply.ar_results.where = NULL;
397 reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
398 if (! xdrrec_skiprecord(xdrs)) {
399 release_fd_lock(ct->ct_fd, mask);
400 return (ct->ct_error.re_status);
402 /* now decode and validate the response header */
403 if (! xdr_replymsg(xdrs, &reply_msg)) {
404 if (ct->ct_error.re_status == RPC_SUCCESS)
406 release_fd_lock(ct->ct_fd, mask);
407 return (ct->ct_error.re_status);
409 if (reply_msg.rm_xid == x_id)
416 _seterr_reply(&reply_msg, &(ct->ct_error));
417 if (ct->ct_error.re_status == RPC_SUCCESS) {
418 if (! AUTH_VALIDATE(cl->cl_auth,
419 &reply_msg.acpted_rply.ar_verf)) {
420 ct->ct_error.re_status = RPC_AUTHERROR;
421 ct->ct_error.re_why = AUTH_INVALIDRESP;
422 } else if (! (*xdr_results)(xdrs, results_ptr)) {
423 if (ct->ct_error.re_status == RPC_SUCCESS)
424 ct->ct_error.re_status = RPC_CANTDECODERES;
426 /* free verifier ... */
427 if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
428 xdrs->x_op = XDR_FREE;
429 (void)xdr_opaque_auth(xdrs,
430 &(reply_msg.acpted_rply.ar_verf));
432 } /* end successful completion */
434 /* maybe our credentials need to be refreshed ... */
435 if (refreshes-- && AUTH_REFRESH(cl->cl_auth, &reply_msg))
437 } /* end of unsuccessful completion */
438 release_fd_lock(ct->ct_fd, mask);
439 return (ct->ct_error.re_status);
443 clnt_vc_geterr(cl, errp)
445 struct rpc_err *errp;
450 assert(errp != NULL);
452 ct = (struct ct_data *) cl->cl_private;
453 *errp = ct->ct_error;
457 clnt_vc_freeres(cl, xdr_res, res_ptr)
470 ct = (struct ct_data *)cl->cl_private;
471 xdrs = &(ct->ct_xdrs);
473 sigfillset(&newmask);
474 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
475 mutex_lock(&clnt_fd_lock);
476 while (vc_fd_locks[ct->ct_fd])
477 cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
478 xdrs->x_op = XDR_FREE;
479 dummy = (*xdr_res)(xdrs, res_ptr);
480 mutex_unlock(&clnt_fd_lock);
481 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
482 cond_signal(&vc_cv[ct->ct_fd]);
495 clnt_vc_control(cl, request, info)
508 ct = (struct ct_data *)cl->cl_private;
510 sigfillset(&newmask);
511 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
512 mutex_lock(&clnt_fd_lock);
513 while (vc_fd_locks[ct->ct_fd])
514 cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
519 vc_fd_locks[ct->ct_fd] = rpc_lock_value;
520 mutex_unlock(&clnt_fd_lock);
524 ct->ct_closeit = TRUE;
525 release_fd_lock(ct->ct_fd, mask);
527 case CLSET_FD_NCLOSE:
528 ct->ct_closeit = FALSE;
529 release_fd_lock(ct->ct_fd, mask);
535 /* for other requests which use info */
537 release_fd_lock(ct->ct_fd, mask);
542 if (time_not_ok((struct timeval *)info)) {
543 release_fd_lock(ct->ct_fd, mask);
546 ct->ct_wait = *(struct timeval *)infop;
547 ct->ct_waitset = TRUE;
550 *(struct timeval *)infop = ct->ct_wait;
552 case CLGET_SERVER_ADDR:
553 (void) memcpy(info, ct->ct_addr.buf, (size_t)ct->ct_addr.len);
556 *(int *)info = ct->ct_fd;
559 /* The caller should not free this memory area */
560 *(struct netbuf *)info = ct->ct_addr;
562 case CLSET_SVC_ADDR: /* set to new address */
563 release_fd_lock(ct->ct_fd, mask);
567 * use the knowledge that xid is the
568 * first element in the call structure
569 * This will get the xid of the PREVIOUS call
572 ntohl(*(u_int32_t *)(void *)&ct->ct_u.ct_mcalli);
575 /* This will set the xid of the NEXT call */
576 *(u_int32_t *)(void *)&ct->ct_u.ct_mcalli =
577 htonl(*((u_int32_t *)info) + 1);
578 /* increment by 1 as clnt_vc_call() decrements once */
582 * This RELIES on the information that, in the call body,
583 * the version number field is the fifth field from the
584 * begining of the RPC header. MUST be changed if the
585 * call_struct is changed
588 ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
589 4 * BYTES_PER_XDR_UNIT));
593 *(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
594 4 * BYTES_PER_XDR_UNIT) =
595 htonl(*(u_int32_t *)info);
600 * This RELIES on the information that, in the call body,
601 * the program number field is the fourth field from the
602 * begining of the RPC header. MUST be changed if the
603 * call_struct is changed
606 ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
607 3 * BYTES_PER_XDR_UNIT));
611 *(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
612 3 * BYTES_PER_XDR_UNIT) =
613 htonl(*(u_int32_t *)info);
617 release_fd_lock(ct->ct_fd, mask);
620 release_fd_lock(ct->ct_fd, mask);
629 struct ct_data *ct = (struct ct_data *) cl->cl_private;
630 int ct_fd = ct->ct_fd;
636 ct = (struct ct_data *) cl->cl_private;
638 sigfillset(&newmask);
639 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
640 mutex_lock(&clnt_fd_lock);
641 while (vc_fd_locks[ct_fd])
642 cond_wait(&vc_cv[ct_fd], &clnt_fd_lock);
643 if (ct->ct_closeit && ct->ct_fd != -1) {
644 (void)_close(ct->ct_fd);
646 XDR_DESTROY(&(ct->ct_xdrs));
648 free(ct->ct_addr.buf);
649 mem_free(ct, sizeof(struct ct_data));
650 mem_free(cl, sizeof(CLIENT));
651 mutex_unlock(&clnt_fd_lock);
652 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
653 cond_signal(&vc_cv[ct_fd]);
657 * Interface between xdr serializer and tcp connection.
658 * Behaves like the system calls, read & write, but keeps some error state
659 * around for the rpc level.
662 read_vc(ctp, buf, len)
669 struct ct_data *ct = (struct ct_data *)ctp;
671 int milliseconds = (int)((ct->ct_wait.tv_sec * 1000) +
672 (ct->ct_wait.tv_usec / 1000));
679 switch (_poll(&fd, 1, milliseconds)) {
681 ct->ct_error.re_status = RPC_TIMEDOUT;
687 ct->ct_error.re_status = RPC_CANTRECV;
688 ct->ct_error.re_errno = errno;
695 if ((_getpeername(ct->ct_fd, &sa, &sal) == 0) &&
696 (sa.sa_family == AF_LOCAL)) {
697 len = __msgread(ct->ct_fd, buf, (size_t)len);
699 len = _read(ct->ct_fd, buf, (size_t)len);
705 ct->ct_error.re_errno = ECONNRESET;
706 ct->ct_error.re_status = RPC_CANTRECV;
707 len = -1; /* it's really an error */
711 ct->ct_error.re_errno = errno;
712 ct->ct_error.re_status = RPC_CANTRECV;
719 write_vc(ctp, buf, len)
726 struct ct_data *ct = (struct ct_data *)ctp;
730 if ((_getpeername(ct->ct_fd, &sa, &sal) == 0) &&
731 (sa.sa_family == AF_LOCAL)) {
732 for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) {
733 if ((i = __msgwrite(ct->ct_fd, buf,
734 (size_t)cnt)) == -1) {
735 ct->ct_error.re_errno = errno;
736 ct->ct_error.re_status = RPC_CANTSEND;
741 for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) {
742 if ((i = _write(ct->ct_fd, buf, (size_t)cnt)) == -1) {
743 ct->ct_error.re_errno = errno;
744 ct->ct_error.re_status = RPC_CANTSEND;
752 static struct clnt_ops *
755 static struct clnt_ops ops;
756 sigset_t mask, newmask;
758 /* VARIABLES PROTECTED BY ops_lock: ops */
760 sigfillset(&newmask);
761 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
762 mutex_lock(&ops_lock);
763 if (ops.cl_call == NULL) {
764 ops.cl_call = clnt_vc_call;
765 ops.cl_abort = clnt_vc_abort;
766 ops.cl_geterr = clnt_vc_geterr;
767 ops.cl_freeres = clnt_vc_freeres;
768 ops.cl_destroy = clnt_vc_destroy;
769 ops.cl_control = clnt_vc_control;
771 mutex_unlock(&ops_lock);
772 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
777 * Make sure that the time is not garbage. -1 value is disallowed.
778 * Note this is different from time_not_ok in clnt_dg.c
784 return (t->tv_sec <= -1 || t->tv_sec > 100000000 ||
785 t->tv_usec <= -1 || t->tv_usec > 1000000);
789 __msgread(sock, buf, cnt)
798 char control[CMSG_SPACE(sizeof(struct cmsgcred))];
801 bzero((char *)&cm, sizeof(cm));
802 iov[0].iov_base = buf;
803 iov[0].iov_len = cnt;
809 msg.msg_control = (caddr_t)&cm;
810 msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
813 return(_recvmsg(sock, &msg, 0));
817 __msgwrite(sock, buf, cnt)
826 char control[CMSG_SPACE(sizeof(struct cmsgcred))];
829 bzero((char *)&cm, sizeof(cm));
830 iov[0].iov_base = buf;
831 iov[0].iov_len = cnt;
833 cm.cmsg.cmsg_type = SCM_CREDS;
834 cm.cmsg.cmsg_level = SOL_SOCKET;
835 cm.cmsg.cmsg_len = CMSG_LEN(sizeof(struct cmsgcred));
841 msg.msg_control = (caddr_t)&cm;
842 msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
845 return(_sendmsg(sock, &msg, 0));