ReactOS 0.4.15-dev-8145-ga541a46
clnt_dg.c File Reference
#include <wintirpc.h>
#include <reentrant.h>
#include <sys/types.h>
#include <rpc/clnt.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "rpc_com.h"
Include dependency graph for clnt_dg.c:

Go to the source code of this file.

Classes

struct  cu_data
 

Macros

#define MAX_DEFAULT_FDS   20000
 
#define release_fd_lock(fd, mask)
 

Functions

static struct clnt_ops * clnt_dg_ops (void)
 
static bool_t time_not_ok (struct timeval *)
 
static enum clnt_stat clnt_dg_call (CLIENT *, rpcproc_t, xdrproc_t, void *, xdrproc_t, void *, struct timeval)
 
static void clnt_dg_geterr (CLIENT *, struct rpc_err *)
 
static bool_t clnt_dg_freeres (CLIENT *, xdrproc_t, void *)
 
static void clnt_dg_abort (CLIENT *)
 
static bool_t clnt_dg_control (CLIENT *, u_int, void *)
 
static void clnt_dg_destroy (CLIENT *)
 
CLIENTclnt_dg_create (SOCKET fd, const struct netbuf *svcaddr, rpcprog_t program, rpcvers_t version, u_int sendsz, u_int recvsz)
 

Variables

static intdg_fd_locks
 
mutex_t clnt_fd_lock
 
static cond_tdg_cv
 
static const char mem_err_clnt_dg [] = "clnt_dg_create: out of memory"
 

Macro Definition Documentation

◆ MAX_DEFAULT_FDS

#define MAX_DEFAULT_FDS   20000

Definition at line 65 of file clnt_dg.c.

◆ release_fd_lock

#define release_fd_lock (   fd,
  mask 
)
Value:
{ \
mutex_lock(&clnt_fd_lock); \
dg_fd_locks[fd] = 0; \
mutex_unlock(&clnt_fd_lock); \
thr_sigsetmask(SIG_SETMASK, &(mask), NULL); \
cond_signal(&dg_cv[fd]); \
}
mutex_t clnt_fd_lock
Definition: mt_misc.c:50
static int * dg_fd_locks
Definition: clnt_dg.c:91
static cond_t * dg_cv
Definition: clnt_dg.c:93
#define NULL
Definition: types.h:112
GLenum GLint GLuint mask
Definition: glext.h:6028
static int fd
Definition: io.c:51

Definition at line 95 of file clnt_dg.c.

Function Documentation

◆ clnt_dg_abort()

static void clnt_dg_abort ( CLIENT h)
static

Definition at line 634 of file clnt_dg.c.

636{
637}

Referenced by clnt_dg_ops().

◆ clnt_dg_call()

static enum clnt_stat clnt_dg_call ( CLIENT cl,
rpcproc_t  proc,
xdrproc_t  xargs,
void argsp,
xdrproc_t  xresults,
void resultsp,
struct timeval  utimeout 
)
static

Definition at line 312 of file clnt_dg.c.

320{
321 struct cu_data *cu = (struct cu_data *)cl->cl_private;
322 XDR *xdrs;
323 size_t outlen = 0;
324 struct rpc_msg reply_msg;
325 XDR reply_xdrs;
326 bool_t ok;
327 int nrefreshes = 2; /* number of times to refresh cred */
328 struct timeval timeout;
329 struct pollfd fd;
330 int total_time, nextsend_time, tv=0;
331 struct sockaddr *sa;
332#ifndef _WIN32
333 sigset_t mask;
334 sigset_t newmask;
335#else
336 /* XXX Need Windows signal/event stuff here XXX */
337#endif
338 socklen_t inlen, salen;
339 ssize_t recvlen = 0;
340 int rpc_lock_value;
341 u_int32_t xid, inval, outval;
342#ifdef __REACTOS__
343 fd_set infd;
344#endif
345
346 outlen = 0;
347#ifndef _WIN32
348 sigfillset(&newmask);
349 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
350#else
351 /* XXX Need Windows signal/event stuff here XXX */
352#endif
356 rpc_lock_value = 1;
357 dg_fd_locks[WINSOCK_HANDLE_HASH(cu->cu_fd)] = rpc_lock_value;
359 if (cu->cu_total.tv_usec == -1) {
360 timeout = utimeout; /* use supplied timeout */
361 } else {
362 timeout = cu->cu_total; /* use default timeout */
363 }
364 total_time = timeout.tv_sec * 1000 + timeout.tv_usec / 1000;
365 nextsend_time = cu->cu_wait.tv_sec * 1000 + cu->cu_wait.tv_usec / 1000;
366
367 if (cu->cu_connect && !cu->cu_connected) {
368 if (connect(cu->cu_fd, (struct sockaddr *)&cu->cu_raddr,
369 cu->cu_rlen) < 0) {
370 cu->cu_error.re_errno = errno;
371 cu->cu_error.re_status = RPC_CANTSEND;
372 goto out;
373 }
374 cu->cu_connected = 1;
375 }
376 if (cu->cu_connected) {
377 sa = NULL;
378 salen = 0;
379 } else {
380 sa = (struct sockaddr *)&cu->cu_raddr;
381 salen = cu->cu_rlen;
382 }
383
384 /* Clean up in case the last call ended in a longjmp(3) call. */
385call_again:
386 xdrs = &(cu->cu_outxdrs);
387 if (cu->cu_async == TRUE && xargs == NULL)
388 goto get_reply;
389 xdrs->x_op = XDR_ENCODE;
390 XDR_SETPOS(xdrs, cu->cu_xdrpos);
391 /*
392 * the transaction is the first thing in the out buffer
393 * XXX Yes, and it's in network byte order, so we should to
394 * be careful when we increment it, shouldn't we.
395 */
396 xid = ntohl(*(u_int32_t *)(void *)(cu->cu_outbuf));
397 xid++;
398 *(u_int32_t *)(void *)(cu->cu_outbuf) = htonl(xid);
399
400 if ((! XDR_PUTINT32(xdrs, (int32_t *)&proc)) ||
401 (! AUTH_MARSHALL(cl->cl_auth, xdrs, NULL)) ||
402 (! (*xargs)(xdrs, argsp))) {
403 cu->cu_error.re_status = RPC_CANTENCODEARGS;
404 goto out;
405 }
406 outlen = (size_t)XDR_GETPOS(xdrs);
407
408 /*
409 * Hack to provide rpc-based message passing
410 */
411 if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
412 cu->cu_error.re_status = RPC_TIMEDOUT;
413 goto out;
414 }
415
416send_again:
417 if (total_time <= 0) {
418 cu->cu_error.re_status = RPC_TIMEDOUT;
419 goto out;
420 }
421 nextsend_time = cu->cu_wait.tv_sec * 1000 + cu->cu_wait.tv_usec / 1000;
422 if (sendto(cu->cu_fd, cu->cu_outbuf, (int)outlen, 0, sa, salen) != outlen) {
423 cu->cu_error.re_errno = errno;
424 cu->cu_error.re_status = RPC_CANTSEND;
425 goto out;
426 }
427
428get_reply:
429
430 /*
431 * sub-optimal code appears here because we have
432 * some clock time to spare while the packets are in flight.
433 * (We assume that this is actually only executed once.)
434 */
435 reply_msg.acpted_rply.ar_verf = _null_auth;
436 reply_msg.acpted_rply.ar_results.where = resultsp;
437 reply_msg.acpted_rply.ar_results.proc = xresults;
438
439 fd.fd = cu->cu_fd;
440 fd.events = POLLIN;
441 fd.revents = 0;
442 while (total_time > 0) {
443 tv = total_time < nextsend_time ? total_time : nextsend_time;
444#ifndef __REACTOS__
445 switch (poll(&fd, 1, tv)) {
446#else
447#ifdef IP_RECVERR
448#error Not supported!
449#endif
450 /* ReactOS: use select instead of poll */
451 FD_ZERO(&infd);
452 FD_SET(cu->cu_fd, &infd);
453
454 timeout.tv_sec = 0;
455 timeout.tv_usec = tv * 1000;
456
457 switch (select(0, &infd, NULL, NULL, &timeout)) {
458#endif
459 case 0:
460 total_time -= tv;
461 goto send_again;
462 // XXX CHECK THIS FOR WINDOWS!
463 case -1:
464 if (errno == EINTR)
465 continue;
466 cu->cu_error.re_status = RPC_CANTRECV;
467 cu->cu_error.re_errno = errno;
468 goto out;
469 }
470 break;
471 }
472#ifdef IP_RECVERR
473 if (fd.revents & POLLERR)
474 {
475 struct msghdr msg;
476 struct cmsghdr *cmsg;
477 struct sock_extended_err *e;
478 struct sockaddr_in err_addr;
479 struct sockaddr_in *sin = (struct sockaddr_in *)&cu->cu_raddr;
480 struct iovec iov;
481 char *cbuf = (char *) alloca (outlen + 256);
482 int ret;
483
484 iov.iov_base = cbuf + 256;
485 iov.iov_len = outlen;
486 msg.msg_name = (void *) &err_addr;
487 msg.msg_namelen = sizeof (err_addr);
488 msg.msg_iov = &iov;
489 msg.msg_iovlen = 1;
490 msg.msg_flags = 0;
491 msg.msg_control = cbuf;
492 msg.msg_controllen = 256;
493 ret = recvmsg (cu->cu_fd, &msg, MSG_ERRQUEUE);
494 if (ret >= 0
495 && memcmp (cbuf + 256, cu->cu_outbuf, ret) == 0
496 && (msg.msg_flags & MSG_ERRQUEUE)
497 && ((msg.msg_namelen == 0
498 && ret >= 12)
499 || (msg.msg_namelen == sizeof (err_addr)
500 && err_addr.sin_family == AF_INET
501 && memcmp (&err_addr.sin_addr, &sin->sin_addr,
502 sizeof (err_addr.sin_addr)) == 0
503 && err_addr.sin_port == sin->sin_port)))
504 for (cmsg = CMSG_FIRSTHDR (&msg); cmsg;
505 cmsg = CMSG_NXTHDR (&msg, cmsg))
506 if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_RECVERR)
507 {
508 e = (struct sock_extended_err *) CMSG_DATA(cmsg);
509 cu->cu_error.re_errno = e->ee_errno;
511 return (cu->cu_error.re_status = RPC_CANTRECV);
512 }
513 }
514#endif
515
516 /* We have some data now */
517 do {
518 recvlen = recvfrom(cu->cu_fd, cu->cu_inbuf,
519 cu->cu_recvsz, 0, NULL, NULL);
521 } while (recvlen == SOCKET_ERROR && errno == WSAEINTR);
522 if (recvlen == SOCKET_ERROR && errno != WSAEWOULDBLOCK) {
523 cu->cu_error.re_errno = errno;
524 cu->cu_error.re_status = RPC_CANTRECV;
525 goto out;
526 }
527
528 if (recvlen < sizeof(u_int32_t)) {
529 total_time -= tv;
530 goto send_again;
531 }
532
533 if (cu->cu_async == TRUE)
534 inlen = (socklen_t)recvlen;
535 else {
536 memcpy(&inval, cu->cu_inbuf, sizeof(u_int32_t));
537 memcpy(&outval, cu->cu_outbuf, sizeof(u_int32_t));
538 if (inval != outval) {
539 total_time -= tv;
540 goto send_again;
541 }
542 inlen = (socklen_t)recvlen;
543 }
544
545 /*
546 * now decode and validate the response
547 */
548
549 xdrmem_create(&reply_xdrs, cu->cu_inbuf, (u_int)recvlen, XDR_DECODE);
550 ok = xdr_replymsg(&reply_xdrs, &reply_msg);
551 /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
552 if (ok) {
553 if ((reply_msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
554 (reply_msg.acpted_rply.ar_stat == SUCCESS))
555 cu->cu_error.re_status = RPC_SUCCESS;
556 else
557 _seterr_reply(&reply_msg, &(cu->cu_error));
558
559 if (cu->cu_error.re_status == RPC_SUCCESS) {
560 if (! AUTH_VALIDATE(cl->cl_auth,
561 &reply_msg.acpted_rply.ar_verf, 0)) {
562 cu->cu_error.re_status = RPC_AUTHERROR;
563 cu->cu_error.re_why = AUTH_INVALIDRESP;
564 }
565 if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
566 xdrs->x_op = XDR_FREE;
567 (void) xdr_opaque_auth(xdrs,
568 &(reply_msg.acpted_rply.ar_verf));
569 }
570 } /* end successful completion */
571 /*
572 * If unsuccesful AND error is an authentication error
573 * then refresh credentials and try again, else break
574 */
575 else if (cu->cu_error.re_status == RPC_AUTHERROR)
576 /* maybe our credentials need to be refreshed ... */
577 if (nrefreshes > 0 &&
578 AUTH_REFRESH(cl->cl_auth, &reply_msg)) {
579 nrefreshes--;
580 goto call_again;
581 }
582 /* end of unsuccessful completion */
583 } /* end of valid reply message */
584 else {
585 cu->cu_error.re_status = RPC_CANTDECODERES;
586
587 }
588out:
590 return (cu->cu_error.re_status);
591}
_STLP_DECLSPEC complex< float > _STLP_CALL sin(const complex< float > &)
#define EINTR
Definition: acclib.h:80
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define ok(value,...)
Definition: atltest.h:57
bool_t xdr_opaque_auth()
#define msg(x)
Definition: auth_time.c:54
#define release_fd_lock(fd, mask)
Definition: clnt_dg.c:95
@ RPC_SUCCESS
Definition: clnt_stat.h:22
@ RPC_CANTDECODERES
Definition: clnt_stat.h:27
@ RPC_TIMEDOUT
Definition: clnt_stat.h:31
@ RPC_AUTHERROR
Definition: clnt_stat.h:38
@ RPC_CANTSEND
Definition: clnt_stat.h:28
@ RPC_CANTRECV
Definition: clnt_stat.h:29
@ RPC_CANTENCODEARGS
Definition: clnt_stat.h:26
@ AUTH_INVALIDRESP
Definition: auth.h:157
#define AUTH_MARSHALL(auth, xdrs, seq)
Definition: auth.h:242
#define AUTH_VALIDATE(auth, verfp, seq)
Definition: auth.h:247
#define AUTH_REFRESH(auth, msg)
Definition: auth.h:252
UINT32 u_int
Definition: types.h:82
int32_t bool_t
Definition: types.h:101
#define TRUE
Definition: types.h:120
INT32 int32_t
Definition: types.h:71
INT WSAAPI recvfrom(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags, OUT LPSOCKADDR from, IN OUT INT FAR *fromlen)
Definition: recv.c:87
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
INT WSAAPI sendto(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags, IN CONST struct sockaddr *to, IN INT tolen)
Definition: send.c:82
__kernel_size_t size_t
Definition: linux.h:237
#define POLLIN
Definition: linux.h:1853
#define POLLERR
Definition: linux.h:1856
#define AF_INET
Definition: tcpip.h:117
#define e
Definition: ke_i.h:82
#define alloca
Definition: malloc.h:357
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ntohl(x)
Definition: module.h:205
#define htonl(x)
Definition: module.h:214
int socklen_t
Definition: tcp.c:35
LONGLONG xid
Definition: nfs41_driver.c:106
static HANDLE proc()
Definition: pdb.c:34
#define mutex_lock(m)
Definition: reentrant.h:128
#define cond_wait(c, m)
Definition: reentrant.h:135
#define thr_sigsetmask(f, n, o)
Definition: reentrant.h:148
#define mutex_unlock(m)
Definition: reentrant.h:129
#define SUCCESS
Definition: regproc.h:26
static FILE * out
Definition: regtests2xml.c:44
unsigned int u_int32_t
Definition: rosdhcp.h:35
int ssize_t
Definition: rosdhcp.h:48
struct opaque_auth _null_auth
@ MSG_ACCEPTED
Definition: rpc_msg.h:83
bool_t xdr_replymsg(XDR *xdrs, struct rpc_msg *rmsg)
Definition: rpc_prot.c:188
void _seterr_reply(struct rpc_msg *msg, struct rpc_err *error)
Definition: rpc_prot.c:348
#define errno
Definition: errno.h:18
void * cl_private
Definition: clnt.h:142
AUTH * cl_auth
Definition: clnt.h:122
Definition: xdr.h:103
int cu_connect
Definition: clnt_dg.c:134
SOCKET cu_fd
Definition: clnt_dg.c:121
struct timeval cu_wait
Definition: clnt_dg.c:125
u_int cu_recvsz
Definition: clnt_dg.c:132
int cu_async
Definition: clnt_dg.c:133
int cu_rlen
Definition: clnt_dg.c:124
struct rpc_err cu_error
Definition: clnt_dg.c:127
u_int cu_xdrpos
Definition: clnt_dg.c:129
XDR cu_outxdrs
Definition: clnt_dg.c:128
char * cu_outbuf
Definition: clnt_dg.c:131
char cu_inbuf[1]
Definition: clnt_dg.c:136
struct sockaddr_storage cu_raddr
Definition: clnt_dg.c:123
int cu_connected
Definition: clnt_dg.c:135
struct timeval cu_total
Definition: clnt_dg.c:126
Definition: winsock.h:66
Definition: linux.h:1700
Definition: linux.h:1867
Definition: dhcpd.h:245
int ret
#define CMSG_DATA
Definition: wincrypt.h:3679
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
#define WSAEINTR
Definition: winerror.h:1942
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
#define FD_ZERO(set)
Definition: winsock.h:96
#define SOCKET_ERROR
Definition: winsock.h:333
#define FD_SET(fd, set)
Definition: winsock.h:89
#define poll
Definition: wintirpc.h:59
#define WINSOCK_HANDLE_HASH(x)
Definition: wintirpc.h:70
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
#define XDR_PUTINT32(xdrs, int32p)
Definition: xdr.h:187
@ XDR_DECODE
Definition: xdr.h:86
@ XDR_FREE
Definition: xdr.h:87
@ XDR_ENCODE
Definition: xdr.h:85
#define XDR_SETPOS(xdrs, pos)
Definition: xdr.h:204
#define XDR_GETPOS(xdrs)
Definition: xdr.h:199
void xdrmem_create(XDR *xdrs, char *addr, u_int size, enum xdr_op op)
Definition: xdr_mem.c:94

Referenced by clnt_dg_ops().

◆ clnt_dg_control()

static bool_t clnt_dg_control ( CLIENT cl,
u_int  request,
void info 
)
static

Definition at line 640 of file clnt_dg.c.

644{
645 struct cu_data *cu = (struct cu_data *)cl->cl_private;
646 struct netbuf *addr;
647#ifndef _WIN32
648 sigset_t mask;
649 sigset_t newmask;
650#else
651 /* XXX Need Windows signal/event stuff here XXX */
652#endif
653 int rpc_lock_value;
654
655#ifndef _WIN32
656 sigfillset(&newmask);
657 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
658#else
659 /* XXX Need Windows signal/event stuff here XXX */
660#endif
664 rpc_lock_value = 1;
665 dg_fd_locks[WINSOCK_HANDLE_HASH(cu->cu_fd)] = rpc_lock_value;
667 switch (request) {
668 case CLSET_FD_CLOSE:
669 cu->cu_closeit = TRUE;
671 return (TRUE);
672 case CLSET_FD_NCLOSE:
673 cu->cu_closeit = FALSE;
675 return (TRUE);
676 }
677
678 /* for other requests which use info */
679 if (info == NULL) {
681 return (FALSE);
682 }
683 switch (request) {
684 case CLSET_TIMEOUT:
685 if (time_not_ok((struct timeval *)info)) {
687 return (FALSE);
688 }
689 cu->cu_total = *(struct timeval *)info;
690 break;
691 case CLGET_TIMEOUT:
692 *(struct timeval *)info = cu->cu_total;
693 break;
694 case CLGET_SERVER_ADDR: /* Give him the fd address */
695 /* Now obsolete. Only for backward compatibility */
696 (void) memcpy(info, &cu->cu_raddr, (size_t)cu->cu_rlen);
697 break;
699 if (time_not_ok((struct timeval *)info)) {
701 return (FALSE);
702 }
703 cu->cu_wait = *(struct timeval *)info;
704 break;
706 *(struct timeval *)info = cu->cu_wait;
707 break;
708 case CLGET_FD:
709 *(SOCKET *)info = cu->cu_fd;
710 break;
711 case CLGET_SVC_ADDR:
712 addr = (struct netbuf *)info;
713 addr->buf = &cu->cu_raddr;
714 addr->len = cu->cu_rlen;
715 addr->maxlen = sizeof cu->cu_raddr;
716 break;
717 case CLSET_SVC_ADDR: /* set to new address */
718 addr = (struct netbuf *)info;
719 if (addr->len < sizeof cu->cu_raddr) {
721 return (FALSE);
722 }
723 (void) memcpy(&cu->cu_raddr, addr->buf, addr->len);
724 cu->cu_rlen = addr->len;
725 break;
726 case CLGET_XID:
727 /*
728 * use the knowledge that xid is the
729 * first element in the call structure *.
730 * This will get the xid of the PREVIOUS call
731 */
732 *(u_int32_t *)info =
733 ntohl(*(u_int32_t *)(void *)cu->cu_outbuf);
734 break;
735
736 case CLSET_XID:
737 /* This will set the xid of the NEXT call */
738 *(u_int32_t *)(void *)cu->cu_outbuf =
739 htonl(*(u_int32_t *)info - 1);
740 /* decrement by 1 as clnt_dg_call() increments once */
741 break;
742
743 case CLGET_VERS:
744 /*
745 * This RELIES on the information that, in the call body,
746 * the version number field is the fifth field from the
747 * begining of the RPC header. MUST be changed if the
748 * call_struct is changed
749 */
750 *(u_int32_t *)info =
751 ntohl(*(u_int32_t *)(void *)(cu->cu_outbuf +
752 4 * BYTES_PER_XDR_UNIT));
753 break;
754
755 case CLSET_VERS:
756 *(u_int32_t *)(void *)(cu->cu_outbuf + 4 * BYTES_PER_XDR_UNIT)
757 = htonl(*(u_int32_t *)info);
758 break;
759
760 case CLGET_PROG:
761 /*
762 * This RELIES on the information that, in the call body,
763 * the program number field is the fourth field from the
764 * begining of the RPC header. MUST be changed if the
765 * call_struct is changed
766 */
767 *(u_int32_t *)info =
768 ntohl(*(u_int32_t *)(void *)(cu->cu_outbuf +
769 3 * BYTES_PER_XDR_UNIT));
770 break;
771
772 case CLSET_PROG:
773 *(u_int32_t *)(void *)(cu->cu_outbuf + 3 * BYTES_PER_XDR_UNIT)
774 = htonl(*(u_int32_t *)info);
775 break;
776 case CLSET_ASYNC:
777 cu->cu_async = *(int *)info;
778 break;
779 case CLSET_CONNECT:
780 cu->cu_connect = *(int *)info;
781 break;
782 default:
784 return (FALSE);
785 }
787 return (TRUE);
788}
#define CLGET_XID
Definition: clnt.h:253
#define CLSET_CONNECT
Definition: clnt.h:268
#define CLGET_FD
Definition: clnt.h:249
#define CLSET_VERS
Definition: clnt.h:256
#define CLSET_RETRY_TIMEOUT
Definition: clnt.h:265
#define CLGET_RETRY_TIMEOUT
Definition: clnt.h:266
#define CLGET_TIMEOUT
Definition: clnt.h:247
#define CLSET_SVC_ADDR
Definition: clnt.h:259
#define CLSET_FD_NCLOSE
Definition: clnt.h:252
#define CLSET_FD_CLOSE
Definition: clnt.h:251
#define CLSET_PROG
Definition: clnt.h:258
#define CLSET_ASYNC
Definition: clnt.h:267
#define CLGET_VERS
Definition: clnt.h:255
#define CLGET_SVC_ADDR
Definition: clnt.h:250
#define CLGET_SERVER_ADDR
Definition: clnt.h:248
#define CLSET_TIMEOUT
Definition: clnt.h:246
#define CLSET_XID
Definition: clnt.h:254
#define CLGET_PROG
Definition: clnt.h:257
static bool_t time_not_ok(struct timeval *)
Definition: clnt_dg.c:856
#define FALSE
Definition: types.h:117
GLenum const GLvoid * addr
Definition: glext.h:9621
bool_t cu_closeit
Definition: clnt_dg.c:122
Definition: types.h:144
Definition: tftpd.h:86
UINT_PTR SOCKET
Definition: winsock.h:47
#define BYTES_PER_XDR_UNIT
Definition: xdr.h:93

Referenced by clnt_dg_ops().

◆ clnt_dg_create()

CLIENT * clnt_dg_create ( SOCKET  fd,
const struct netbuf svcaddr,
rpcprog_t  program,
rpcvers_t  version,
u_int  sendsz,
u_int  recvsz 
)

Definition at line 154 of file clnt_dg.c.

161{
162 CLIENT *cl = NULL; /* client handle */
163 struct cu_data *cu = NULL; /* private data */
164 struct timeval now;
165 struct rpc_msg call_msg;
166#ifndef _WIN32
167 sigset_t mask;
168 sigset_t newmask;
169#else
170 /* XXX Need Windows signal/event stuff here XXX */
171#endif
172 struct __rpc_sockinfo si;
173 u_long one = 1;
174
175#ifndef _WIN32
176 sigfillset(&newmask);
177 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
178#else
179 /* XXX Need Windows signal/event stuff here XXX */
180#endif
182 if (dg_fd_locks == (int *) NULL) {
183 int cv_allocsz;
184 size_t fd_allocsz;
185 int dtbsize = __rpc_dtbsize();
186
187 fd_allocsz = dtbsize * sizeof (int);
188 dg_fd_locks = (int *) mem_alloc(fd_allocsz);
189 if (dg_fd_locks == (int *) NULL) {
191// thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
192 goto err1;
193 } else
194 memset(dg_fd_locks, 0, fd_allocsz);
195
196 cv_allocsz = dtbsize * sizeof (cond_t);
197 dg_cv = (cond_t *) mem_alloc(cv_allocsz);
198 if (dg_cv == (cond_t *) NULL) {
199 mem_free(dg_fd_locks, fd_allocsz);
200 dg_fd_locks = (int *) NULL;
202// thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
203 goto err1;
204 } else {
205 int i;
206
207 for (i = 0; i < dtbsize; i++)
208 cond_init(&dg_cv[i], 0, (void *) 0);
209 }
210 }
211
213// thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
214
215 if (svcaddr == NULL) {
217 return (NULL);
218 }
219
220 if (!__rpc_fd2sockinfo(fd, &si)) {
222 rpc_createerr.cf_error.re_errno = 0;
223 return (NULL);
224 }
225 /*
226 * Find the receive and the send size
227 */
228 sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
229 recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
230 if ((sendsz == 0) || (recvsz == 0)) {
232 rpc_createerr.cf_error.re_errno = 0;
233 return (NULL);
234 }
235
236 if ((cl = mem_alloc(sizeof (CLIENT))) == NULL)
237 goto err1;
238 /*
239 * Should be multiple of 4 for XDR.
240 */
241 sendsz = ((sendsz + 3) / 4) * 4;
242 recvsz = ((recvsz + 3) / 4) * 4;
243 cu = mem_alloc(sizeof (*cu) + sendsz + recvsz);
244 if (cu == NULL)
245 goto err1;
246 (void) memcpy(&cu->cu_raddr, svcaddr->buf, (size_t)svcaddr->len);
247 cu->cu_rlen = svcaddr->len;
248 cu->cu_outbuf = &cu->cu_inbuf[recvsz];
249 /* Other values can also be set through clnt_control() */
250 cu->cu_wait.tv_sec = 15; /* heuristically chosen */
251 cu->cu_wait.tv_usec = 0;
252 cu->cu_total.tv_sec = -1;
253 cu->cu_total.tv_usec = -1;
254 cu->cu_sendsz = sendsz;
255 cu->cu_recvsz = recvsz;
256 cu->cu_async = FALSE;
257 cu->cu_connect = FALSE;
258 cu->cu_connected = FALSE;
260// call_msg.rm_xid = __RPC_GETXID(&now);
261
262 call_msg.rm_xid = ((u_int32_t)_getpid() ^ (u_int32_t)(&now)->tv_sec ^ (u_int32_t)(&now)->tv_usec);
263 call_msg.rm_call.cb_prog = program;
264 call_msg.rm_call.cb_vers = version;
265 xdrmem_create(&(cu->cu_outxdrs), cu->cu_outbuf, sendsz, XDR_ENCODE);
266 if (! xdr_callhdr(&(cu->cu_outxdrs), &call_msg)) {
268 rpc_createerr.cf_error.re_errno = 0;
269 goto err2;
270 }
271 cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs));
272
273 /* XXX fvdl - do we still want this? */
274#if 0
275 (void)bindresvport_sa(fd, (struct sockaddr *)svcaddr->buf);
276#endif
277#ifdef IP_RECVERR
278 {
279 int on = 1;
280 setsockopt(fd, SOL_IP, IP_RECVERR, &on, sizeof(on));
281 }
282#endif
284 /*
285 * By default, closeit is always FALSE. It is users responsibility
286 * to do a close on it, else the user may use clnt_control
287 * to let clnt_destroy do it for him/her.
288 */
289 cu->cu_closeit = FALSE;
290 cu->cu_fd = fd;
291 cl->cl_ops = clnt_dg_ops();
292 cl->cl_private = (caddr_t)(void *)cu;
293 cl->cl_auth = authnone_create();
294 cl->cl_tp = NULL;
295 cl->cl_netid = NULL;
296
297 return (cl);
298err1:
299 //warnx(mem_err_clnt_dg);
301 rpc_createerr.cf_error.re_errno = errno;
302err2:
303 if (cl) {
304 mem_free(cl, sizeof (CLIENT));
305 if (cu)
306 mem_free(cu, sizeof (*cu) + sendsz + recvsz);
307 }
308 return (NULL);
309}
#define gettimeofday(tv, tz)
Definition: adns_win32.h:159
AUTH * authnone_create()
Definition: auth_none.c:100
#define caddr_t
Definition: ftp.c:24
int bindresvport_sa(SOCKET sd, struct sockaddr *sa)
Definition: bindresvport.c:161
static struct clnt_ops * clnt_dg_ops(void)
Definition: clnt_dg.c:823
@ RPC_TLIERROR
Definition: clnt_stat.h:64
@ RPC_UNKNOWNADDR
Definition: clnt_stat.h:50
@ RPC_SYSTEMERROR
Definition: clnt_stat.h:43
#define mem_free(ptr, bsize)
Definition: types.h:124
#define mem_alloc(bsize)
Definition: types.h:123
static const WCHAR version[]
Definition: asmname.c:66
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
unsigned long u_long
Definition: linux.h:269
time_t now
Definition: finger.c:65
GLuint program
Definition: glext.h:6723
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ioctlsocket
Definition: ncftp.h:481
#define cond_init(c, a, p)
Definition: reentrant.h:132
#define cond_t
Definition: reentrant.h:120
u_int __rpc_get_t_size(int af, int proto, int size)
Definition: rpc_generic.c:139
int __rpc_fd2sockinfo(SOCKET fd, struct __rpc_sockinfo *sip)
Definition: rpc_generic.c:481
bool_t xdr_callhdr(XDR *xdrs, struct rpc_msg *cmsg)
Definition: rpc_prot.c:257
_CRTIMP int __cdecl _getpid(void)
Definition: procid.c:7
#define memset(x, y, z)
Definition: compat.h:39
int one
Definition: sehframes.cpp:28
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421
int __rpc_dtbsize(void)
Definition: rpc_generic.c:110
char * cl_tp
Definition: clnt.h:144
char * cl_netid
Definition: clnt.h:143
struct __rpc_client::clnt_ops * cl_ops
u_int cu_sendsz
Definition: clnt_dg.c:130
void * buf
Definition: types.h:147
unsigned int len
Definition: types.h:146
struct rpc_err cf_error
Definition: clnt.h:497
enum clnt_stat cf_stat
Definition: clnt.h:496
#define FIONBIO
Definition: winsock.h:149

Referenced by clnt_tli_create().

◆ clnt_dg_destroy()

static void clnt_dg_destroy ( CLIENT cl)
static

Definition at line 791 of file clnt_dg.c.

793{
794 struct cu_data *cu = (struct cu_data *)cl->cl_private;
795 SOCKET cu_fd = cu->cu_fd;
796#ifndef _WIN32
797 sigset_t mask;
798 sigset_t newmask;
799
800 sigfillset(&newmask);
801 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
802#else
803 /* XXX Need Windows signal/event stuff here XXX */
804#endif
808 if (cu->cu_closeit)
810 XDR_DESTROY(&(cu->cu_outxdrs));
811 mem_free(cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
812 if (cl->cl_netid && cl->cl_netid[0])
813 mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
814 if (cl->cl_tp && cl->cl_tp[0])
815 mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
816 mem_free(cl, sizeof (CLIENT));
818// thr_sigsetmask(SIG_SETMASK, &mask, NULL);
820}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define closesocket
Definition: ncftp.h:477
#define cond_signal(m)
Definition: reentrant.h:133
#define XDR_DESTROY(xdrs)
Definition: xdr.h:214

Referenced by clnt_dg_ops().

◆ clnt_dg_freeres()

static bool_t clnt_dg_freeres ( CLIENT cl,
xdrproc_t  xdr_res,
void res_ptr 
)
static

Definition at line 604 of file clnt_dg.c.

608{
609 struct cu_data *cu = (struct cu_data *)cl->cl_private;
610 XDR *xdrs = &(cu->cu_outxdrs);
612#ifndef _WIN32
613 sigset_t mask;
614 sigset_t newmask;
615
616 sigfillset(&newmask);
617 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
618#else
619 /* XXX Need Windows signal/event stuff here XXX */
620#endif
624 xdrs->x_op = XDR_FREE;
625 dummy = (*xdr_res)(xdrs, res_ptr);
627// thr_sigsetmask(SIG_SETMASK, &mask, NULL);
629 return (dummy);
630}

Referenced by clnt_dg_ops().

◆ clnt_dg_geterr()

static void clnt_dg_geterr ( CLIENT cl,
struct rpc_err errp 
)
static

Definition at line 594 of file clnt_dg.c.

597{
598 struct cu_data *cu = (struct cu_data *)cl->cl_private;
599
600 *errp = cu->cu_error;
601}

Referenced by clnt_dg_ops().

◆ clnt_dg_ops()

static struct clnt_ops * clnt_dg_ops ( void  )
static

Definition at line 823 of file clnt_dg.c.

824{
825 static struct clnt_ops ops;
826 extern mutex_t ops_lock;
827#ifndef _WIN32
828 sigset_t mask;
829 sigset_t newmask;
830
831/* VARIABLES PROTECTED BY ops_lock: ops */
832
833 sigfillset(&newmask);
834 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
835#else
836 /* XXX Need Windows signal/event stuff here XXX */
837#endif
839 if (ops.cl_call == NULL) {
840 ops.cl_call = clnt_dg_call;
841 ops.cl_abort = clnt_dg_abort;
842 ops.cl_geterr = clnt_dg_geterr;
843 ops.cl_freeres = clnt_dg_freeres;
844 ops.cl_destroy = clnt_dg_destroy;
845 ops.cl_control = clnt_dg_control;
846 }
848// thr_sigsetmask(SIG_SETMASK, &mask, NULL);
849 return (&ops);
850}
static void clnt_dg_destroy(CLIENT *)
Definition: clnt_dg.c:791
static enum clnt_stat clnt_dg_call(CLIENT *, rpcproc_t, xdrproc_t, void *, xdrproc_t, void *, struct timeval)
Definition: clnt_dg.c:312
static bool_t clnt_dg_freeres(CLIENT *, xdrproc_t, void *)
Definition: clnt_dg.c:604
static void clnt_dg_abort(CLIENT *)
Definition: clnt_dg.c:634
static void clnt_dg_geterr(CLIENT *, struct rpc_err *)
Definition: clnt_dg.c:594
static bool_t clnt_dg_control(CLIENT *, u_int, void *)
Definition: clnt_dg.c:640
mutex_t ops_lock
Definition: mt_misc.c:71
Definition: module.h:456

Referenced by clnt_dg_create().

◆ time_not_ok()

static bool_t time_not_ok ( struct timeval t)
static

Definition at line 856 of file clnt_dg.c.

858{
859 return (t->tv_sec < -1 || t->tv_sec > 100000000 ||
860 t->tv_usec < -1 || t->tv_usec > 1000000);
861}
GLdouble GLdouble t
Definition: gl.h:2047

Referenced by clnt_dg_control().

Variable Documentation

◆ clnt_fd_lock

mutex_t clnt_fd_lock
extern

Definition at line 50 of file mt_misc.c.

Referenced by clnt_dg_control(), clnt_dg_create(), clnt_dg_destroy(), and clnt_dg_freeres().

◆ dg_cv

cond_t* dg_cv
static

Definition at line 93 of file clnt_dg.c.

Referenced by clnt_dg_control(), clnt_dg_create(), clnt_dg_destroy(), and clnt_dg_freeres().

◆ dg_fd_locks

int* dg_fd_locks
static

Definition at line 91 of file clnt_dg.c.

Referenced by clnt_dg_control(), clnt_dg_create(), clnt_dg_destroy(), and clnt_dg_freeres().

◆ mem_err_clnt_dg

const char mem_err_clnt_dg[] = "clnt_dg_create: out of memory"
static

Definition at line 113 of file clnt_dg.c.