#include <errno.h>
#include <stdio.h>
#include <unistd.h>
+#include <libintl.h>
#include <rpc/rpc.h>
#include <sys/poll.h>
#include <sys/socket.h>
#include <rpc/pmap_clnt.h>
+#ifdef USE_IN_LIBIO
+# include <wchar.h>
+#endif
+
+extern u_long _create_xid (void);
#define MCALL_MSG_SIZE 24
static bool_t clnttcp_control (CLIENT *, int, char *);
static void clnttcp_destroy (CLIENT *);
-static struct clnt_ops tcp_ops =
+static const struct clnt_ops tcp_ops =
{
clnttcp_call,
clnttcp_abort,
int *sockp, u_int sendsz, u_int recvsz)
{
CLIENT *h;
- struct ct_data *ct = (struct ct_data *) mem_alloc (sizeof (*ct));
- struct timeval now;
+ struct ct_data *ct;
struct rpc_msg call_msg;
h = (CLIENT *) mem_alloc (sizeof (*h));
- if (h == NULL)
- {
- (void) fprintf (stderr, _("clnttcp_create: out of memory\n"));
- rpc_createerr.cf_stat = RPC_SYSTEMERROR;
- rpc_createerr.cf_error.re_errno = errno;
- goto fooy;
- }
- /* ct = (struct ct_data *) mem_alloc (sizeof (*ct)); */
- if (ct == NULL)
+ ct = (struct ct_data *) mem_alloc (sizeof (*ct));
+ if (h == NULL || ct == NULL)
{
- (void) fprintf (stderr, _("clnttcp_create: out of memory\n"));
- rpc_createerr.cf_stat = RPC_SYSTEMERROR;
- rpc_createerr.cf_error.re_errno = errno;
+ struct rpc_createerr *ce = &get_rpc_createerr ();
+ (void) __fxprintf (NULL, "%s: %s", __func__, _("out of memory\n"));
+ ce->cf_stat = RPC_SYSTEMERROR;
+ ce->cf_error.re_errno = ENOMEM;
goto fooy;
}
*/
if (*sockp < 0)
{
- *sockp = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ *sockp = __socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
(void) bindresvport (*sockp, (struct sockaddr_in *) 0);
if ((*sockp < 0)
- || (connect (*sockp, (struct sockaddr *) raddr,
- sizeof (*raddr)) < 0))
+ || (__connect (*sockp, (struct sockaddr *) raddr,
+ sizeof (*raddr)) < 0))
{
- rpc_createerr.cf_stat = RPC_SYSTEMERROR;
- rpc_createerr.cf_error.re_errno = errno;
+ struct rpc_createerr *ce = &get_rpc_createerr ();
+ ce->cf_stat = RPC_SYSTEMERROR;
+ ce->cf_error.re_errno = errno;
if (*sockp >= 0)
- (void) close (*sockp);
+ (void) __close (*sockp);
goto fooy;
}
ct->ct_closeit = TRUE;
/*
* Initialize call message
*/
- (void) gettimeofday (&now, (struct timezone *) 0);
- call_msg.rm_xid = getpid () ^ now.tv_sec ^ now.tv_usec;
+ call_msg.rm_xid = _create_xid ();
call_msg.rm_direction = CALL;
call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
call_msg.rm_call.cb_prog = prog;
/*
* pre-serialize the static part of the call msg and stash it away
*/
- xdrmem_create (&(ct->ct_xdrs), ct->ct_mcall, MCALL_MSG_SIZE,
- XDR_ENCODE);
- if (!xdr_callhdr (&(ct->ct_xdrs), &call_msg))
+ INTUSE(xdrmem_create) (&(ct->ct_xdrs), ct->ct_mcall, MCALL_MSG_SIZE,
+ XDR_ENCODE);
+ if (!INTUSE(xdr_callhdr) (&(ct->ct_xdrs), &call_msg))
{
if (ct->ct_closeit)
{
- (void) close (*sockp);
+ (void) __close (*sockp);
}
goto fooy;
}
* Create a client handle which uses xdrrec for serialization
* and authnone for authentication.
*/
- xdrrec_create (&(ct->ct_xdrs), sendsz, recvsz,
- (caddr_t) ct, readtcp, writetcp);
- h->cl_ops = &tcp_ops;
+ INTUSE(xdrrec_create) (&(ct->ct_xdrs), sendsz, recvsz,
+ (caddr_t) ct, readtcp, writetcp);
+ h->cl_ops = (struct clnt_ops *) &tcp_ops;
h->cl_private = (caddr_t) ct;
- h->cl_auth = authnone_create ();
+ h->cl_auth = INTUSE(authnone_create) ();
return h;
fooy:
mem_free ((caddr_t) h, sizeof (CLIENT));
return ((CLIENT *) NULL);
}
+INTDEF (clnttcp_create)
static enum clnt_stat
clnttcp_call (h, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout)
}
shipnow =
- (xdr_results == (xdrproc_t) 0 && timeout.tv_sec == 0
- && timeout.tv_usec == 0) ? FALSE : TRUE;
+ (xdr_results == (xdrproc_t) 0 && ct->ct_wait.tv_sec == 0
+ && ct->ct_wait.tv_usec == 0) ? FALSE : TRUE;
call_again:
xdrs->x_op = XDR_ENCODE;
{
if (ct->ct_error.re_status == RPC_SUCCESS)
ct->ct_error.re_status = RPC_CANTENCODEARGS;
- (void) xdrrec_endofrecord (xdrs, TRUE);
+ (void) INTUSE(xdrrec_endofrecord) (xdrs, TRUE);
return (ct->ct_error.re_status);
}
- if (!xdrrec_endofrecord (xdrs, shipnow))
+ if (!INTUSE(xdrrec_endofrecord) (xdrs, shipnow))
return ct->ct_error.re_status = RPC_CANTSEND;
if (!shipnow)
return RPC_SUCCESS;
/*
* Hack to provide rpc-based message passing
*/
- if (timeout.tv_sec == 0 && timeout.tv_usec == 0)
+ if (ct->ct_wait.tv_sec == 0 && ct->ct_wait.tv_usec == 0)
{
return ct->ct_error.re_status = RPC_TIMEDOUT;
}
{
reply_msg.acpted_rply.ar_verf = _null_auth;
reply_msg.acpted_rply.ar_results.where = NULL;
- reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
- if (!xdrrec_skiprecord (xdrs))
+ reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)INTUSE(xdr_void);
+ if (!INTUSE(xdrrec_skiprecord) (xdrs))
return (ct->ct_error.re_status);
/* now decode and validate the response header */
- if (!xdr_replymsg (xdrs, &reply_msg))
+ if (!INTUSE(xdr_replymsg) (xdrs, &reply_msg))
{
if (ct->ct_error.re_status == RPC_SUCCESS)
continue;
return ct->ct_error.re_status;
}
- if (reply_msg.rm_xid == x_id)
+ if ((u_int32_t) reply_msg.rm_xid == (u_int32_t) x_id)
break;
}
if (reply_msg.acpted_rply.ar_verf.oa_base != NULL)
{
xdrs->x_op = XDR_FREE;
- (void) xdr_opaque_auth (xdrs, &(reply_msg.acpted_rply.ar_verf));
+ (void) INTUSE(xdr_opaque_auth) (xdrs,
+ &(reply_msg.acpted_rply.ar_verf));
}
} /* end successful completion */
else
if (ct->ct_closeit)
{
- (void) close (ct->ct_sock);
+ (void) __close (ct->ct_sock);
}
XDR_DESTROY (&(ct->ct_xdrs));
mem_free ((caddr_t) ct, sizeof (struct ct_data));
}
break;
}
- switch (len = read (ct->ct_sock, buf, len))
+ switch (len = __read (ct->ct_sock, buf, len))
{
case 0:
for (cnt = len; cnt > 0; cnt -= i, buf += i)
{
- if ((i = write (ct->ct_sock, buf, cnt)) == -1)
+ if ((i = __write (ct->ct_sock, buf, cnt)) == -1)
{
ct->ct_error.re_errno = errno;
ct->ct_error.re_status = RPC_CANTSEND;