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