Home | History | Annotate | Line # | Download | only in rpc
clnt_bcast.c revision 1.11
      1 /*	$NetBSD: clnt_bcast.c,v 1.11 2003/09/09 00:22:17 itojun Exp $	*/
      2 
      3 /*
      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.
     10  *
     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.
     14  *
     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.
     18  *
     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.
     22  *
     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.
     26  *
     27  * Sun Microsystems, Inc.
     28  * 2550 Garcia Avenue
     29  * Mountain View, California  94043
     30  */
     31 /*
     32  * Copyright (c) 1986-1991 by Sun Microsystems Inc.
     33  */
     34 
     35 /* #ident	"@(#)clnt_bcast.c	1.18	94/05/03 SMI" */
     36 
     37 #if 0
     38 #if !defined(lint) && defined(SCCSIDS)
     39 static char sccsid[] = "@(#)clnt_bcast.c 1.15 89/04/21 Copyr 1988 Sun Micro";
     40 #endif
     41 #endif
     42 
     43 
     44 /*
     45  * clnt_bcast.c
     46  * Client interface to broadcast service.
     47  *
     48  * Copyright (C) 1988, Sun Microsystems, Inc.
     49  *
     50  * The following is kludged-up support for simple rpc broadcasts.
     51  * Someday a large, complicated system will replace these routines.
     52  */
     53 
     54 #include "namespace.h"
     55 #include <sys/types.h>
     56 #include <sys/socket.h>
     57 #include <sys/queue.h>
     58 #include <net/if.h>
     59 #include <netinet/in.h>
     60 #include <ifaddrs.h>
     61 #include <sys/poll.h>
     62 #include <rpc/rpc.h>
     63 #ifdef PORTMAP
     64 #include <rpc/pmap_prot.h>
     65 #include <rpc/pmap_clnt.h>
     66 #include <rpc/pmap_rmt.h>
     67 #endif
     68 #include <rpc/nettype.h>
     69 #include <arpa/inet.h>
     70 #ifdef RPC_DEBUG
     71 #include <stdio.h>
     72 #endif
     73 #include <assert.h>
     74 #include <errno.h>
     75 #include <stdlib.h>
     76 #include <unistd.h>
     77 #include <netdb.h>
     78 #include <err.h>
     79 #include <string.h>
     80 
     81 #include "rpc_internal.h"
     82 
     83 #define	MAXBCAST 20	/* Max no of broadcasting transports */
     84 #define	INITTIME 4000	/* Time to wait initially */
     85 #define	WAITTIME 8000	/* Maximum time to wait */
     86 
     87 /*
     88  * If nettype is NULL, it broadcasts on all the available
     89  * datagram_n transports. May potentially lead to broadacst storms
     90  * and hence should be used with caution, care and courage.
     91  *
     92  * The current parameter xdr packet size is limited by the max tsdu
     93  * size of the transport. If the max tsdu size of any transport is
     94  * smaller than the parameter xdr packet, then broadcast is not
     95  * sent on that transport.
     96  *
     97  * Also, the packet size should be less the packet size of
     98  * the data link layer (for ethernet it is 1400 bytes).  There is
     99  * no easy way to find out the max size of the data link layer and
    100  * we are assuming that the args would be smaller than that.
    101  *
    102  * The result size has to be smaller than the transport tsdu size.
    103  *
    104  * If PORTMAP has been defined, we send two packets for UDP, one for
    105  * rpcbind and one for portmap. For those machines which support
    106  * both rpcbind and portmap, it will cause them to reply twice, and
    107  * also here it will get two responses ... inefficient and clumsy.
    108  */
    109 
    110 #ifdef __weak_alias
    111 __weak_alias(rpc_broadcast_exp,_rpc_broadcast_exp)
    112 __weak_alias(rpc_broadcast,_rpc_broadcast)
    113 #endif
    114 
    115 struct broadif {
    116 	int index;
    117 	struct sockaddr_storage broadaddr;
    118 	TAILQ_ENTRY(broadif) link;
    119 };
    120 
    121 typedef TAILQ_HEAD(, broadif) broadlist_t;
    122 
    123 int __rpc_getbroadifs __P((int, int, int, broadlist_t *));
    124 void __rpc_freebroadifs __P((broadlist_t *));
    125 int __rpc_broadenable __P((int, int, struct broadif *));
    126 
    127 int __rpc_lowvers = 0;
    128 
    129 int
    130 __rpc_getbroadifs(int af, int proto, int socktype, broadlist_t *list)
    131 {
    132 	int count = 0;
    133 	struct broadif *bip;
    134 	struct ifaddrs *ifap, *ifp;
    135 #ifdef INET6
    136 	struct sockaddr_in6 *sin6;
    137 #endif
    138 	struct sockaddr_in *gbsin;
    139 	struct addrinfo hints, *res;
    140 
    141 	_DIAGASSERT(list != NULL);
    142 
    143 	if (getifaddrs(&ifp) < 0)
    144 		return 0;
    145 
    146 	memset(&hints, 0, sizeof hints);
    147 
    148 	hints.ai_family = af;
    149 	hints.ai_protocol = proto;
    150 	hints.ai_socktype = socktype;
    151 
    152 	if (getaddrinfo(NULL, "sunrpc", &hints, &res) != 0)
    153 		return 0;
    154 
    155 	for (ifap = ifp; ifap != NULL; ifap = ifap->ifa_next) {
    156 		if (ifap->ifa_addr->sa_family != af ||
    157 		    !(ifap->ifa_flags & IFF_UP))
    158 			continue;
    159 		bip = (struct broadif *)malloc(sizeof *bip);
    160 		if (bip == NULL)
    161 			break;
    162 		bip->index = if_nametoindex(ifap->ifa_name);
    163 		if (
    164 #ifdef INET6
    165 		    af != AF_INET6 &&
    166 #endif
    167 		    (ifap->ifa_flags & IFF_BROADCAST) &&
    168 		    ifap->ifa_broadaddr) {
    169 			memcpy(&bip->broadaddr, ifap->ifa_broadaddr,
    170 			    (size_t)ifap->ifa_broadaddr->sa_len);
    171 			gbsin = (struct sockaddr_in *)(void *)&bip->broadaddr;
    172 			gbsin->sin_port =
    173 			    ((struct sockaddr_in *)
    174 			    (void *)res->ai_addr)->sin_port;
    175 		} else
    176 #ifdef INET6
    177 		if (af == AF_INET6 && (ifap->ifa_flags & IFF_MULTICAST)) {
    178 			sin6 = (struct sockaddr_in6 *)(void *)&bip->broadaddr;
    179 			inet_pton(af, RPCB_MULTICAST_ADDR, &sin6->sin6_addr);
    180 			sin6->sin6_family = af;
    181 			sin6->sin6_len = sizeof *sin6;
    182 			sin6->sin6_port =
    183 			    ((struct sockaddr_in6 *)
    184 			    (void *)res->ai_addr)->sin6_port;
    185 			sin6->sin6_scope_id = bip->index;
    186 		} else
    187 #endif
    188 		{
    189 			free(bip);
    190 			continue;
    191 		}
    192 		TAILQ_INSERT_TAIL(list, bip, link);
    193 		count++;
    194 	}
    195 	freeifaddrs(ifp);
    196 	freeaddrinfo(res);
    197 
    198 	return count;
    199 }
    200 
    201 void
    202 __rpc_freebroadifs(broadlist_t *list)
    203 {
    204 	struct broadif *bip, *next;
    205 
    206 	_DIAGASSERT(list != NULL);
    207 
    208 	bip = TAILQ_FIRST(list);
    209 
    210 	while (bip != NULL) {
    211 		next = TAILQ_NEXT(bip, link);
    212 		free(bip);
    213 		bip = next;
    214 	}
    215 }
    216 
    217 int
    218 /*ARGSUSED*/
    219 __rpc_broadenable(int af, int s, struct broadif *bip)
    220 {
    221 	int o = 1;
    222 
    223 #if 0
    224 	_DIAGASSERT(bip != NULL);
    225 
    226 	if (af == AF_INET6) {
    227 		fprintf(stderr, "set v6 multicast if to %d\n", bip->index);
    228 		if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &bip->index,
    229 		    sizeof bip->index) < 0)
    230 			return -1;
    231 	} else
    232 #endif
    233 		if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &o, sizeof o) < 0)
    234 			return -1;
    235 
    236 	return 0;
    237 }
    238 
    239 
    240 enum clnt_stat
    241 rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
    242 	eachresult, inittime, waittime, nettype)
    243 	rpcprog_t	prog;		/* program number */
    244 	rpcvers_t	vers;		/* version number */
    245 	rpcproc_t	proc;		/* procedure number */
    246 	xdrproc_t	xargs;		/* xdr routine for args */
    247 	caddr_t		argsp;		/* pointer to args */
    248 	xdrproc_t	xresults;	/* xdr routine for results */
    249 	caddr_t		resultsp;	/* pointer to results */
    250 	resultproc_t	eachresult;	/* call with each result obtained */
    251 	int 		inittime;	/* how long to wait initially */
    252 	int 		waittime;	/* maximum time to wait */
    253 	const char		*nettype;	/* transport type */
    254 {
    255 	enum clnt_stat	stat = RPC_SUCCESS; /* Return status */
    256 	XDR 		xdr_stream; /* XDR stream */
    257 	XDR 		*xdrs = &xdr_stream;
    258 	struct rpc_msg	msg;	/* RPC message */
    259 	char 		*outbuf = NULL;	/* Broadcast msg buffer */
    260 	char		*inbuf = NULL; /* Reply buf */
    261 	int		inlen;
    262 	u_int 		maxbufsize = 0;
    263 	AUTH 		*sys_auth = authunix_create_default();
    264 	int		i;
    265 	void		*handle;
    266 	char		uaddress[1024];	/* A self imposed limit */
    267 	char		*uaddrp = uaddress;
    268 	int 		pmap_reply_flag; /* reply recvd from PORTMAP */
    269 	/* An array of all the suitable broadcast transports */
    270 	struct {
    271 		int fd;		/* File descriptor */
    272 		int af;
    273 		int proto;
    274 		struct netconfig *nconf; /* Netconfig structure */
    275 		u_int asize;	/* Size of the addr buf */
    276 		u_int dsize;	/* Size of the data buf */
    277 		struct sockaddr_storage raddr; /* Remote address */
    278 		broadlist_t nal;
    279 	} fdlist[MAXBCAST];
    280 	struct pollfd pfd[MAXBCAST];
    281 	size_t fdlistno = 0;
    282 	struct r_rpcb_rmtcallargs barg;	/* Remote arguments */
    283 	struct r_rpcb_rmtcallres bres; /* Remote results */
    284 	size_t outlen;
    285 	struct netconfig *nconf;
    286 	int msec;
    287 	int pollretval;
    288 	int fds_found;
    289 
    290 #ifdef PORTMAP
    291 	size_t outlen_pmap;
    292 	u_long port;		/* Remote port number */
    293 	int pmap_flag = 0;	/* UDP exists ? */
    294 	char *outbuf_pmap = NULL;
    295 	struct rmtcallargs barg_pmap;	/* Remote arguments */
    296 	struct rmtcallres bres_pmap; /* Remote results */
    297 	u_int udpbufsz = 0;
    298 #endif				/* PORTMAP */
    299 
    300 	if (sys_auth == NULL) {
    301 		return (RPC_SYSTEMERROR);
    302 	}
    303 	/*
    304 	 * initialization: create a fd, a broadcast address, and send the
    305 	 * request on the broadcast transport.
    306 	 * Listen on all of them and on replies, call the user supplied
    307 	 * function.
    308 	 */
    309 
    310 	if (nettype == NULL)
    311 		nettype = "datagram_n";
    312 	if ((handle = __rpc_setconf(nettype)) == NULL) {
    313 		return (RPC_UNKNOWNPROTO);
    314 	}
    315 	while ((nconf = __rpc_getconf(handle)) != NULL) {
    316 		int fd;
    317 		struct __rpc_sockinfo si;
    318 
    319 		if (nconf->nc_semantics != NC_TPI_CLTS)
    320 			continue;
    321 		if (fdlistno >= MAXBCAST)
    322 			break;	/* No more slots available */
    323 		if (!__rpc_nconf2sockinfo(nconf, &si))
    324 			continue;
    325 
    326 		TAILQ_INIT(&fdlist[fdlistno].nal);
    327 		if (__rpc_getbroadifs(si.si_af, si.si_proto, si.si_socktype,
    328 		    &fdlist[fdlistno].nal) == 0)
    329 			continue;
    330 
    331 		fd = socket(si.si_af, si.si_socktype, si.si_proto);
    332 		if (fd < 0) {
    333 			stat = RPC_CANTSEND;
    334 			continue;
    335 		}
    336 		fdlist[fdlistno].af = si.si_af;
    337 		fdlist[fdlistno].proto = si.si_proto;
    338 		fdlist[fdlistno].fd = fd;
    339 		fdlist[fdlistno].nconf = nconf;
    340 		fdlist[fdlistno].asize = __rpc_get_a_size(si.si_af);
    341 		pfd[fdlistno].events = POLLIN | POLLPRI |
    342 			POLLRDNORM | POLLRDBAND;
    343 		pfd[fdlistno].fd = fdlist[fdlistno].fd = fd;
    344 		fdlist[fdlistno].dsize = __rpc_get_t_size(si.si_af, si.si_proto,
    345 							  0);
    346 
    347 		if (maxbufsize <= fdlist[fdlistno].dsize)
    348 			maxbufsize = fdlist[fdlistno].dsize;
    349 
    350 #ifdef PORTMAP
    351 		if (si.si_af == AF_INET && si.si_proto == IPPROTO_UDP) {
    352 			udpbufsz = fdlist[fdlistno].dsize;
    353 			if ((outbuf_pmap = malloc(udpbufsz)) == NULL) {
    354 				close(fd);
    355 				stat = RPC_SYSTEMERROR;
    356 				goto done_broad;
    357 			}
    358 			pmap_flag = 1;
    359 		}
    360 #endif
    361 		fdlistno++;
    362 	}
    363 
    364 	if (fdlistno == 0) {
    365 		if (stat == RPC_SUCCESS)
    366 			stat = RPC_UNKNOWNPROTO;
    367 		goto done_broad;
    368 	}
    369 	if (maxbufsize == 0) {
    370 		if (stat == RPC_SUCCESS)
    371 			stat = RPC_CANTSEND;
    372 		goto done_broad;
    373 	}
    374 	inbuf = malloc(maxbufsize);
    375 	outbuf = malloc(maxbufsize);
    376 	if ((inbuf == NULL) || (outbuf == NULL)) {
    377 		stat = RPC_SYSTEMERROR;
    378 		goto done_broad;
    379 	}
    380 
    381 	/* Serialize all the arguments which have to be sent */
    382 	msg.rm_xid = __RPC_GETXID();
    383 	msg.rm_direction = CALL;
    384 	msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
    385 	msg.rm_call.cb_prog = RPCBPROG;
    386 	msg.rm_call.cb_vers = RPCBVERS;
    387 	msg.rm_call.cb_proc = RPCBPROC_CALLIT;
    388 	barg.prog = prog;
    389 	barg.vers = vers;
    390 	barg.proc = proc;
    391 	barg.args.args_val = argsp;
    392 	barg.xdr_args = xargs;
    393 	bres.addr = uaddrp;
    394 	bres.results.results_val = resultsp;
    395 	bres.xdr_res = xresults;
    396 	msg.rm_call.cb_cred = sys_auth->ah_cred;
    397 	msg.rm_call.cb_verf = sys_auth->ah_verf;
    398 	xdrmem_create(xdrs, outbuf, maxbufsize, XDR_ENCODE);
    399 	if ((!xdr_callmsg(xdrs, &msg)) ||
    400 	    (!xdr_rpcb_rmtcallargs(xdrs,
    401 	    (struct rpcb_rmtcallargs *)(void *)&barg))) {
    402 		stat = RPC_CANTENCODEARGS;
    403 		goto done_broad;
    404 	}
    405 	outlen = xdr_getpos(xdrs);
    406 	xdr_destroy(xdrs);
    407 
    408 #ifdef PORTMAP
    409 	/* Prepare the packet for version 2 PORTMAP */
    410 	if (pmap_flag) {
    411 		msg.rm_xid++;	/* One way to distinguish */
    412 		msg.rm_call.cb_prog = PMAPPROG;
    413 		msg.rm_call.cb_vers = PMAPVERS;
    414 		msg.rm_call.cb_proc = PMAPPROC_CALLIT;
    415 		barg_pmap.prog = prog;
    416 		barg_pmap.vers = vers;
    417 		barg_pmap.proc = proc;
    418 		barg_pmap.args_ptr = argsp;
    419 		barg_pmap.xdr_args = xargs;
    420 		bres_pmap.port_ptr = &port;
    421 		bres_pmap.xdr_results = xresults;
    422 		bres_pmap.results_ptr = resultsp;
    423 		xdrmem_create(xdrs, outbuf_pmap, udpbufsz, XDR_ENCODE);
    424 		if ((! xdr_callmsg(xdrs, &msg)) ||
    425 		    (! xdr_rmtcall_args(xdrs, &barg_pmap))) {
    426 			stat = RPC_CANTENCODEARGS;
    427 			goto done_broad;
    428 		}
    429 		outlen_pmap = xdr_getpos(xdrs);
    430 		xdr_destroy(xdrs);
    431 	}
    432 #endif				/* PORTMAP */
    433 
    434 	/*
    435 	 * Basic loop: broadcast the packets to transports which
    436 	 * support data packets of size such that one can encode
    437 	 * all the arguments.
    438 	 * Wait a while for response(s).
    439 	 * The response timeout grows larger per iteration.
    440 	 */
    441 	for (msec = inittime; msec <= waittime; msec += msec) {
    442 		struct broadif *bip;
    443 
    444 		/* Broadcast all the packets now */
    445 		for (i = 0; i < fdlistno; i++) {
    446 			if (fdlist[i].dsize < outlen) {
    447 				stat = RPC_CANTSEND;
    448 				continue;
    449 			}
    450 			for (bip = TAILQ_FIRST(&fdlist[i].nal); bip != NULL;
    451 			     bip = TAILQ_NEXT(bip, link)) {
    452 				void *addr;
    453 
    454 				addr = &bip->broadaddr;
    455 
    456 				__rpc_broadenable(fdlist[i].af, fdlist[i].fd,
    457 				    bip);
    458 
    459 				/*
    460 				 * Only use version 3 if lowvers is not set
    461 				 */
    462 
    463 				if (!__rpc_lowvers)
    464 					if (sendto(fdlist[i].fd, outbuf,
    465 					    outlen, 0, (struct sockaddr*)addr,
    466 					    (size_t)fdlist[i].asize) !=
    467 					    outlen) {
    468 #ifdef RPC_DEBUG
    469 						perror("sendto");
    470 #endif
    471 						warnx("clnt_bcast: cannot send"
    472 						      " broadcast packet");
    473 						stat = RPC_CANTSEND;
    474 						continue;
    475 					};
    476 #ifdef RPC_DEBUG
    477 				if (!__rpc_lowvers)
    478 					fprintf(stderr, "Broadcast packet sent "
    479 						"for %s\n",
    480 						 fdlist[i].nconf->nc_netid);
    481 #endif
    482 #ifdef PORTMAP
    483 				/*
    484 				 * Send the version 2 packet also
    485 				 * for UDP/IP
    486 				 */
    487 				if (pmap_flag && fdlist[i].proto == IPPROTO_UDP) {
    488 					if (sendto(fdlist[i].fd, outbuf_pmap,
    489 					    outlen_pmap, 0, addr,
    490 					    (size_t)fdlist[i].asize) !=
    491 						outlen_pmap) {
    492 						warnx("clnt_bcast: "
    493 				"Cannot send broadcast packet");
    494 						stat = RPC_CANTSEND;
    495 						continue;
    496 					}
    497 				}
    498 #ifdef RPC_DEBUG
    499 				fprintf(stderr, "PMAP Broadcast packet "
    500 					"sent for %s\n",
    501 					fdlist[i].nconf->nc_netid);
    502 #endif
    503 #endif				/* PORTMAP */
    504 			}
    505 			/* End for sending all packets on this transport */
    506 		}	/* End for sending on all transports */
    507 
    508 		if (eachresult == NULL) {
    509 			stat = RPC_SUCCESS;
    510 			goto done_broad;
    511 		}
    512 
    513 		/*
    514 		 * Get all the replies from these broadcast requests
    515 		 */
    516 	recv_again:
    517 
    518 		switch (pollretval = poll(pfd, fdlistno, msec)) {
    519 		case 0:		/* timed out */
    520 			stat = RPC_TIMEDOUT;
    521 			continue;
    522 		case -1:	/* some kind of error - we ignore it */
    523 			goto recv_again;
    524 		}		/* end of poll results switch */
    525 
    526 		for (i = fds_found = 0;
    527 		     i < fdlistno && fds_found < pollretval; i++) {
    528 			bool_t done = FALSE;
    529 
    530 			if (pfd[i].revents == 0)
    531 				continue;
    532 			else if (pfd[i].revents & POLLNVAL) {
    533 				/*
    534 				 * Something bad has happened to this descri-
    535 				 * ptor. We can cause poll() to ignore
    536 				 * it simply by using a negative fd.  We do that
    537 				 * rather than compacting the pfd[] and fdlist[]
    538 				 * arrays.
    539 				 */
    540 				pfd[i].fd = -1;
    541 				fds_found++;
    542 				continue;
    543 			} else
    544 				fds_found++;
    545 #ifdef RPC_DEBUG
    546 			fprintf(stderr, "response for %s\n",
    547 				fdlist[i].nconf->nc_netid);
    548 #endif
    549 		try_again:
    550 			inlen = recvfrom(fdlist[i].fd, inbuf, fdlist[i].dsize,
    551 			    0, (struct sockaddr *)(void *)&fdlist[i].raddr,
    552 			    &fdlist[i].asize);
    553 			if (inlen < 0) {
    554 				if (errno == EINTR)
    555 					goto try_again;
    556 				warnx("clnt_bcast: Cannot receive reply to "
    557 					"broadcast");
    558 				stat = RPC_CANTRECV;
    559 				continue;
    560 			}
    561 			if (inlen < sizeof (u_int32_t))
    562 				continue; /* Drop that and go ahead */
    563 			/*
    564 			 * see if reply transaction id matches sent id.
    565 			 * If so, decode the results. If return id is xid + 1
    566 			 * it was a PORTMAP reply
    567 			 */
    568 			if (*((u_int32_t *)(void *)(inbuf)) ==
    569 			    *((u_int32_t *)(void *)(outbuf))) {
    570 				pmap_reply_flag = 0;
    571 				msg.acpted_rply.ar_verf = _null_auth;
    572 				msg.acpted_rply.ar_results.where =
    573 					(caddr_t)(void *)&bres;
    574 				msg.acpted_rply.ar_results.proc =
    575 					(xdrproc_t)xdr_rpcb_rmtcallres;
    576 #ifdef PORTMAP
    577 			} else if (pmap_flag &&
    578 				*((u_int32_t *)(void *)(inbuf)) ==
    579 				*((u_int32_t *)(void *)(outbuf_pmap))) {
    580 				pmap_reply_flag = 1;
    581 				msg.acpted_rply.ar_verf = _null_auth;
    582 				msg.acpted_rply.ar_results.where =
    583 					(caddr_t)(void *)&bres_pmap;
    584 				msg.acpted_rply.ar_results.proc =
    585 					(xdrproc_t)xdr_rmtcallres;
    586 #endif				/* PORTMAP */
    587 			} else
    588 				continue;
    589 			xdrmem_create(xdrs, inbuf, (u_int)inlen, XDR_DECODE);
    590 			if (xdr_replymsg(xdrs, &msg)) {
    591 				if ((msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
    592 				    (msg.acpted_rply.ar_stat == SUCCESS)) {
    593 					struct netbuf taddr, *np;
    594 					struct sockaddr_in *bsin;
    595 
    596 #ifdef PORTMAP
    597 					if (pmap_flag && pmap_reply_flag) {
    598 						bsin = (struct sockaddr_in *)
    599 						    (void *)&fdlist[i].raddr;
    600 						bsin->sin_port =
    601 						    htons((u_short)port);
    602 						taddr.len = taddr.maxlen =
    603 						    fdlist[i].raddr.ss_len;
    604 						taddr.buf = &fdlist[i].raddr;
    605 						done = (*eachresult)(resultsp,
    606 						    &taddr, fdlist[i].nconf);
    607 					} else {
    608 #endif
    609 #ifdef RPC_DEBUG
    610 						fprintf(stderr, "uaddr %s\n",
    611 						    uaddrp);
    612 #endif
    613 						np = uaddr2taddr(
    614 						    fdlist[i].nconf, uaddrp);
    615 						done = (*eachresult)(resultsp,
    616 						    np, fdlist[i].nconf);
    617 						free(np);
    618 #ifdef PORTMAP
    619 					}
    620 #endif
    621 				}
    622 				/* otherwise, we just ignore the errors ... */
    623 			}
    624 			/* else some kind of deserialization problem ... */
    625 
    626 			xdrs->x_op = XDR_FREE;
    627 			msg.acpted_rply.ar_results.proc = (xdrproc_t) xdr_void;
    628 			(void) xdr_replymsg(xdrs, &msg);
    629 			(void) (*xresults)(xdrs, resultsp);
    630 			XDR_DESTROY(xdrs);
    631 			if (done) {
    632 				stat = RPC_SUCCESS;
    633 				goto done_broad;
    634 			} else {
    635 				goto recv_again;
    636 			}
    637 		}		/* The recv for loop */
    638 	}			/* The giant for loop */
    639 
    640 done_broad:
    641 	if (inbuf)
    642 		(void) free(inbuf);
    643 	if (outbuf)
    644 		(void) free(outbuf);
    645 #ifdef PORTMAP
    646 	if (outbuf_pmap)
    647 		(void) free(outbuf_pmap);
    648 #endif
    649 	for (i = 0; i < fdlistno; i++) {
    650 		(void) close(fdlist[i].fd);
    651 		__rpc_freebroadifs(&fdlist[i].nal);
    652 	}
    653 	AUTH_DESTROY(sys_auth);
    654 	(void) __rpc_endconf(handle);
    655 
    656 	return (stat);
    657 }
    658 
    659 
    660 enum clnt_stat
    661 rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
    662 			eachresult, nettype)
    663 	rpcprog_t	prog;		/* program number */
    664 	rpcvers_t	vers;		/* version number */
    665 	rpcproc_t	proc;		/* procedure number */
    666 	xdrproc_t	xargs;		/* xdr routine for args */
    667 	caddr_t		argsp;		/* pointer to args */
    668 	xdrproc_t	xresults;	/* xdr routine for results */
    669 	caddr_t		resultsp;	/* pointer to results */
    670 	resultproc_t	eachresult;	/* call with each result obtained */
    671 	const char		*nettype;	/* transport type */
    672 {
    673 	enum clnt_stat	dummy;
    674 
    675 	dummy = rpc_broadcast_exp(prog, vers, proc, xargs, argsp,
    676 		xresults, resultsp, eachresult,
    677 		INITTIME, WAITTIME, nettype);
    678 	return (dummy);
    679 }
    680