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