Home | History | Annotate | Line # | Download | only in rpc
rpc_soc.c revision 1.5.4.2
      1  1.5.4.2  minoura /*	$NetBSD: rpc_soc.c,v 1.5.4.2 2000/06/23 16:17:47 minoura Exp $	*/
      2  1.5.4.2  minoura 
      3  1.5.4.2  minoura /*
      4  1.5.4.2  minoura  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
      5  1.5.4.2  minoura  * unrestricted use provided that this legend is included on all tape
      6  1.5.4.2  minoura  * media and as a part of the software program in whole or part.  Users
      7  1.5.4.2  minoura  * may copy or modify Sun RPC without charge, but are not authorized
      8  1.5.4.2  minoura  * to license or distribute it to anyone else except as part of a product or
      9  1.5.4.2  minoura  * program developed by the user.
     10  1.5.4.2  minoura  *
     11  1.5.4.2  minoura  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
     12  1.5.4.2  minoura  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
     13  1.5.4.2  minoura  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
     14  1.5.4.2  minoura  *
     15  1.5.4.2  minoura  * Sun RPC is provided with no support and without any obligation on the
     16  1.5.4.2  minoura  * part of Sun Microsystems, Inc. to assist in its use, correction,
     17  1.5.4.2  minoura  * modification or enhancement.
     18  1.5.4.2  minoura  *
     19  1.5.4.2  minoura  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
     20  1.5.4.2  minoura  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
     21  1.5.4.2  minoura  * OR ANY PART THEREOF.
     22  1.5.4.2  minoura  *
     23  1.5.4.2  minoura  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
     24  1.5.4.2  minoura  * or profits or other special, indirect and consequential damages, even if
     25  1.5.4.2  minoura  * Sun has been advised of the possibility of such damages.
     26  1.5.4.2  minoura  *
     27  1.5.4.2  minoura  * Sun Microsystems, Inc.
     28  1.5.4.2  minoura  * 2550 Garcia Avenue
     29  1.5.4.2  minoura  * Mountain View, California  94043
     30  1.5.4.2  minoura  */
     31  1.5.4.2  minoura 
     32  1.5.4.2  minoura /* #ident	"@(#)rpc_soc.c	1.17	94/04/24 SMI" */
     33  1.5.4.2  minoura 
     34  1.5.4.2  minoura /*
     35  1.5.4.2  minoura  * Copyright (c) 1986-1991 by Sun Microsystems Inc.
     36  1.5.4.2  minoura  * In addition, portions of such source code were derived from Berkeley
     37  1.5.4.2  minoura  * 4.3 BSD under license from the Regents of the University of
     38  1.5.4.2  minoura  * California.
     39  1.5.4.2  minoura  */
     40  1.5.4.2  minoura 
     41  1.5.4.2  minoura #if 0
     42  1.5.4.2  minoura #if !defined(lint) && defined(SCCSIDS)
     43  1.5.4.2  minoura static char sccsid[] = "@(#)rpc_soc.c 1.41 89/05/02 Copyr 1988 Sun Micro";
     44  1.5.4.2  minoura #endif
     45  1.5.4.2  minoura #endif
     46  1.5.4.2  minoura 
     47  1.5.4.2  minoura #ifdef PORTMAP
     48  1.5.4.2  minoura /*
     49  1.5.4.2  minoura  * rpc_soc.c
     50  1.5.4.2  minoura  *
     51  1.5.4.2  minoura  * The backward compatibility routines for the earlier implementation
     52  1.5.4.2  minoura  * of RPC, where the only transports supported were tcp/ip and udp/ip.
     53  1.5.4.2  minoura  * Based on berkeley socket abstraction, now implemented on the top
     54  1.5.4.2  minoura  * of TLI/Streams
     55  1.5.4.2  minoura  */
     56  1.5.4.2  minoura 
     57  1.5.4.2  minoura #include "namespace.h"
     58  1.5.4.2  minoura #include "reentrant.h"
     59  1.5.4.2  minoura #include <sys/types.h>
     60  1.5.4.2  minoura #include <sys/socket.h>
     61  1.5.4.2  minoura #include <stdio.h>
     62  1.5.4.2  minoura #include <rpc/rpc.h>
     63  1.5.4.2  minoura #include <rpc/pmap_clnt.h>
     64  1.5.4.2  minoura #include <rpc/pmap_prot.h>
     65  1.5.4.2  minoura #include <netinet/in.h>
     66  1.5.4.2  minoura #include <netdb.h>
     67  1.5.4.2  minoura #include <errno.h>
     68  1.5.4.2  minoura #include <syslog.h>
     69  1.5.4.2  minoura #include <stdlib.h>
     70  1.5.4.2  minoura #include <string.h>
     71  1.5.4.2  minoura #include <unistd.h>
     72  1.5.4.2  minoura 
     73  1.5.4.2  minoura #include "rpc_com.h"
     74  1.5.4.2  minoura 
     75  1.5.4.2  minoura #ifdef __weak_alias
     76  1.5.4.2  minoura __weak_alias(clntudp_bufcreate,_clntudp_bufcreate)
     77  1.5.4.2  minoura __weak_alias(clntudp_create,_clntudp_create)
     78  1.5.4.2  minoura __weak_alias(clnttcp_create,_clnttcp_create)
     79  1.5.4.2  minoura __weak_alias(clntraw_create,_clntraw_create)
     80  1.5.4.2  minoura __weak_alias(get_myaddress,_get_myaddress)
     81  1.5.4.2  minoura __weak_alias(svcfd_create,_svcfd_create)
     82  1.5.4.2  minoura __weak_alias(svcudp_bufcreate,_svcudp_bufcreate)
     83  1.5.4.2  minoura __weak_alias(svcudp_create,_svcudp_create)
     84  1.5.4.2  minoura __weak_alias(svctcp_create,_svctcp_create)
     85  1.5.4.2  minoura __weak_alias(svcraw_create,_svcraw_create)
     86  1.5.4.2  minoura __weak_alias(callrpc,_callrpc)
     87  1.5.4.2  minoura __weak_alias(registerrpc,_registerrpc)
     88  1.5.4.2  minoura __weak_alias(clnt_broadcast,_clnt_broadcast)
     89  1.5.4.2  minoura #endif
     90  1.5.4.2  minoura 
     91  1.5.4.2  minoura #ifdef __REENT
     92  1.5.4.2  minoura extern mutex_t	rpcsoc_lock;
     93  1.5.4.2  minoura #endif
     94  1.5.4.2  minoura 
     95  1.5.4.2  minoura static CLIENT *clnt_com_create __P((struct sockaddr_in *, rpcprog_t, rpcvers_t,
     96  1.5.4.2  minoura 				    int *, u_int, u_int, char *));
     97  1.5.4.2  minoura static SVCXPRT *svc_com_create __P((int, u_int, u_int, char *));
     98  1.5.4.2  minoura static bool_t rpc_wrap_bcast __P((char *, struct netbuf *, struct netconfig *));
     99  1.5.4.2  minoura 
    100  1.5.4.2  minoura /*
    101  1.5.4.2  minoura  * A common clnt create routine
    102  1.5.4.2  minoura  */
    103  1.5.4.2  minoura static CLIENT *
    104  1.5.4.2  minoura clnt_com_create(raddr, prog, vers, sockp, sendsz, recvsz, tp)
    105  1.5.4.2  minoura 	struct sockaddr_in *raddr;
    106  1.5.4.2  minoura 	rpcprog_t prog;
    107  1.5.4.2  minoura 	rpcvers_t vers;
    108  1.5.4.2  minoura 	int *sockp;
    109  1.5.4.2  minoura 	u_int sendsz;
    110  1.5.4.2  minoura 	u_int recvsz;
    111  1.5.4.2  minoura 	char *tp;
    112  1.5.4.2  minoura {
    113  1.5.4.2  minoura 	CLIENT *cl;
    114  1.5.4.2  minoura 	int madefd = FALSE;
    115  1.5.4.2  minoura 	int fd = *sockp;
    116  1.5.4.2  minoura 	struct netconfig *nconf;
    117  1.5.4.2  minoura 	struct netbuf bindaddr;
    118  1.5.4.2  minoura 
    119  1.5.4.2  minoura 	mutex_lock(&rpcsoc_lock);
    120  1.5.4.2  minoura 	if ((nconf = __rpc_getconfip(tp)) == NULL) {
    121  1.5.4.2  minoura 		rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
    122  1.5.4.2  minoura 		mutex_unlock(&rpcsoc_lock);
    123  1.5.4.2  minoura 		return ((CLIENT *)NULL);
    124  1.5.4.2  minoura 	}
    125  1.5.4.2  minoura 	if (fd == RPC_ANYSOCK) {
    126  1.5.4.2  minoura 		fd = __rpc_nconf2fd(nconf);
    127  1.5.4.2  minoura 		if (fd == -1)
    128  1.5.4.2  minoura 			goto syserror;
    129  1.5.4.2  minoura 		madefd = TRUE;
    130  1.5.4.2  minoura 	}
    131  1.5.4.2  minoura 
    132  1.5.4.2  minoura 	if (raddr->sin_port == 0) {
    133  1.5.4.2  minoura 		u_int proto;
    134  1.5.4.2  minoura 		u_short sport;
    135  1.5.4.2  minoura 
    136  1.5.4.2  minoura 		mutex_unlock(&rpcsoc_lock);	/* pmap_getport is recursive */
    137  1.5.4.2  minoura 		proto = strcmp(tp, "udp") == 0 ? IPPROTO_UDP : IPPROTO_TCP;
    138  1.5.4.2  minoura 		sport = pmap_getport(raddr, prog, vers, proto);
    139  1.5.4.2  minoura 		if (sport == 0) {
    140  1.5.4.2  minoura 			goto err;
    141  1.5.4.2  minoura 		}
    142  1.5.4.2  minoura 		raddr->sin_port = htons(sport);
    143  1.5.4.2  minoura 		mutex_lock(&rpcsoc_lock);	/* pmap_getport is recursive */
    144  1.5.4.2  minoura 	}
    145  1.5.4.2  minoura 
    146  1.5.4.2  minoura 	/* Transform sockaddr_in to netbuf */
    147  1.5.4.2  minoura 	bindaddr.maxlen = bindaddr.len =  sizeof (struct sockaddr_in);
    148  1.5.4.2  minoura 	bindaddr.buf = raddr;
    149  1.5.4.2  minoura 
    150  1.5.4.2  minoura 	bindresvport(fd, NULL);
    151  1.5.4.2  minoura 	cl = clnt_tli_create(fd, nconf, &bindaddr, prog, vers,
    152  1.5.4.2  minoura 				sendsz, recvsz);
    153  1.5.4.2  minoura 	if (cl) {
    154  1.5.4.2  minoura 		if (madefd == TRUE) {
    155  1.5.4.2  minoura 			/*
    156  1.5.4.2  minoura 			 * The fd should be closed while destroying the handle.
    157  1.5.4.2  minoura 			 */
    158  1.5.4.2  minoura 			(void) CLNT_CONTROL(cl, CLSET_FD_CLOSE, (char *)NULL);
    159  1.5.4.2  minoura 			*sockp = fd;
    160  1.5.4.2  minoura 		}
    161  1.5.4.2  minoura 		(void) freenetconfigent(nconf);
    162  1.5.4.2  minoura 		mutex_unlock(&rpcsoc_lock);
    163  1.5.4.2  minoura 		return (cl);
    164  1.5.4.2  minoura 	}
    165  1.5.4.2  minoura 	goto err;
    166  1.5.4.2  minoura 
    167  1.5.4.2  minoura syserror:
    168  1.5.4.2  minoura 	rpc_createerr.cf_stat = RPC_SYSTEMERROR;
    169  1.5.4.2  minoura 	rpc_createerr.cf_error.re_errno = errno;
    170  1.5.4.2  minoura 
    171  1.5.4.2  minoura err:	if (madefd == TRUE)
    172  1.5.4.2  minoura 		(void) close(fd);
    173  1.5.4.2  minoura 	(void) freenetconfigent(nconf);
    174  1.5.4.2  minoura 	mutex_unlock(&rpcsoc_lock);
    175  1.5.4.2  minoura 	return ((CLIENT *)NULL);
    176  1.5.4.2  minoura }
    177  1.5.4.2  minoura 
    178  1.5.4.2  minoura CLIENT *
    179  1.5.4.2  minoura clntudp_bufcreate(raddr, prog, vers, wait, sockp, sendsz, recvsz)
    180  1.5.4.2  minoura 	register struct sockaddr_in *raddr;
    181  1.5.4.2  minoura 	u_long prog;
    182  1.5.4.2  minoura 	u_long vers;
    183  1.5.4.2  minoura 	struct timeval wait;
    184  1.5.4.2  minoura 	int *sockp;
    185  1.5.4.2  minoura 	u_int sendsz;
    186  1.5.4.2  minoura 	u_int recvsz;
    187  1.5.4.2  minoura {
    188  1.5.4.2  minoura 	CLIENT *cl;
    189  1.5.4.2  minoura 
    190  1.5.4.2  minoura 	cl = clnt_com_create(raddr, prog, vers, sockp, sendsz, recvsz, "udp");
    191  1.5.4.2  minoura 	if (cl == (CLIENT *)NULL) {
    192  1.5.4.2  minoura 		return ((CLIENT *)NULL);
    193  1.5.4.2  minoura 	}
    194  1.5.4.2  minoura 	(void) CLNT_CONTROL(cl, CLSET_RETRY_TIMEOUT, (char *)&wait);
    195  1.5.4.2  minoura 	return (cl);
    196  1.5.4.2  minoura }
    197  1.5.4.2  minoura 
    198  1.5.4.2  minoura CLIENT *
    199  1.5.4.2  minoura clntudp_create(raddr, program, version, wait, sockp)
    200  1.5.4.2  minoura 	struct sockaddr_in *raddr;
    201  1.5.4.2  minoura 	u_long program;
    202  1.5.4.2  minoura 	u_long version;
    203  1.5.4.2  minoura 	struct timeval wait;
    204  1.5.4.2  minoura 	int *sockp;
    205  1.5.4.2  minoura {
    206  1.5.4.2  minoura 	return clntudp_bufcreate(raddr, program, version, wait, sockp,
    207  1.5.4.2  minoura 					UDPMSGSIZE, UDPMSGSIZE);
    208  1.5.4.2  minoura }
    209  1.5.4.2  minoura 
    210  1.5.4.2  minoura CLIENT *
    211  1.5.4.2  minoura clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
    212  1.5.4.2  minoura 	struct sockaddr_in *raddr;
    213  1.5.4.2  minoura 	u_long prog;
    214  1.5.4.2  minoura 	u_long vers;
    215  1.5.4.2  minoura 	register int *sockp;
    216  1.5.4.2  minoura 	u_int sendsz;
    217  1.5.4.2  minoura 	u_int recvsz;
    218  1.5.4.2  minoura {
    219  1.5.4.2  minoura 	return clnt_com_create(raddr, prog, vers, sockp, sendsz,
    220  1.5.4.2  minoura 			recvsz, "tcp");
    221  1.5.4.2  minoura }
    222  1.5.4.2  minoura 
    223  1.5.4.2  minoura CLIENT *
    224  1.5.4.2  minoura clntraw_create(prog, vers)
    225  1.5.4.2  minoura 	u_long prog;
    226  1.5.4.2  minoura 	u_long vers;
    227  1.5.4.2  minoura {
    228  1.5.4.2  minoura 	return clnt_raw_create(prog, vers);
    229  1.5.4.2  minoura }
    230  1.5.4.2  minoura 
    231  1.5.4.2  minoura /*
    232  1.5.4.2  minoura  * A common server create routine
    233  1.5.4.2  minoura  */
    234  1.5.4.2  minoura static SVCXPRT *
    235  1.5.4.2  minoura svc_com_create(fd, sendsize, recvsize, netid)
    236  1.5.4.2  minoura 	register int fd;
    237  1.5.4.2  minoura 	u_int sendsize;
    238  1.5.4.2  minoura 	u_int recvsize;
    239  1.5.4.2  minoura 	char *netid;
    240  1.5.4.2  minoura {
    241  1.5.4.2  minoura 	struct netconfig *nconf;
    242  1.5.4.2  minoura 	SVCXPRT *svc;
    243  1.5.4.2  minoura 	int madefd = FALSE;
    244  1.5.4.2  minoura 	int port;
    245  1.5.4.2  minoura 	struct sockaddr_in sin;
    246  1.5.4.2  minoura 
    247  1.5.4.2  minoura 	if ((nconf = __rpc_getconfip(netid)) == NULL) {
    248  1.5.4.2  minoura 		(void) syslog(LOG_ERR, "Could not get %s transport", netid);
    249  1.5.4.2  minoura 		return ((SVCXPRT *)NULL);
    250  1.5.4.2  minoura 	}
    251  1.5.4.2  minoura 	if (fd == RPC_ANYSOCK) {
    252  1.5.4.2  minoura 		fd = __rpc_nconf2fd(nconf);
    253  1.5.4.2  minoura 		if (fd == -1) {
    254  1.5.4.2  minoura 			(void) freenetconfigent(nconf);
    255  1.5.4.2  minoura 			(void) syslog(LOG_ERR,
    256  1.5.4.2  minoura 			"svc%s_create: could not open connection", netid);
    257  1.5.4.2  minoura 			return ((SVCXPRT *)NULL);
    258  1.5.4.2  minoura 		}
    259  1.5.4.2  minoura 		madefd = TRUE;
    260  1.5.4.2  minoura 	}
    261  1.5.4.2  minoura 
    262  1.5.4.2  minoura 	memset(&sin, 0, sizeof sin);
    263  1.5.4.2  minoura 	sin.sin_family = AF_INET;
    264  1.5.4.2  minoura 	bindresvport(fd, &sin);
    265  1.5.4.2  minoura 	listen(fd, SOMAXCONN);
    266  1.5.4.2  minoura 	svc = svc_tli_create(fd, nconf, (struct t_bind *)NULL,
    267  1.5.4.2  minoura 				sendsize, recvsize);
    268  1.5.4.2  minoura 	(void) freenetconfigent(nconf);
    269  1.5.4.2  minoura 	if (svc == (SVCXPRT *)NULL) {
    270  1.5.4.2  minoura 		if (madefd)
    271  1.5.4.2  minoura 			(void) close(fd);
    272  1.5.4.2  minoura 		return ((SVCXPRT *)NULL);
    273  1.5.4.2  minoura 	}
    274  1.5.4.2  minoura 	port = (((struct sockaddr_in *)svc->xp_ltaddr.buf)->sin_port);
    275  1.5.4.2  minoura 	svc->xp_port = ntohs(port);
    276  1.5.4.2  minoura 	return (svc);
    277  1.5.4.2  minoura }
    278  1.5.4.2  minoura 
    279  1.5.4.2  minoura SVCXPRT *
    280  1.5.4.2  minoura svctcp_create(fd, sendsize, recvsize)
    281  1.5.4.2  minoura 	register int fd;
    282  1.5.4.2  minoura 	u_int sendsize;
    283  1.5.4.2  minoura 	u_int recvsize;
    284  1.5.4.2  minoura {
    285  1.5.4.2  minoura 	return svc_com_create(fd, sendsize, recvsize, "tcp");
    286  1.5.4.2  minoura }
    287  1.5.4.2  minoura 
    288  1.5.4.2  minoura SVCXPRT *
    289  1.5.4.2  minoura svcudp_bufcreate(fd, sendsz, recvsz)
    290  1.5.4.2  minoura 	register int fd;
    291  1.5.4.2  minoura 	u_int sendsz, recvsz;
    292  1.5.4.2  minoura {
    293  1.5.4.2  minoura 	return svc_com_create(fd, sendsz, recvsz, "udp");
    294  1.5.4.2  minoura }
    295  1.5.4.2  minoura 
    296  1.5.4.2  minoura SVCXPRT *
    297  1.5.4.2  minoura svcfd_create(fd, sendsize, recvsize)
    298  1.5.4.2  minoura 	int fd;
    299  1.5.4.2  minoura 	u_int sendsize;
    300  1.5.4.2  minoura 	u_int recvsize;
    301  1.5.4.2  minoura {
    302  1.5.4.2  minoura 	return svc_fd_create(fd, sendsize, recvsize);
    303  1.5.4.2  minoura }
    304  1.5.4.2  minoura 
    305  1.5.4.2  minoura 
    306  1.5.4.2  minoura SVCXPRT *
    307  1.5.4.2  minoura svcudp_create(fd)
    308  1.5.4.2  minoura 	register int fd;
    309  1.5.4.2  minoura {
    310  1.5.4.2  minoura 	return svc_com_create(fd, UDPMSGSIZE, UDPMSGSIZE, "udp");
    311  1.5.4.2  minoura }
    312  1.5.4.2  minoura 
    313  1.5.4.2  minoura SVCXPRT *
    314  1.5.4.2  minoura svcraw_create()
    315  1.5.4.2  minoura {
    316  1.5.4.2  minoura 	return svc_raw_create();
    317  1.5.4.2  minoura }
    318  1.5.4.2  minoura 
    319  1.5.4.2  minoura int
    320  1.5.4.2  minoura get_myaddress(addr)
    321  1.5.4.2  minoura 	struct sockaddr_in *addr;
    322  1.5.4.2  minoura {
    323  1.5.4.2  minoura 	memset((void *) addr, 0, sizeof(*addr));
    324  1.5.4.2  minoura 	addr->sin_family = AF_INET;
    325  1.5.4.2  minoura 	addr->sin_port = htons(PMAPPORT);
    326  1.5.4.2  minoura 	addr->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
    327  1.5.4.2  minoura 	return (0);
    328  1.5.4.2  minoura }
    329  1.5.4.2  minoura 
    330  1.5.4.2  minoura /*
    331  1.5.4.2  minoura  * For connectionless "udp" transport. Obsoleted by rpc_call().
    332  1.5.4.2  minoura  */
    333  1.5.4.2  minoura int
    334  1.5.4.2  minoura callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
    335  1.5.4.2  minoura 	char *host;
    336  1.5.4.2  minoura 	int prognum, versnum, procnum;
    337  1.5.4.2  minoura 	xdrproc_t inproc, outproc;
    338  1.5.4.2  minoura 	char *in, *out;
    339  1.5.4.2  minoura {
    340  1.5.4.2  minoura 	return (int)rpc_call(host, (u_long)prognum, (u_long)versnum,
    341  1.5.4.2  minoura 		    (u_long)procnum, inproc, in, outproc, out, "udp");
    342  1.5.4.2  minoura }
    343  1.5.4.2  minoura 
    344  1.5.4.2  minoura /*
    345  1.5.4.2  minoura  * For connectionless kind of transport. Obsoleted by rpc_reg()
    346  1.5.4.2  minoura  */
    347  1.5.4.2  minoura int
    348  1.5.4.2  minoura registerrpc(prognum, versnum, procnum, progname, inproc, outproc)
    349  1.5.4.2  minoura 	int prognum, versnum, procnum;
    350  1.5.4.2  minoura 	char *(*progname) __P((char [UDPMSGSIZE]));
    351  1.5.4.2  minoura 	xdrproc_t inproc, outproc;
    352  1.5.4.2  minoura {
    353  1.5.4.2  minoura 	return rpc_reg((u_long)prognum, (u_long)versnum, (u_long)procnum,
    354  1.5.4.2  minoura 	    progname, inproc, outproc, "udp");
    355  1.5.4.2  minoura }
    356  1.5.4.2  minoura 
    357  1.5.4.2  minoura /*
    358  1.5.4.2  minoura  * All the following clnt_broadcast stuff is convulated; it supports
    359  1.5.4.2  minoura  * the earlier calling style of the callback function
    360  1.5.4.2  minoura  */
    361  1.5.4.2  minoura #ifdef __REENT
    362  1.5.4.2  minoura static thread_key_t	clnt_broadcast_key;
    363  1.5.4.2  minoura #endif
    364  1.5.4.2  minoura static resultproc_t	clnt_broadcast_result_main;
    365  1.5.4.2  minoura 
    366  1.5.4.2  minoura /*
    367  1.5.4.2  minoura  * Need to translate the netbuf address into sockaddr_in address.
    368  1.5.4.2  minoura  * Dont care about netid here.
    369  1.5.4.2  minoura  */
    370  1.5.4.2  minoura /* ARGSUSED */
    371  1.5.4.2  minoura static bool_t
    372  1.5.4.2  minoura rpc_wrap_bcast(resultp, addr, nconf)
    373  1.5.4.2  minoura 	char *resultp;		/* results of the call */
    374  1.5.4.2  minoura 	struct netbuf *addr;	/* address of the guy who responded */
    375  1.5.4.2  minoura 	struct netconfig *nconf; /* Netconf of the transport */
    376  1.5.4.2  minoura {
    377  1.5.4.2  minoura 	resultproc_t clnt_broadcast_result;
    378  1.5.4.2  minoura 
    379  1.5.4.2  minoura 	if (strcmp(nconf->nc_netid, "udp"))
    380  1.5.4.2  minoura 		return (FALSE);
    381  1.5.4.2  minoura #ifdef __REENT
    382  1.5.4.2  minoura 	if (_thr_main())
    383  1.5.4.2  minoura 		clnt_broadcast_result = clnt_broadcast_result_main;
    384  1.5.4.2  minoura 	else
    385  1.5.4.2  minoura 		thr_getspecific(clnt_broadcast_key,
    386  1.5.4.2  minoura 			(void **) &clnt_broadcast_result);
    387  1.5.4.2  minoura #else
    388  1.5.4.2  minoura 	clnt_broadcast_result = clnt_broadcast_result_main;
    389  1.5.4.2  minoura #endif
    390  1.5.4.2  minoura 	return (*clnt_broadcast_result)(resultp,
    391  1.5.4.2  minoura 				(struct sockaddr_in *)addr->buf);
    392  1.5.4.2  minoura }
    393  1.5.4.2  minoura 
    394  1.5.4.2  minoura /*
    395  1.5.4.2  minoura  * Broadcasts on UDP transport. Obsoleted by rpc_broadcast().
    396  1.5.4.2  minoura  */
    397  1.5.4.2  minoura enum clnt_stat
    398  1.5.4.2  minoura clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
    399  1.5.4.2  minoura 	u_long		prog;		/* program number */
    400  1.5.4.2  minoura 	u_long		vers;		/* version number */
    401  1.5.4.2  minoura 	u_long		proc;		/* procedure number */
    402  1.5.4.2  minoura 	xdrproc_t	xargs;		/* xdr routine for args */
    403  1.5.4.2  minoura 	caddr_t		argsp;		/* pointer to args */
    404  1.5.4.2  minoura 	xdrproc_t	xresults;	/* xdr routine for results */
    405  1.5.4.2  minoura 	caddr_t		resultsp;	/* pointer to results */
    406  1.5.4.2  minoura 	resultproc_t	eachresult;	/* call with each result obtained */
    407  1.5.4.2  minoura {
    408  1.5.4.2  minoura #ifdef __REENT
    409  1.5.4.2  minoura 	extern mutex_t tsd_lock;
    410  1.5.4.2  minoura #endif
    411  1.5.4.2  minoura 
    412  1.5.4.2  minoura #ifdef __REENT
    413  1.5.4.2  minoura 	if (_thr_main())
    414  1.5.4.2  minoura 		clnt_broadcast_result_main = eachresult;
    415  1.5.4.2  minoura 	else {
    416  1.5.4.2  minoura 		if (clnt_broadcast_key == 0) {
    417  1.5.4.2  minoura 			mutex_lock(&tsd_lock);
    418  1.5.4.2  minoura 			if (clnt_broadcast_key == 0)
    419  1.5.4.2  minoura 				thr_keycreate(&clnt_broadcast_key, free);
    420  1.5.4.2  minoura 			mutex_unlock(&tsd_lock);
    421  1.5.4.2  minoura 		}
    422  1.5.4.2  minoura 		thr_setspecific(clnt_broadcast_key, (void *) eachresult);
    423  1.5.4.2  minoura 	}
    424  1.5.4.2  minoura #else
    425  1.5.4.2  minoura 	clnt_broadcast_result_main = eachresult;
    426  1.5.4.2  minoura #endif
    427  1.5.4.2  minoura 	return rpc_broadcast(prog, vers, proc, xargs, argsp, xresults,
    428  1.5.4.2  minoura 				resultsp, (resultproc_t) rpc_wrap_bcast, "udp");
    429  1.5.4.2  minoura }
    430  1.5.4.2  minoura 
    431  1.5.4.2  minoura #endif /* PORTMAP */
    432