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