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