Home | History | Annotate | Line # | Download | only in rpc
pmap_rmt.c revision 1.22
      1  1.22     lukem /*	$NetBSD: pmap_rmt.c,v 1.22 1999/09/16 11:45:24 lukem Exp $	*/
      2   1.4       cgd 
      3   1.1       cgd /*
      4   1.1       cgd  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
      5   1.1       cgd  * unrestricted use provided that this legend is included on all tape
      6   1.1       cgd  * media and as a part of the software program in whole or part.  Users
      7   1.1       cgd  * may copy or modify Sun RPC without charge, but are not authorized
      8   1.1       cgd  * to license or distribute it to anyone else except as part of a product or
      9   1.1       cgd  * program developed by the user.
     10   1.1       cgd  *
     11   1.1       cgd  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
     12   1.1       cgd  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
     13   1.1       cgd  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
     14   1.1       cgd  *
     15   1.1       cgd  * Sun RPC is provided with no support and without any obligation on the
     16   1.1       cgd  * part of Sun Microsystems, Inc. to assist in its use, correction,
     17   1.1       cgd  * modification or enhancement.
     18   1.1       cgd  *
     19   1.1       cgd  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
     20   1.1       cgd  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
     21   1.1       cgd  * OR ANY PART THEREOF.
     22   1.1       cgd  *
     23   1.1       cgd  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
     24   1.1       cgd  * or profits or other special, indirect and consequential damages, even if
     25   1.1       cgd  * Sun has been advised of the possibility of such damages.
     26   1.1       cgd  *
     27   1.1       cgd  * Sun Microsystems, Inc.
     28   1.1       cgd  * 2550 Garcia Avenue
     29   1.1       cgd  * Mountain View, California  94043
     30   1.1       cgd  */
     31   1.1       cgd 
     32   1.9  christos #include <sys/cdefs.h>
     33   1.1       cgd #if defined(LIBC_SCCS) && !defined(lint)
     34   1.9  christos #if 0
     35   1.9  christos static char *sccsid = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
     36   1.9  christos static char *sccsid = "@(#)pmap_rmt.c	2.2 88/08/01 4.0 RPCSRC";
     37   1.9  christos #else
     38  1.22     lukem __RCSID("$NetBSD: pmap_rmt.c,v 1.22 1999/09/16 11:45:24 lukem Exp $");
     39   1.9  christos #endif
     40   1.1       cgd #endif
     41   1.1       cgd 
     42   1.1       cgd /*
     43   1.1       cgd  * pmap_rmt.c
     44   1.1       cgd  * Client interface to pmap rpc service.
     45   1.1       cgd  * remote call and broadcast service
     46   1.1       cgd  *
     47   1.1       cgd  * Copyright (C) 1984, Sun Microsystems, Inc.
     48   1.1       cgd  */
     49   1.1       cgd 
     50  1.10       jtc #include "namespace.h"
     51  1.14     lukem 
     52   1.7       mrg #include <sys/types.h>
     53  1.14     lukem #include <sys/ioctl.h>
     54   1.7       mrg #include <sys/poll.h>
     55  1.14     lukem #include <sys/socket.h>
     56  1.14     lukem 
     57  1.14     lukem #include <net/if.h>
     58  1.14     lukem #include <netinet/in.h>
     59  1.14     lukem #include <arpa/inet.h>
     60  1.14     lukem 
     61  1.22     lukem #include <assert.h>
     62  1.14     lukem #include <err.h>
     63  1.14     lukem #include <errno.h>
     64  1.14     lukem #include <stdio.h>
     65  1.14     lukem #include <string.h>
     66  1.14     lukem #include <unistd.h>
     67  1.13     lukem 
     68  1.13     lukem #include <rpc/rpc.h>
     69  1.13     lukem #include <rpc/pmap_prot.h>
     70  1.13     lukem #include <rpc/pmap_clnt.h>
     71  1.13     lukem #include <rpc/pmap_rmt.h>
     72   1.7       mrg 
     73  1.10       jtc #ifdef __weak_alias
     74  1.10       jtc __weak_alias(clnt_broadcast,_clnt_broadcast);
     75  1.10       jtc __weak_alias(pmap_rmtcall,_pmap_rmtcall);
     76  1.10       jtc __weak_alias(xdr_rmtcall_args,_xdr_rmtcall_args);
     77  1.10       jtc __weak_alias(xdr_rmtcallres,_xdr_rmtcallres);
     78  1.10       jtc #endif
     79  1.10       jtc 
     80   1.1       cgd #define MAX_BROADCAST_SIZE 1400
     81   1.1       cgd 
     82   1.9  christos static int getbroadcastnets __P((struct in_addr *, int, char *));
     83   1.9  christos 
     84  1.16   mycroft static const struct timeval timeout = { 3, 0 };
     85   1.1       cgd 
     86   1.1       cgd /*
     87   1.1       cgd  * pmapper remote-call-service interface.
     88   1.1       cgd  * This routine is used to call the pmapper remote call service
     89   1.1       cgd  * which will look up a service program in the port maps, and then
     90   1.1       cgd  * remotely call that routine with the given parameters.  This allows
     91   1.1       cgd  * programs to do a lookup and call in one step.
     92   1.1       cgd */
     93   1.1       cgd enum clnt_stat
     94  1.18     lukem pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout,
     95  1.18     lukem     port_ptr)
     96   1.1       cgd 	struct sockaddr_in *addr;
     97  1.13     lukem 	u_long prog, vers, proc;
     98   1.1       cgd 	xdrproc_t xdrargs, xdrres;
     99   1.1       cgd 	caddr_t argsp, resp;
    100   1.1       cgd 	struct timeval tout;
    101  1.13     lukem 	u_long *port_ptr;
    102   1.1       cgd {
    103  1.17  christos 	int sock = -1;
    104  1.14     lukem 	CLIENT *client;
    105   1.1       cgd 	struct rmtcallargs a;
    106   1.1       cgd 	struct rmtcallres r;
    107   1.1       cgd 	enum clnt_stat stat;
    108   1.1       cgd 
    109  1.22     lukem 	_DIAGASSERT(addr != NULL);
    110  1.22     lukem 	_DIAGASSERT(port_ptr != NULL);
    111  1.22     lukem #ifdef _DIAGNOSTIC
    112  1.22     lukem 	if (addr == NULL || port_ptr == NULL) {
    113  1.22     lukem 		errno = EFAULT;
    114  1.22     lukem 		return (RPC_SYSTEMERROR);
    115  1.22     lukem 	}
    116  1.22     lukem #endif
    117  1.22     lukem 
    118   1.1       cgd 	addr->sin_port = htons(PMAPPORT);
    119  1.17  christos 	client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock);
    120   1.1       cgd 	if (client != (CLIENT *)NULL) {
    121   1.1       cgd 		a.prog = prog;
    122   1.1       cgd 		a.vers = vers;
    123   1.1       cgd 		a.proc = proc;
    124   1.1       cgd 		a.args_ptr = argsp;
    125   1.1       cgd 		a.xdr_args = xdrargs;
    126   1.1       cgd 		r.port_ptr = port_ptr;
    127   1.1       cgd 		r.results_ptr = resp;
    128   1.1       cgd 		r.xdr_results = xdrres;
    129  1.19  christos 		stat = CLNT_CALL(client, PMAPPROC_CALLIT,
    130  1.19  christos 		    (xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres,
    131  1.19  christos 		    &r, tout);
    132   1.1       cgd 		CLNT_DESTROY(client);
    133   1.1       cgd 	} else {
    134   1.1       cgd 		stat = RPC_FAILED;
    135   1.1       cgd 	}
    136   1.1       cgd 	addr->sin_port = 0;
    137   1.1       cgd 	return (stat);
    138   1.1       cgd }
    139   1.1       cgd 
    140   1.1       cgd 
    141   1.1       cgd /*
    142   1.1       cgd  * XDR remote call arguments
    143   1.1       cgd  * written for XDR_ENCODE direction only
    144   1.1       cgd  */
    145   1.1       cgd bool_t
    146   1.1       cgd xdr_rmtcall_args(xdrs, cap)
    147  1.14     lukem 	XDR *xdrs;
    148  1.14     lukem 	struct rmtcallargs *cap;
    149   1.1       cgd {
    150  1.13     lukem 	u_int lenposition, argposition, position;
    151   1.1       cgd 
    152  1.22     lukem 	_DIAGASSERT(xdrs != NULL);
    153  1.22     lukem 	_DIAGASSERT(cap != NULL);
    154  1.22     lukem #ifdef _DIAGNOSTIC
    155  1.22     lukem 	if (xdrs == NULL || cap == NULL)
    156  1.22     lukem 		return (FALSE);
    157  1.22     lukem #endif
    158  1.22     lukem 
    159  1.13     lukem 	if (xdr_u_long(xdrs, &(cap->prog)) &&
    160  1.13     lukem 	    xdr_u_long(xdrs, &(cap->vers)) &&
    161  1.13     lukem 	    xdr_u_long(xdrs, &(cap->proc))) {
    162   1.1       cgd 		lenposition = XDR_GETPOS(xdrs);
    163  1.13     lukem 		if (! xdr_u_long(xdrs, &(cap->arglen)))
    164   1.1       cgd 		    return (FALSE);
    165   1.1       cgd 		argposition = XDR_GETPOS(xdrs);
    166   1.1       cgd 		if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
    167   1.1       cgd 		    return (FALSE);
    168   1.1       cgd 		position = XDR_GETPOS(xdrs);
    169  1.13     lukem 		cap->arglen = (u_long)position - (u_long)argposition;
    170   1.1       cgd 		XDR_SETPOS(xdrs, lenposition);
    171  1.13     lukem 		if (! xdr_u_long(xdrs, &(cap->arglen)))
    172   1.1       cgd 		    return (FALSE);
    173   1.1       cgd 		XDR_SETPOS(xdrs, position);
    174   1.1       cgd 		return (TRUE);
    175   1.1       cgd 	}
    176   1.1       cgd 	return (FALSE);
    177   1.1       cgd }
    178   1.1       cgd 
    179   1.1       cgd /*
    180   1.1       cgd  * XDR remote call results
    181   1.1       cgd  * written for XDR_DECODE direction only
    182   1.1       cgd  */
    183   1.1       cgd bool_t
    184   1.1       cgd xdr_rmtcallres(xdrs, crp)
    185  1.14     lukem 	XDR *xdrs;
    186  1.14     lukem 	struct rmtcallres *crp;
    187   1.1       cgd {
    188   1.1       cgd 	caddr_t port_ptr;
    189   1.1       cgd 
    190  1.22     lukem 	_DIAGASSERT(xdrs != NULL);
    191  1.22     lukem 	_DIAGASSERT(crp != NULL);
    192  1.22     lukem #ifdef _DIAGNOSTIC
    193  1.22     lukem 	if (xdrs == NULL || crp == NULL)
    194  1.22     lukem 		return (FALSE);
    195  1.22     lukem #endif
    196  1.22     lukem 
    197  1.17  christos 	port_ptr = (caddr_t)(void *)crp->port_ptr;
    198  1.13     lukem 	if (xdr_reference(xdrs, &port_ptr, sizeof (u_long),
    199  1.19  christos 	    (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
    200  1.17  christos 		crp->port_ptr = (u_long *)(void *)port_ptr;
    201   1.1       cgd 		return ((*(crp->xdr_results))(xdrs, crp->results_ptr));
    202   1.1       cgd 	}
    203   1.1       cgd 	return (FALSE);
    204   1.1       cgd }
    205   1.1       cgd 
    206   1.1       cgd 
    207   1.1       cgd /*
    208   1.1       cgd  * The following is kludged-up support for simple rpc broadcasts.
    209   1.1       cgd  * Someday a large, complicated system will replace these trivial
    210   1.1       cgd  * routines which only support udp/ip .
    211   1.1       cgd  */
    212   1.1       cgd 
    213   1.1       cgd static int
    214   1.1       cgd getbroadcastnets(addrs, sock, buf)
    215   1.1       cgd 	struct in_addr *addrs;
    216   1.1       cgd 	int sock;  /* any valid socket will do */
    217   1.1       cgd 	char *buf;  /* why allocxate more when we can use existing... */
    218   1.1       cgd {
    219   1.1       cgd 	struct ifconf ifc;
    220   1.1       cgd         struct ifreq ifreq, *ifr;
    221   1.1       cgd 	struct sockaddr_in *sin;
    222   1.1       cgd         char *cp, *cplim;
    223   1.9  christos         int i = 0;
    224  1.22     lukem 
    225  1.22     lukem 	_DIAGASSERT(addrs != NULL);
    226  1.22     lukem 	_DIAGASSERT(buf != NULL);
    227   1.1       cgd 
    228   1.1       cgd         ifc.ifc_len = UDPMSGSIZE;
    229   1.1       cgd         ifc.ifc_buf = buf;
    230  1.17  christos         if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
    231  1.18     lukem                 warn("getbroadcastnets: ioctl (get interface configuration)");
    232   1.1       cgd                 return (0);
    233   1.1       cgd         }
    234   1.1       cgd #define max(a, b) (a > b ? a : b)
    235   1.1       cgd #define size(p)	max((p).sa_len, sizeof(p))
    236   1.1       cgd 	cplim = buf + ifc.ifc_len; /*skip over if's with big ifr_addr's */
    237   1.1       cgd 	for (cp = buf; cp < cplim;
    238   1.1       cgd 			cp += sizeof (ifr->ifr_name) + size(ifr->ifr_addr)) {
    239  1.17  christos 		ifr = (struct ifreq *)(void *)cp;
    240   1.1       cgd 		if (ifr->ifr_addr.sa_family != AF_INET)
    241   1.1       cgd 			continue;
    242   1.1       cgd 		ifreq = *ifr;
    243  1.17  christos                 if (ioctl(sock, SIOCGIFFLAGS, &ifreq) < 0) {
    244  1.18     lukem                         warn("getbroadcastnets: ioctl (get interface flags)");
    245   1.1       cgd                         continue;
    246   1.1       cgd                 }
    247   1.1       cgd                 if ((ifreq.ifr_flags & IFF_BROADCAST) &&
    248   1.1       cgd 		    (ifreq.ifr_flags & IFF_UP)) {
    249  1.17  christos 			sin = (struct sockaddr_in *)(void *)&ifr->ifr_addr;
    250   1.1       cgd #ifdef SIOCGIFBRDADDR   /* 4.3BSD */
    251  1.17  christos 			if (ioctl(sock, SIOCGIFBRDADDR, &ifreq) < 0) {
    252   1.1       cgd 				addrs[i++] =
    253   1.1       cgd 				    inet_makeaddr(inet_netof(sin->sin_addr),
    254  1.17  christos 				    (unsigned long)INADDR_ANY);
    255   1.1       cgd 			} else {
    256  1.17  christos 				addrs[i++] = ((struct sockaddr_in *)(void *)
    257   1.1       cgd 				  &ifreq.ifr_addr)->sin_addr;
    258   1.1       cgd 			}
    259   1.1       cgd #else /* 4.2 BSD */
    260   1.1       cgd 			addrs[i++] = inet_makeaddr(inet_netof(sin->sin_addr),
    261   1.1       cgd 			    INADDR_ANY);
    262   1.1       cgd #endif
    263   1.1       cgd 		}
    264   1.1       cgd 	}
    265   1.1       cgd 	return (i);
    266   1.1       cgd }
    267   1.1       cgd 
    268   1.9  christos typedef bool_t (*resultproc_t) __P((caddr_t, struct sockaddr_in *));
    269   1.1       cgd 
    270   1.1       cgd enum clnt_stat
    271   1.1       cgd clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
    272  1.13     lukem 	u_long		prog;		/* program number */
    273  1.13     lukem 	u_long		vers;		/* version number */
    274  1.13     lukem 	u_long		proc;		/* procedure number */
    275   1.1       cgd 	xdrproc_t	xargs;		/* xdr routine for args */
    276   1.1       cgd 	caddr_t		argsp;		/* pointer to args */
    277   1.1       cgd 	xdrproc_t	xresults;	/* xdr routine for results */
    278   1.1       cgd 	caddr_t		resultsp;	/* pointer to results */
    279   1.1       cgd 	resultproc_t	eachresult;	/* call with each result obtained */
    280   1.1       cgd {
    281   1.1       cgd 	enum clnt_stat stat;
    282   1.1       cgd 	AUTH *unix_auth = authunix_create_default();
    283   1.1       cgd 	XDR xdr_stream;
    284  1.14     lukem 	XDR *xdrs = &xdr_stream;
    285  1.21  christos 	int inlen, nets;
    286  1.21  christos 	socklen_t fromlen;
    287  1.17  christos 	size_t outlen;
    288  1.14     lukem 	int sock;
    289   1.1       cgd 	int on = 1;
    290   1.7       mrg 	struct pollfd fd;
    291  1.14     lukem 	int i;
    292   1.1       cgd 	bool_t done = FALSE;
    293  1.17  christos 	u_int32_t xid;
    294  1.13     lukem 	u_long port;
    295   1.1       cgd 	struct in_addr addrs[20];
    296   1.1       cgd 	struct sockaddr_in baddr, raddr; /* broadcast and response addresses */
    297   1.1       cgd 	struct rmtcallargs a;
    298   1.1       cgd 	struct rmtcallres r;
    299   1.1       cgd 	struct rpc_msg msg;
    300   1.1       cgd 	struct timeval t;
    301   1.7       mrg 	int milliseconds;
    302   1.1       cgd 	char outbuf[MAX_BROADCAST_SIZE], inbuf[UDPMSGSIZE];
    303   1.1       cgd 
    304   1.1       cgd 	/*
    305   1.1       cgd 	 * initialization: create a socket, a broadcast address, and
    306   1.1       cgd 	 * preserialize the arguments into a send buffer.
    307   1.1       cgd 	 */
    308   1.1       cgd 	if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
    309  1.18     lukem 		warn("Cannot create socket for broadcast rpc");
    310   1.1       cgd 		stat = RPC_CANTSEND;
    311   1.1       cgd 		goto done_broad;
    312   1.1       cgd 	}
    313   1.1       cgd #ifdef SO_BROADCAST
    314   1.1       cgd 	if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) {
    315  1.18     lukem 		warn("Cannot set socket option SO_BROADCAST");
    316   1.1       cgd 		stat = RPC_CANTSEND;
    317   1.1       cgd 		goto done_broad;
    318   1.1       cgd 	}
    319   1.1       cgd #endif /* def SO_BROADCAST */
    320   1.7       mrg 	fd.fd = sock;
    321   1.8   mycroft 	fd.events = POLLIN;
    322   1.1       cgd 	nets = getbroadcastnets(addrs, sock, inbuf);
    323   1.5       jtc 	memset(&baddr, 0, sizeof (baddr));
    324   1.6   mycroft 	baddr.sin_len = sizeof(struct sockaddr_in);
    325   1.1       cgd 	baddr.sin_family = AF_INET;
    326   1.1       cgd 	baddr.sin_port = htons(PMAPPORT);
    327   1.1       cgd 	baddr.sin_addr.s_addr = htonl(INADDR_ANY);
    328   1.1       cgd 	(void)gettimeofday(&t, (struct timezone *)0);
    329  1.17  christos 	msg.rm_xid = xid = (u_int32_t)(getpid() ^ t.tv_sec ^ t.tv_usec);
    330   1.1       cgd 	t.tv_usec = 0;
    331   1.1       cgd 	msg.rm_direction = CALL;
    332   1.1       cgd 	msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
    333   1.1       cgd 	msg.rm_call.cb_prog = PMAPPROG;
    334   1.1       cgd 	msg.rm_call.cb_vers = PMAPVERS;
    335   1.1       cgd 	msg.rm_call.cb_proc = PMAPPROC_CALLIT;
    336   1.1       cgd 	msg.rm_call.cb_cred = unix_auth->ah_cred;
    337   1.1       cgd 	msg.rm_call.cb_verf = unix_auth->ah_verf;
    338   1.1       cgd 	a.prog = prog;
    339   1.1       cgd 	a.vers = vers;
    340   1.1       cgd 	a.proc = proc;
    341   1.1       cgd 	a.xdr_args = xargs;
    342   1.1       cgd 	a.args_ptr = argsp;
    343   1.1       cgd 	r.port_ptr = &port;
    344   1.1       cgd 	r.xdr_results = xresults;
    345   1.1       cgd 	r.results_ptr = resultsp;
    346   1.1       cgd 	xdrmem_create(xdrs, outbuf, MAX_BROADCAST_SIZE, XDR_ENCODE);
    347   1.1       cgd 	if ((! xdr_callmsg(xdrs, &msg)) || (! xdr_rmtcall_args(xdrs, &a))) {
    348   1.1       cgd 		stat = RPC_CANTENCODEARGS;
    349   1.1       cgd 		goto done_broad;
    350   1.1       cgd 	}
    351  1.17  christos 	outlen = xdr_getpos(xdrs);
    352   1.1       cgd 	xdr_destroy(xdrs);
    353   1.1       cgd 	/*
    354   1.1       cgd 	 * Basic loop: broadcast a packet and wait a while for response(s).
    355   1.1       cgd 	 * The response timeout grows larger per iteration.
    356   1.1       cgd 	 */
    357   1.1       cgd 	for (t.tv_sec = 4; t.tv_sec <= 14; t.tv_sec += 2) {
    358   1.1       cgd 		for (i = 0; i < nets; i++) {
    359   1.1       cgd 			baddr.sin_addr = addrs[i];
    360   1.1       cgd 			if (sendto(sock, outbuf, outlen, 0,
    361  1.17  christos 				(struct sockaddr *)(void *)&baddr,
    362   1.1       cgd 				sizeof (struct sockaddr)) != outlen) {
    363  1.18     lukem 				warn("Cannot send broadcast packet");
    364   1.1       cgd 				stat = RPC_CANTSEND;
    365   1.1       cgd 				goto done_broad;
    366   1.1       cgd 			}
    367   1.1       cgd 		}
    368   1.1       cgd 		if (eachresult == NULL) {
    369   1.1       cgd 			stat = RPC_SUCCESS;
    370   1.1       cgd 			goto done_broad;
    371   1.1       cgd 		}
    372   1.1       cgd 	recv_again:
    373  1.17  christos 		milliseconds = (int)(t.tv_sec * 1000 + t.tv_usec / 1000);
    374   1.1       cgd 		msg.acpted_rply.ar_verf = _null_auth;
    375  1.17  christos 		msg.acpted_rply.ar_results.where = (caddr_t)(void *)&r;
    376  1.19  christos                 msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_rmtcallres;
    377   1.7       mrg 		switch (poll(&fd, 1, milliseconds)) {
    378   1.1       cgd 
    379   1.1       cgd 		case 0:  /* timed out */
    380   1.1       cgd 			stat = RPC_TIMEDOUT;
    381   1.1       cgd 			continue;
    382   1.1       cgd 
    383   1.1       cgd 		case -1:  /* some kind of error */
    384   1.1       cgd 			if (errno == EINTR)
    385   1.1       cgd 				goto recv_again;
    386  1.18     lukem 			warn("Broadcast poll problem");
    387   1.1       cgd 			stat = RPC_CANTRECV;
    388   1.1       cgd 			goto done_broad;
    389   1.1       cgd 
    390   1.7       mrg 		}  /* end of poll results switch */
    391   1.1       cgd 	try_again:
    392   1.1       cgd 		fromlen = sizeof(struct sockaddr);
    393   1.1       cgd 		inlen = recvfrom(sock, inbuf, UDPMSGSIZE, 0,
    394  1.17  christos 			(struct sockaddr *)(void *)&raddr, &fromlen);
    395   1.1       cgd 		if (inlen < 0) {
    396   1.1       cgd 			if (errno == EINTR)
    397   1.1       cgd 				goto try_again;
    398  1.18     lukem 			warn("Cannot receive reply to broadcast");
    399   1.1       cgd 			stat = RPC_CANTRECV;
    400   1.1       cgd 			goto done_broad;
    401   1.1       cgd 		}
    402   1.3       cgd 		if (inlen < sizeof(u_int32_t))
    403   1.1       cgd 			goto recv_again;
    404   1.1       cgd 		/*
    405   1.1       cgd 		 * see if reply transaction id matches sent id.
    406   1.1       cgd 		 * If so, decode the results.
    407   1.1       cgd 		 */
    408  1.13     lukem 		xdrmem_create(xdrs, inbuf, (u_int)inlen, XDR_DECODE);
    409   1.1       cgd 		if (xdr_replymsg(xdrs, &msg)) {
    410   1.1       cgd 			if ((msg.rm_xid == xid) &&
    411   1.1       cgd 				(msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
    412   1.1       cgd 				(msg.acpted_rply.ar_stat == SUCCESS)) {
    413  1.13     lukem 				raddr.sin_port = htons((u_short)port);
    414   1.1       cgd 				done = (*eachresult)(resultsp, &raddr);
    415   1.1       cgd 			}
    416   1.1       cgd 			/* otherwise, we just ignore the errors ... */
    417   1.1       cgd 		} else {
    418   1.1       cgd #ifdef notdef
    419   1.1       cgd 			/* some kind of deserialization problem ... */
    420   1.1       cgd 			if (msg.rm_xid == xid)
    421  1.18     lukem 				fprintf(stderr,
    422  1.18     lukem 				    "Broadcast deserialization problem");
    423   1.1       cgd 			/* otherwise, just random garbage */
    424   1.1       cgd #endif
    425   1.1       cgd 		}
    426   1.1       cgd 		xdrs->x_op = XDR_FREE;
    427  1.19  christos 		msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
    428   1.1       cgd 		(void)xdr_replymsg(xdrs, &msg);
    429   1.1       cgd 		(void)(*xresults)(xdrs, resultsp);
    430   1.1       cgd 		xdr_destroy(xdrs);
    431   1.1       cgd 		if (done) {
    432   1.1       cgd 			stat = RPC_SUCCESS;
    433   1.1       cgd 			goto done_broad;
    434   1.1       cgd 		} else {
    435   1.1       cgd 			goto recv_again;
    436   1.1       cgd 		}
    437   1.1       cgd 	}
    438  1.15        tv 	stat = RPC_TIMEDOUT;
    439   1.1       cgd done_broad:
    440  1.18     lukem 	if (sock != -1)
    441  1.18     lukem 		(void)close(sock);
    442   1.1       cgd 	AUTH_DESTROY(unix_auth);
    443   1.1       cgd 	return (stat);
    444   1.1       cgd }
    445