Debian Codegraph @

extra/tirpc/libtirpc-1.3.5/src/clnt_bcast.c

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