xref: /freebsd/lib/libc/rpc/clnt_bcast.c (revision 734e82fe33aa764367791a7d603b383996c6b40b)
1 /*	$NetBSD: clnt_bcast.c,v 1.3 2000/07/06 03:05:20 christos Exp $	*/
2 
3 /*-
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  * Copyright (c) 2009, Sun Microsystems, Inc.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * - Redistributions of source code must retain the above copyright notice,
12  *   this list of conditions and the following disclaimer.
13  * - Redistributions in binary form must reproduce the above copyright notice,
14  *   this list of conditions and the following disclaimer in the documentation
15  *   and/or other materials provided with the distribution.
16  * - Neither the name of Sun Microsystems, Inc. nor the names of its
17  *   contributors may be used to endorse or promote products derived
18  *   from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*
33  * Copyright (c) 1986-1991 by Sun Microsystems Inc.
34  */
35 
36 #if defined(LIBC_SCCS) && !defined(lint)
37 #ident	"@(#)clnt_bcast.c	1.18	94/05/03 SMI"
38 static char sccsid[] = "@(#)clnt_bcast.c 1.15 89/04/21 Copyr 1988 Sun Micro";
39 #endif
40 #include <sys/cdefs.h>
41 /*
42  * clnt_bcast.c
43  * Client interface to broadcast service.
44  *
45  * Copyright (C) 1988, Sun Microsystems, Inc.
46  *
47  * The following is kludged-up support for simple rpc broadcasts.
48  * Someday a large, complicated system will replace these routines.
49  */
50 
51 #include "namespace.h"
52 #include <sys/types.h>
53 #include <sys/socket.h>
54 #include <sys/queue.h>
55 #include <net/if.h>
56 #include <netinet/in.h>
57 #include <ifaddrs.h>
58 #include <sys/poll.h>
59 #include <rpc/rpc.h>
60 #ifdef PORTMAP
61 #include <rpc/pmap_prot.h>
62 #include <rpc/pmap_clnt.h>
63 #include <rpc/pmap_rmt.h>
64 #endif				/* PORTMAP */
65 #include <rpc/nettype.h>
66 #include <arpa/inet.h>
67 #ifdef RPC_DEBUG
68 #include <stdio.h>
69 #endif
70 #include <errno.h>
71 #include <stdlib.h>
72 #include <unistd.h>
73 #include <netdb.h>
74 #include <err.h>
75 #include <string.h>
76 #include "un-namespace.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 struct broadif {
108 	int index;
109 	struct sockaddr_storage broadaddr;
110 	TAILQ_ENTRY(broadif) link;
111 };
112 
113 typedef TAILQ_HEAD(, broadif) broadlist_t;
114 
115 int __rpc_getbroadifs(int, int, int, broadlist_t *);
116 void __rpc_freebroadifs(broadlist_t *);
117 int __rpc_broadenable(int, int, struct broadif *);
118 
119 int __rpc_lowvers = 0;
120 
121 int
122 __rpc_getbroadifs(int af, int proto, int socktype, broadlist_t *list)
123 {
124 	int count = 0;
125 	struct broadif *bip;
126 	struct ifaddrs *ifap, *ifp;
127 #ifdef INET6
128 	struct sockaddr_in6 *sin6;
129 #endif
130 	struct sockaddr_in *sin;
131 	struct addrinfo hints, *res;
132 
133 	if (getifaddrs(&ifp) < 0)
134 		return 0;
135 
136 	memset(&hints, 0, sizeof hints);
137 
138 	hints.ai_family = af;
139 	hints.ai_protocol = proto;
140 	hints.ai_socktype = socktype;
141 
142 	if (getaddrinfo(NULL, "sunrpc", &hints, &res) != 0) {
143 		freeifaddrs(ifp);
144 		return 0;
145 	}
146 
147 	for (ifap = ifp; ifap != NULL; ifap = ifap->ifa_next) {
148 		if (ifap->ifa_addr->sa_family != af ||
149 		    !(ifap->ifa_flags & IFF_UP))
150 			continue;
151 		bip = (struct broadif *)malloc(sizeof *bip);
152 		if (bip == NULL)
153 			break;
154 		bip->index = if_nametoindex(ifap->ifa_name);
155 		if (
156 #ifdef INET6
157 		af != AF_INET6 &&
158 #endif
159 		(ifap->ifa_flags & IFF_BROADCAST) &&
160 		 ifap->ifa_broadaddr) {
161 			memcpy(&bip->broadaddr, ifap->ifa_broadaddr,
162 			    (size_t)ifap->ifa_broadaddr->sa_len);
163 			sin = (struct sockaddr_in *)(void *)&bip->broadaddr;
164 			sin->sin_port =
165 			    ((struct sockaddr_in *)
166 			    (void *)res->ai_addr)->sin_port;
167 		} else
168 #ifdef INET6
169 		if (af == AF_INET6 && (ifap->ifa_flags & IFF_MULTICAST)) {
170 			sin6 = (struct sockaddr_in6 *)(void *)&bip->broadaddr;
171 			inet_pton(af, RPCB_MULTICAST_ADDR, &sin6->sin6_addr);
172 			sin6->sin6_family = af;
173 			sin6->sin6_len = sizeof *sin6;
174 			sin6->sin6_port =
175 			    ((struct sockaddr_in6 *)
176 			    (void *)res->ai_addr)->sin6_port;
177 			sin6->sin6_scope_id = bip->index;
178 		} else
179 #endif
180 		{
181 			free(bip);
182 			continue;
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 /*ARGSUSED*/
209 __rpc_broadenable(int af, int s, struct broadif *bip)
210 {
211 	int o = 1;
212 
213 #if 0
214 	if (af == AF_INET6) {
215 		fprintf(stderr, "set v6 multicast if to %d\n", bip->index);
216 		if (_setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &bip->index,
217 		    sizeof bip->index) < 0)
218 			return -1;
219 	} else
220 #endif
221 		if (_setsockopt(s, SOL_SOCKET, SO_BROADCAST, &o, sizeof o) < 0)
222 			return -1;
223 
224 	return 0;
225 }
226 
227 /*
228  * rpc_broadcast_exp()
229  *
230  * prog      - program number
231  * vers      - version number
232  * proc      - procedure number
233  * xargs     - xdr routine for args
234  * argsp     - pointer to args
235  * xresults  - xdr routine for results
236  * resultsp  - pointer to results
237  * eachresult - call with each result obtained
238  * inittime  - how long to wait initially
239  * waittime  - maximum time to wait
240  * nettype   - transport type
241  */
242 enum clnt_stat
243 rpc_broadcast_exp(rpcprog_t prog, rpcvers_t vers, rpcproc_t proc,
244     xdrproc_t xargs, caddr_t argsp, xdrproc_t xresults, caddr_t resultsp,
245     resultproc_t eachresult, int inittime, int waittime,
246     const char *nettype)
247 {
248 	enum clnt_stat	stat = RPC_SUCCESS; /* Return status */
249 	XDR 		xdr_stream; /* XDR stream */
250 	XDR 		*xdrs = &xdr_stream;
251 	struct rpc_msg	msg;	/* RPC message */
252 	struct timeval	t;
253 	char 		*outbuf = NULL;	/* Broadcast msg buffer */
254 	char		*inbuf = NULL; /* Reply buf */
255 	int		inlen;
256 	u_int 		maxbufsize = 0;
257 	AUTH 		*sys_auth = authunix_create_default();
258 	u_int		i;
259 	void		*handle;
260 	char		uaddress[1024];	/* A self imposed limit */
261 	char		*uaddrp = uaddress;
262 	int 		pmap_reply_flag; /* reply recvd from PORTMAP */
263 	/* An array of all the suitable broadcast transports */
264 	struct {
265 		int fd;		/* File descriptor */
266 		int af;
267 		int proto;
268 		struct netconfig *nconf; /* Netconfig structure */
269 		u_int asize;	/* Size of the addr buf */
270 		u_int dsize;	/* Size of the data buf */
271 		struct sockaddr_storage raddr; /* Remote address */
272 		broadlist_t nal;
273 	} fdlist[MAXBCAST];
274 	struct pollfd pfd[MAXBCAST];
275 	size_t fdlistno = 0;
276 	struct r_rpcb_rmtcallargs barg;	/* Remote arguments */
277 	struct r_rpcb_rmtcallres bres; /* Remote results */
278 	size_t outlen;
279 	struct netconfig *nconf;
280 	int msec;
281 	int pollretval;
282 	int fds_found;
283 
284 #ifdef PORTMAP
285 	size_t outlen_pmap = 0;
286 	u_long port;		/* Remote port number */
287 	int pmap_flag = 0;	/* UDP exists ? */
288 	char *outbuf_pmap = NULL;
289 	struct rmtcallargs barg_pmap;	/* Remote arguments */
290 	struct rmtcallres bres_pmap; /* Remote results */
291 	u_int udpbufsz = 0;
292 #endif				/* PORTMAP */
293 
294 	if (sys_auth == NULL) {
295 		return (RPC_SYSTEMERROR);
296 	}
297 	/*
298 	 * initialization: create a fd, a broadcast address, and send the
299 	 * request on the broadcast transport.
300 	 * Listen on all of them and on replies, call the user supplied
301 	 * function.
302 	 */
303 
304 	if (nettype == NULL)
305 		nettype = "datagram_n";
306 	if ((handle = __rpc_setconf(nettype)) == NULL) {
307 		AUTH_DESTROY(sys_auth);
308 		return (RPC_UNKNOWNPROTO);
309 	}
310 	while ((nconf = __rpc_getconf(handle)) != NULL) {
311 		int fd;
312 		struct __rpc_sockinfo si;
313 
314 		if (nconf->nc_semantics != NC_TPI_CLTS)
315 			continue;
316 		if (fdlistno >= MAXBCAST)
317 			break;	/* No more slots available */
318 		if (!__rpc_nconf2sockinfo(nconf, &si))
319 			continue;
320 
321 		TAILQ_INIT(&fdlist[fdlistno].nal);
322 		if (__rpc_getbroadifs(si.si_af, si.si_proto, si.si_socktype,
323 		    &fdlist[fdlistno].nal) == 0)
324 			continue;
325 
326 		fd = _socket(si.si_af, si.si_socktype, si.si_proto);
327 		if (fd < 0) {
328 			stat = RPC_CANTSEND;
329 			continue;
330 		}
331 		fdlist[fdlistno].af = si.si_af;
332 		fdlist[fdlistno].proto = si.si_proto;
333 		fdlist[fdlistno].fd = fd;
334 		fdlist[fdlistno].nconf = nconf;
335 		fdlist[fdlistno].asize = __rpc_get_a_size(si.si_af);
336 		pfd[fdlistno].events = POLLIN | POLLPRI |
337 			POLLRDNORM | POLLRDBAND;
338 		pfd[fdlistno].fd = fdlist[fdlistno].fd = fd;
339 		fdlist[fdlistno].dsize = __rpc_get_t_size(si.si_af, si.si_proto,
340 							  0);
341 
342 		if (maxbufsize <= fdlist[fdlistno].dsize)
343 			maxbufsize = fdlist[fdlistno].dsize;
344 
345 #ifdef PORTMAP
346 		if (si.si_af == AF_INET && si.si_proto == IPPROTO_UDP) {
347 			udpbufsz = fdlist[fdlistno].dsize;
348 			outbuf_pmap = reallocf(outbuf_pmap, udpbufsz);
349 			if (outbuf_pmap == NULL) {
350 				_close(fd);
351 				stat = RPC_SYSTEMERROR;
352 				goto done_broad;
353 			}
354 			pmap_flag = 1;
355 		}
356 #endif				/* PORTMAP */
357 		fdlistno++;
358 	}
359 
360 	if (fdlistno == 0) {
361 		if (stat == RPC_SUCCESS)
362 			stat = RPC_UNKNOWNPROTO;
363 		goto done_broad;
364 	}
365 	if (maxbufsize == 0) {
366 		if (stat == RPC_SUCCESS)
367 			stat = RPC_CANTSEND;
368 		goto done_broad;
369 	}
370 	inbuf = malloc(maxbufsize);
371 	outbuf = malloc(maxbufsize);
372 	if ((inbuf == NULL) || (outbuf == NULL)) {
373 		stat = RPC_SYSTEMERROR;
374 		goto done_broad;
375 	}
376 
377 	/* Serialize all the arguments which have to be sent */
378 	(void) gettimeofday(&t, NULL);
379 	msg.rm_xid = __RPC_GETXID(&t);
380 	msg.rm_direction = CALL;
381 	msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
382 	msg.rm_call.cb_prog = RPCBPROG;
383 	msg.rm_call.cb_vers = RPCBVERS;
384 	msg.rm_call.cb_proc = RPCBPROC_CALLIT;
385 	barg.prog = prog;
386 	barg.vers = vers;
387 	barg.proc = proc;
388 	barg.args.args_val = argsp;
389 	barg.xdr_args = xargs;
390 	bres.addr = uaddrp;
391 	bres.results.results_val = resultsp;
392 	bres.xdr_res = xresults;
393 	msg.rm_call.cb_cred = sys_auth->ah_cred;
394 	msg.rm_call.cb_verf = sys_auth->ah_verf;
395 	xdrmem_create(xdrs, outbuf, maxbufsize, XDR_ENCODE);
396 	if ((!xdr_callmsg(xdrs, &msg)) ||
397 	    (!xdr_rpcb_rmtcallargs(xdrs,
398 	    (struct rpcb_rmtcallargs *)(void *)&barg))) {
399 		stat = RPC_CANTENCODEARGS;
400 		goto done_broad;
401 	}
402 	outlen = xdr_getpos(xdrs);
403 	xdr_destroy(xdrs);
404 
405 #ifdef PORTMAP
406 	/* Prepare the packet for version 2 PORTMAP */
407 	if (pmap_flag) {
408 		msg.rm_xid++;	/* One way to distinguish */
409 		msg.rm_call.cb_prog = PMAPPROG;
410 		msg.rm_call.cb_vers = PMAPVERS;
411 		msg.rm_call.cb_proc = PMAPPROC_CALLIT;
412 		barg_pmap.prog = prog;
413 		barg_pmap.vers = vers;
414 		barg_pmap.proc = proc;
415 		barg_pmap.args_ptr = argsp;
416 		barg_pmap.xdr_args = xargs;
417 		bres_pmap.port_ptr = &port;
418 		bres_pmap.xdr_results = xresults;
419 		bres_pmap.results_ptr = resultsp;
420 		xdrmem_create(xdrs, outbuf_pmap, udpbufsz, XDR_ENCODE);
421 		if ((! xdr_callmsg(xdrs, &msg)) ||
422 		    (! xdr_rmtcall_args(xdrs, &barg_pmap))) {
423 			stat = RPC_CANTENCODEARGS;
424 			goto done_broad;
425 		}
426 		outlen_pmap = xdr_getpos(xdrs);
427 		xdr_destroy(xdrs);
428 	}
429 #endif				/* PORTMAP */
430 
431 	/*
432 	 * Basic loop: broadcast the packets to transports which
433 	 * support data packets of size such that one can encode
434 	 * all the arguments.
435 	 * Wait a while for response(s).
436 	 * The response timeout grows larger per iteration.
437 	 */
438 	for (msec = inittime; msec <= waittime; msec += msec) {
439 		struct broadif *bip;
440 
441 		/* Broadcast all the packets now */
442 		for (i = 0; i < fdlistno; i++) {
443 			if (fdlist[i].dsize < outlen) {
444 				stat = RPC_CANTSEND;
445 				continue;
446 			}
447 			for (bip = TAILQ_FIRST(&fdlist[i].nal); bip != NULL;
448 			     bip = TAILQ_NEXT(bip, link)) {
449 				void *addr;
450 
451 				addr = &bip->broadaddr;
452 
453 				__rpc_broadenable(fdlist[i].af, fdlist[i].fd,
454 				    bip);
455 
456 				/*
457 				 * Only use version 3 if lowvers is not set
458 				 */
459 
460 				if (!__rpc_lowvers)
461 					if (_sendto(fdlist[i].fd, outbuf,
462 					    outlen, 0, (struct sockaddr*)addr,
463 					    (size_t)fdlist[i].asize) !=
464 					    outlen) {
465 #ifdef RPC_DEBUG
466 						perror("sendto");
467 #endif
468 						warnx("clnt_bcast: cannot send "
469 						      "broadcast packet");
470 						stat = RPC_CANTSEND;
471 						continue;
472 					}
473 #ifdef RPC_DEBUG
474 				if (!__rpc_lowvers)
475 					fprintf(stderr, "Broadcast packet sent "
476 						"for %s\n",
477 						 fdlist[i].nconf->nc_netid);
478 #endif
479 #ifdef PORTMAP
480 				/*
481 				 * Send the version 2 packet also
482 				 * for UDP/IP
483 				 */
484 				if (pmap_flag &&
485 				    fdlist[i].proto == IPPROTO_UDP) {
486 					if (_sendto(fdlist[i].fd, outbuf_pmap,
487 					    outlen_pmap, 0, addr,
488 					    (size_t)fdlist[i].asize) !=
489 						outlen_pmap) {
490 						warnx("clnt_bcast: "
491 						    "Cannot send broadcast packet");
492 						stat = RPC_CANTSEND;
493 						continue;
494 					}
495 				}
496 #ifdef RPC_DEBUG
497 				fprintf(stderr, "PMAP Broadcast packet "
498 					"sent for %s\n",
499 					fdlist[i].nconf->nc_netid);
500 #endif
501 #endif				/* PORTMAP */
502 			}
503 			/* End for sending all packets on this transport */
504 		}	/* End for sending on all transports */
505 
506 		if (eachresult == NULL) {
507 			stat = RPC_SUCCESS;
508 			goto done_broad;
509 		}
510 
511 		/*
512 		 * Get all the replies from these broadcast requests
513 		 */
514 	recv_again:
515 
516 		switch (pollretval = _poll(pfd, fdlistno, msec)) {
517 		case 0:		/* timed out */
518 			stat = RPC_TIMEDOUT;
519 			continue;
520 		case -1:	/* some kind of error - we ignore it */
521 			goto recv_again;
522 		}		/* end of poll results switch */
523 
524 		for (i = fds_found = 0;
525 		     i < fdlistno && fds_found < pollretval; i++) {
526 			bool_t done = FALSE;
527 
528 			if (pfd[i].revents == 0)
529 				continue;
530 			else if (pfd[i].revents & POLLNVAL) {
531 				/*
532 				 * Something bad has happened to this descri-
533 				 * ptor. We can cause _poll() to ignore
534 				 * it simply by using a negative fd.  We do that
535 				 * rather than compacting the pfd[] and fdlist[]
536 				 * arrays.
537 				 */
538 				pfd[i].fd = -1;
539 				fds_found++;
540 				continue;
541 			} else
542 				fds_found++;
543 #ifdef RPC_DEBUG
544 			fprintf(stderr, "response for %s\n",
545 				fdlist[i].nconf->nc_netid);
546 #endif
547 		try_again:
548 			inlen = _recvfrom(fdlist[i].fd, inbuf, fdlist[i].dsize,
549 			    0, (struct sockaddr *)(void *)&fdlist[i].raddr,
550 			    &fdlist[i].asize);
551 			if (inlen < 0) {
552 				if (errno == EINTR)
553 					goto try_again;
554 				warnx("clnt_bcast: Cannot receive reply to "
555 					"broadcast");
556 				stat = RPC_CANTRECV;
557 				continue;
558 			}
559 			if (inlen < sizeof (u_int32_t))
560 				continue; /* Drop that and go ahead */
561 			/*
562 			 * see if reply transaction id matches sent id.
563 			 * If so, decode the results. If return id is xid + 1
564 			 * it was a PORTMAP reply
565 			 */
566 			if (*((u_int32_t *)(void *)(inbuf)) ==
567 			    *((u_int32_t *)(void *)(outbuf))) {
568 				pmap_reply_flag = 0;
569 				msg.acpted_rply.ar_verf = _null_auth;
570 				msg.acpted_rply.ar_results.where =
571 					(caddr_t)(void *)&bres;
572 				msg.acpted_rply.ar_results.proc =
573 					(xdrproc_t)xdr_rpcb_rmtcallres;
574 #ifdef PORTMAP
575 			} else if (pmap_flag &&
576 				*((u_int32_t *)(void *)(inbuf)) ==
577 				*((u_int32_t *)(void *)(outbuf_pmap))) {
578 				pmap_reply_flag = 1;
579 				msg.acpted_rply.ar_verf = _null_auth;
580 				msg.acpted_rply.ar_results.where =
581 					(caddr_t)(void *)&bres_pmap;
582 				msg.acpted_rply.ar_results.proc =
583 					(xdrproc_t)xdr_rmtcallres;
584 #endif				/* PORTMAP */
585 			} else
586 				continue;
587 			xdrmem_create(xdrs, inbuf, (u_int)inlen, XDR_DECODE);
588 			if (xdr_replymsg(xdrs, &msg)) {
589 				if ((msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
590 				    (msg.acpted_rply.ar_stat == SUCCESS)) {
591 					struct netbuf taddr, *np;
592 					struct sockaddr_in *sin;
593 
594 #ifdef PORTMAP
595 					if (pmap_flag && pmap_reply_flag) {
596 						sin = (struct sockaddr_in *)
597 						    (void *)&fdlist[i].raddr;
598 						sin->sin_port =
599 						    htons((u_short)port);
600 						taddr.len = taddr.maxlen =
601 						    fdlist[i].raddr.ss_len;
602 						taddr.buf = &fdlist[i].raddr;
603 						done = (*eachresult)(resultsp,
604 						    &taddr, fdlist[i].nconf);
605 					} else {
606 #endif				/* PORTMAP */
607 #ifdef RPC_DEBUG
608 						fprintf(stderr, "uaddr %s\n",
609 						    uaddrp);
610 #endif
611 						np = uaddr2taddr(
612 						    fdlist[i].nconf, uaddrp);
613 						done = (*eachresult)(resultsp,
614 						    np, fdlist[i].nconf);
615 						free(np);
616 #ifdef PORTMAP
617 					}
618 #endif				/* PORTMAP */
619 				}
620 				/* otherwise, we just ignore the errors ... */
621 			}
622 			/* else some kind of deserialization problem ... */
623 
624 			xdrs->x_op = XDR_FREE;
625 			msg.acpted_rply.ar_results.proc = (xdrproc_t) xdr_void;
626 			(void) xdr_replymsg(xdrs, &msg);
627 			(void) (*xresults)(xdrs, resultsp);
628 			XDR_DESTROY(xdrs);
629 			if (done) {
630 				stat = RPC_SUCCESS;
631 				goto done_broad;
632 			} else {
633 				goto recv_again;
634 			}
635 		}		/* The recv for loop */
636 	}			/* The giant for loop */
637 
638 done_broad:
639 	free(inbuf);
640 	free(outbuf);
641 #ifdef PORTMAP
642 	free(outbuf_pmap);
643 #endif				/* PORTMAP */
644 	for (i = 0; i < fdlistno; i++) {
645 		(void)_close(fdlist[i].fd);
646 		__rpc_freebroadifs(&fdlist[i].nal);
647 	}
648 	AUTH_DESTROY(sys_auth);
649 	(void) __rpc_endconf(handle);
650 
651 	return (stat);
652 }
653 
654 /*
655  * rpc_broadcast()
656  *
657  * prog       - program number
658  * vers       - version number
659  * proc       - procedure number
660  * xargs      - xdr routine for args
661  * argsp      - pointer to args
662  * xresults   - xdr routine for results
663  * resultsp   - pointer to results
664  * eachresult - call with each result obtained
665  * nettype    - transport type
666  */
667 enum clnt_stat
668 rpc_broadcast(rpcprog_t prog, rpcvers_t vers, rpcproc_t proc, xdrproc_t xargs,
669     caddr_t argsp, xdrproc_t xresults, caddr_t resultsp,
670     resultproc_t eachresult, const char *nettype)
671 {
672 	enum clnt_stat	dummy;
673 
674 	dummy = rpc_broadcast_exp(prog, vers, proc, xargs, argsp,
675 		xresults, resultsp, eachresult,
676 		INITTIME, WAITTIME, nettype);
677 	return (dummy);
678 }
679