| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 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 |
| 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 |
| 69 |
#define INITTIME 4000 |
| 70 |
#define WAITTIME 8000 |
| 71 |
|
| 72 |
# define POLLRDNORM 0x040 |
| 73 |
# define POLLRDBAND 0x080 |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 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 || |
| 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 |
|
| 159 |
|
| 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 |
|
| 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 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 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 |
|
| 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 |
|
| 248 |
|
| 249 |
sin.sin_port = ((struct sockaddr_in6 *) np)->sin6_port; |
| 250 |
|
| 251 |
|
| 252 |
|
| 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; |
| 263 |
rpcvers_t vers; |
| 264 |
rpcproc_t proc; |
| 265 |
xdrproc_t xargs; |
| 266 |
caddr_t argsp; |
| 267 |
xdrproc_t xresults; |
| 268 |
caddr_t resultsp; |
| 269 |
resultproc_t eachresult; |
| 270 |
int inittime; |
| 271 |
int waittime; |
| 272 |
const char *nettype; |
| 273 |
{ |
| 274 |
enum clnt_stat stat = RPC_SUCCESS; |
| 275 |
XDR xdr_stream; |
| 276 |
XDR *xdrs = &xdr_stream; |
| 277 |
struct rpc_msg msg; |
| 278 |
struct timeval t; |
| 279 |
char *outbuf = NULL; |
| 280 |
char *inbuf = NULL; |
| 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]; |
| 287 |
char *uaddrp = uaddress; |
| 288 |
int pmap_reply_flag; |
| 289 |
|
| 290 |
struct { |
| 291 |
int fd; |
| 292 |
int af; |
| 293 |
int proto; |
| 294 |
struct netconfig *nconf; |
| 295 |
u_int asize; |
| 296 |
u_int dsize; |
| 297 |
struct sockaddr_storage raddr; |
| 298 |
broadlist_t nal; |
| 299 |
} fdlist[MAXBCAST]; |
| 300 |
struct pollfd pfd[MAXBCAST]; |
| 301 |
size_t fdlistno = 0; |
| 302 |
struct r_rpcb_rmtcallargs barg; |
| 303 |
struct r_rpcb_rmtcallres bres; |
| 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; |
| 313 |
int pmap_flag = 0; |
| 314 |
char *outbuf_pmap = NULL; |
| 315 |
struct rmtcallargs barg_pmap; |
| 316 |
struct rmtcallres bres_pmap; |
| 317 |
u_int udpbufsz = 0; |
| 318 |
#endif |
| 319 |
|
| 320 |
if (sys_auth == NULL) { |
| 321 |
return (RPC_SYSTEMERROR); |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 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; |
| 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 |
| 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 |
|
| 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 |
|
| 432 |
if (pmap_flag) { |
| 433 |
msg.rm_xid++; |
| 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 |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
for (msec = inittime; msec <= waittime; msec += msec) { |
| 464 |
struct broadif *bip; |
| 465 |
|
| 466 |
|
| 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 |
|
| 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 |
|
| 502 |
|
| 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 |
| 519 |
} |
| 520 |
|
| 521 |
} |
| 522 |
|
| 523 |
if (eachresult == NULL) { |
| 524 |
stat = RPC_SUCCESS; |
| 525 |
goto done_broad; |
| 526 |
} |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
recv_again: |
| 532 |
|
| 533 |
switch (pollretval = poll(pfd, fdlistno, msec)) { |
| 534 |
case 0: |
| 535 |
stat = RPC_TIMEDOUT; |
| 536 |
continue; |
| 537 |
case -1: |
| 538 |
goto recv_again; |
| 539 |
} |
| 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 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 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; |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 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 |
| 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 |
| 622 |
LIBTIRPC_DEBUG(3, ("rpc_broadcast_exp: uaddr %s\n", uaddrp)); |
| 623 |
np = uaddr2taddr( |
| 624 |
fdlist[i].nconf, uaddrp); |
| 625 |
|
| 626 |
|
| 627 |
|
| 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 |
| 640 |
} |
| 641 |
|
| 642 |
} |
| 643 |
|
| 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 |
} |
| 657 |
} |
| 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 |
| 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; |
| 683 |
rpcvers_t vers; |
| 684 |
rpcproc_t proc; |
| 685 |
xdrproc_t xargs; |
| 686 |
caddr_t argsp; |
| 687 |
xdrproc_t xresults; |
| 688 |
caddr_t resultsp; |
| 689 |
resultproc_t eachresult; |
| 690 |
const char *nettype; |
| 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 |
} |