summaryrefslogtreecommitdiff
path: root/libc/inet/rpc/pmap_rmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/inet/rpc/pmap_rmt.c')
-rw-r--r--libc/inet/rpc/pmap_rmt.c212
1 files changed, 106 insertions, 106 deletions
diff --git a/libc/inet/rpc/pmap_rmt.c b/libc/inet/rpc/pmap_rmt.c
index 1921b74c1..1f2b47cba 100644
--- a/libc/inet/rpc/pmap_rmt.c
+++ b/libc/inet/rpc/pmap_rmt.c
@@ -63,13 +63,14 @@ static struct timeval timeout = { 3, 0 };
* programs to do a lookup and call in one step.
*/
enum clnt_stat
-pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, port_ptr)
- struct sockaddr_in *addr;
- u_long prog, vers, proc;
- xdrproc_t xdrargs, xdrres;
- caddr_t argsp, resp;
- struct timeval tout;
- u_long *port_ptr;
+pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout,
+ port_ptr)
+struct sockaddr_in *addr;
+u_long prog, vers, proc;
+xdrproc_t xdrargs, xdrres;
+caddr_t argsp, resp;
+struct timeval tout;
+u_long *port_ptr;
{
int socket = -1;
register CLIENT *client;
@@ -79,7 +80,7 @@ pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, port_pt
addr->sin_port = htons(PMAPPORT);
client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &socket);
- if (client != (CLIENT *)NULL) {
+ if (client != (CLIENT *) NULL) {
a.prog = prog;
a.vers = vers;
a.proc = proc;
@@ -89,12 +90,12 @@ pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, port_pt
r.results_ptr = resp;
r.xdr_results = xdrres;
stat = CLNT_CALL(client, PMAPPROC_CALLIT, xdr_rmtcall_args, &a,
- xdr_rmtcallres, &r, tout);
+ xdr_rmtcallres, &r, tout);
CLNT_DESTROY(client);
} else {
stat = RPC_FAILED;
}
- (void)close(socket);
+ (void) close(socket);
addr->sin_port = 0;
return (stat);
}
@@ -104,27 +105,25 @@ pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, port_pt
* XDR remote call arguments
* written for XDR_ENCODE direction only
*/
-bool_t
-xdr_rmtcall_args(xdrs, cap)
- register XDR *xdrs;
- register struct rmtcallargs *cap;
+bool_t xdr_rmtcall_args(xdrs, cap)
+register XDR *xdrs;
+register struct rmtcallargs *cap;
{
u_int lenposition, argposition, position;
if (xdr_u_long(xdrs, &(cap->prog)) &&
- xdr_u_long(xdrs, &(cap->vers)) &&
- xdr_u_long(xdrs, &(cap->proc))) {
+ xdr_u_long(xdrs, &(cap->vers)) && xdr_u_long(xdrs, &(cap->proc))) {
lenposition = XDR_GETPOS(xdrs);
- if (! xdr_u_long(xdrs, &(cap->arglen)))
- return (FALSE);
+ if (!xdr_u_long(xdrs, &(cap->arglen)))
+ return (FALSE);
argposition = XDR_GETPOS(xdrs);
- if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
- return (FALSE);
+ if (!(*(cap->xdr_args)) (xdrs, cap->args_ptr))
+ return (FALSE);
position = XDR_GETPOS(xdrs);
- cap->arglen = (u_long)position - (u_long)argposition;
+ cap->arglen = (u_long) position - (u_long) argposition;
XDR_SETPOS(xdrs, lenposition);
- if (! xdr_u_long(xdrs, &(cap->arglen)))
- return (FALSE);
+ if (!xdr_u_long(xdrs, &(cap->arglen)))
+ return (FALSE);
XDR_SETPOS(xdrs, position);
return (TRUE);
}
@@ -135,18 +134,17 @@ xdr_rmtcall_args(xdrs, cap)
* XDR remote call results
* written for XDR_DECODE direction only
*/
-bool_t
-xdr_rmtcallres(xdrs, crp)
- register XDR *xdrs;
- register struct rmtcallres *crp;
+bool_t xdr_rmtcallres(xdrs, crp)
+register XDR *xdrs;
+register struct rmtcallres *crp;
{
caddr_t port_ptr;
- port_ptr = (caddr_t)crp->port_ptr;
- if (xdr_reference(xdrs, &port_ptr, sizeof (u_long),
- xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
- crp->port_ptr = (u_long *)port_ptr;
- return ((*(crp->xdr_results))(xdrs, crp->results_ptr));
+ port_ptr = (caddr_t) crp->port_ptr;
+ if (xdr_reference(xdrs, &port_ptr, sizeof(u_long),
+ xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
+ crp->port_ptr = (u_long *) port_ptr;
+ return ((*(crp->xdr_results)) (xdrs, crp->results_ptr));
}
return (FALSE);
}
@@ -158,11 +156,10 @@ xdr_rmtcallres(xdrs, crp)
* routines which only support udp/ip .
*/
-static int
-getbroadcastnets(addrs, sock, buf)
- struct in_addr *addrs;
- int sock; /* any valid socket will do */
- char *buf; /* why allocxate more when we can use existing... */
+static int getbroadcastnets(addrs, sock, buf)
+struct in_addr *addrs;
+int sock; /* any valid socket will do */
+char *buf; /* why allocxate more when we can use existing... */
{
#ifdef __linux__
struct sockaddr_in addr;
@@ -176,45 +173,46 @@ getbroadcastnets(addrs, sock, buf)
return 1;
#else
struct ifconf ifc;
- struct ifreq ifreq, *ifr;
+ struct ifreq ifreq, *ifr;
struct sockaddr_in *sin;
- int n, i;
+ int n, i;
- ifc.ifc_len = UDPMSGSIZE;
- ifc.ifc_buf = buf;
- if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
- perror("broadcast: ioctl (get interface configuration)");
- return (0);
- }
- ifr = ifc.ifc_req;
- for (i = 0, n = ifc.ifc_len/sizeof (struct ifreq); n > 0; n--, ifr++) {
- ifreq = *ifr;
- if (ioctl(sock, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
- perror("broadcast: ioctl (get interface flags)");
- continue;
- }
- if ((ifreq.ifr_flags & IFF_BROADCAST) &&
- (ifreq.ifr_flags & IFF_UP) &&
- ifr->ifr_addr.sa_family == AF_INET) {
- sin = (struct sockaddr_in *)&ifr->ifr_addr;
-#ifdef SIOCGIFBRDADDR /* 4.3BSD */
- if (ioctl(sock, SIOCGIFBRDADDR, (char *)&ifreq) < 0) {
+ ifc.ifc_len = UDPMSGSIZE;
+ ifc.ifc_buf = buf;
+ if (ioctl(sock, SIOCGIFCONF, (char *) &ifc) < 0) {
+ perror("broadcast: ioctl (get interface configuration)");
+ return (0);
+ }
+ ifr = ifc.ifc_req;
+ for (i = 0, n = ifc.ifc_len / sizeof(struct ifreq); n > 0; n--, ifr++) {
+ ifreq = *ifr;
+ if (ioctl(sock, SIOCGIFFLAGS, (char *) &ifreq) < 0) {
+ perror("broadcast: ioctl (get interface flags)");
+ continue;
+ }
+ if ((ifreq.ifr_flags & IFF_BROADCAST) &&
+ (ifreq.ifr_flags & IFF_UP) &&
+ ifr->ifr_addr.sa_family == AF_INET) {
+ sin = (struct sockaddr_in *) &ifr->ifr_addr;
+#ifdef SIOCGIFBRDADDR /* 4.3BSD */
+ if (ioctl(sock, SIOCGIFBRDADDR, (char *) &ifreq) < 0) {
#if 1
-printf("%s(%d): no inet_makeaddr()\n", __FILE__, __LINE__);
+ printf("%s(%d): no inet_makeaddr()\n", __FILE__, __LINE__);
#else
addrs[i++] = inet_makeaddr(inet_netof
- (sin->sin_addr.s_addr), INADDR_ANY);
+ (sin->sin_addr.s_addr),
+ INADDR_ANY);
#endif
} else {
- addrs[i++] = ((struct sockaddr_in*)
- &ifreq.ifr_addr)->sin_addr;
+ addrs[i++] = ((struct sockaddr_in *)
+ &ifreq.ifr_addr)->sin_addr;
}
-#else /* 4.2 BSD */
+#else /* 4.2 BSD */
#if 1
-printf("%s(%d): no inet_makeaddr()\n", __FILE__, __LINE__);
+ printf("%s(%d): no inet_makeaddr()\n", __FILE__, __LINE__);
#else
addrs[i++] = inet_makeaddr(inet_netof
- (sin->sin_addr.s_addr), INADDR_ANY);
+ (sin->sin_addr.s_addr), INADDR_ANY);
#endif
#endif
}
@@ -223,18 +221,19 @@ printf("%s(%d): no inet_makeaddr()\n", __FILE__, __LINE__);
#endif
}
-typedef bool_t (*resultproc_t)();
+typedef bool_t(*resultproc_t) ();
-enum clnt_stat
-clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
- u_long prog; /* program number */
- u_long vers; /* version number */
- u_long proc; /* procedure number */
- xdrproc_t xargs; /* xdr routine for args */
- caddr_t argsp; /* pointer to args */
- xdrproc_t xresults; /* xdr routine for results */
- caddr_t resultsp; /* pointer to results */
- resultproc_t eachresult; /* call with each result obtained */
+enum clnt_stat
+clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
+ eachresult)
+u_long prog; /* program number */
+u_long vers; /* version number */
+u_long proc; /* procedure number */
+xdrproc_t xargs; /* xdr routine for args */
+caddr_t argsp; /* pointer to args */
+xdrproc_t xresults; /* xdr routine for results */
+caddr_t resultsp; /* pointer to results */
+resultproc_t eachresult; /* call with each result obtained */
{
enum clnt_stat stat;
AUTH *unix_auth = authunix_create_default();
@@ -243,23 +242,24 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
int outlen, inlen, fromlen, nets;
register int sock;
int on = 1;
+
#ifdef FD_SETSIZE
fd_set mask;
fd_set readfds;
#else
int readfds;
register int mask;
-#endif /* def FD_SETSIZE */
+#endif /* def FD_SETSIZE */
register int i;
bool_t done = FALSE;
register u_long xid;
u_long port;
struct in_addr addrs[20];
- struct sockaddr_in baddr, raddr; /* broadcast and response addresses */
+ struct sockaddr_in baddr, raddr; /* broadcast and response addresses */
struct rmtcallargs a;
struct rmtcallres r;
struct rpc_msg msg;
- struct timeval t;
+ struct timeval t;
char outbuf[MAX_BROADCAST_SIZE], inbuf[UDPMSGSIZE];
/*
@@ -272,25 +272,25 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
goto done_broad;
}
#ifdef SO_BROADCAST
- if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) {
+ if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) < 0) {
perror("Cannot set socket option SO_BROADCAST");
stat = RPC_CANTSEND;
goto done_broad;
}
-#endif /* def SO_BROADCAST */
+#endif /* def SO_BROADCAST */
#ifdef FD_SETSIZE
FD_ZERO(&mask);
FD_SET(sock, &mask);
#else
mask = (1 << sock);
-#endif /* def FD_SETSIZE */
+#endif /* def FD_SETSIZE */
nets = getbroadcastnets(addrs, sock, inbuf);
- bzero((char *)&baddr, sizeof (baddr));
+ bzero((char *) &baddr, sizeof(baddr));
baddr.sin_family = AF_INET;
baddr.sin_port = htons(PMAPPORT);
baddr.sin_addr.s_addr = htonl(INADDR_ANY);
/* baddr.sin_addr.S_un.S_addr = htonl(INADDR_ANY); */
- (void)gettimeofday(&t, (struct timezone *)0);
+ (void) gettimeofday(&t, (struct timezone *) 0);
msg.rm_xid = xid = getpid() ^ t.tv_sec ^ t.tv_usec;
t.tv_usec = 0;
msg.rm_direction = CALL;
@@ -309,11 +309,11 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
r.xdr_results = xresults;
r.results_ptr = resultsp;
xdrmem_create(xdrs, outbuf, MAX_BROADCAST_SIZE, XDR_ENCODE);
- if ((! xdr_callmsg(xdrs, &msg)) || (! xdr_rmtcall_args(xdrs, &a))) {
+ if ((!xdr_callmsg(xdrs, &msg)) || (!xdr_rmtcall_args(xdrs, &a))) {
stat = RPC_CANTENCODEARGS;
goto done_broad;
}
- outlen = (int)xdr_getpos(xdrs);
+ outlen = (int) xdr_getpos(xdrs);
xdr_destroy(xdrs);
/*
* Basic loop: broadcast a packet and wait a while for response(s).
@@ -323,8 +323,8 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
for (i = 0; i < nets; i++) {
baddr.sin_addr = addrs[i];
if (sendto(sock, outbuf, outlen, 0,
- (struct sockaddr *)&baddr,
- sizeof (struct sockaddr)) != outlen) {
+ (struct sockaddr *) &baddr,
+ sizeof(struct sockaddr)) != outlen) {
perror("Cannot send broadcast packet");
stat = RPC_CANTSEND;
goto done_broad;
@@ -334,30 +334,31 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
stat = RPC_SUCCESS;
goto done_broad;
}
- recv_again:
+ recv_again:
msg.acpted_rply.ar_verf = _null_auth;
- msg.acpted_rply.ar_results.where = (caddr_t)&r;
- msg.acpted_rply.ar_results.proc = xdr_rmtcallres;
+ msg.acpted_rply.ar_results.where = (caddr_t) & r;
+ msg.acpted_rply.ar_results.proc = xdr_rmtcallres;
readfds = mask;
- switch (select(_rpc_dtablesize(), &readfds, (int *)NULL,
- (int *)NULL, &t)) {
+ switch (select(_rpc_dtablesize(), &readfds, (int *) NULL,
+ (int *) NULL, &t)) {
- case 0: /* timed out */
+ case 0: /* timed out */
stat = RPC_TIMEDOUT;
continue;
- case -1: /* some kind of error */
+ case -1: /* some kind of error */
if (errno == EINTR)
goto recv_again;
perror("Broadcast select problem");
stat = RPC_CANTRECV;
goto done_broad;
- } /* end of select results switch */
- try_again:
+ } /* end of select results switch */
+ try_again:
fromlen = sizeof(struct sockaddr);
+
inlen = recvfrom(sock, inbuf, UDPMSGSIZE, 0,
- (struct sockaddr *)&raddr, &fromlen);
+ (struct sockaddr *) &raddr, &fromlen);
if (inlen < 0) {
if (errno == EINTR)
goto try_again;
@@ -371,13 +372,13 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
* see if reply transaction id matches sent id.
* If so, decode the results.
*/
- xdrmem_create(xdrs, inbuf, (u_int)inlen, XDR_DECODE);
+ xdrmem_create(xdrs, inbuf, (u_int) inlen, XDR_DECODE);
if (xdr_replymsg(xdrs, &msg)) {
if ((msg.rm_xid == xid) &&
(msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
(msg.acpted_rply.ar_stat == SUCCESS)) {
- raddr.sin_port = htons((u_short)port);
- done = (*eachresult)(resultsp, &raddr);
+ raddr.sin_port = htons((u_short) port);
+ done = (*eachresult) (resultsp, &raddr);
}
/* otherwise, we just ignore the errors ... */
} else {
@@ -390,8 +391,8 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
}
xdrs->x_op = XDR_FREE;
msg.acpted_rply.ar_results.proc = xdr_void;
- (void)xdr_replymsg(xdrs, &msg);
- (void)(*xresults)(xdrs, resultsp);
+ (void) xdr_replymsg(xdrs, &msg);
+ (void) (*xresults) (xdrs, resultsp);
xdr_destroy(xdrs);
if (done) {
stat = RPC_SUCCESS;
@@ -400,9 +401,8 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
goto recv_again;
}
}
-done_broad:
- (void)close(sock);
+ done_broad:
+ (void) close(sock);
AUTH_DESTROY(unix_auth);
return (stat);
}
-