1 /* $NetBSD: pmap_clnt.c,v 1.19 2013/03/11 20:19:29 tron Exp $ */
4 * Copyright (c) 2010, Oracle America, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 * * Neither the name of the "Oracle America, Inc." nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 #if defined(LIBC_SCCS) && !defined(lint)
37 static char *sccsid
= "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
38 static char *sccsid
= "@(#)pmap_clnt.c 2.2 88/08/01 4.0 RPCSRC";
40 __RCSID("$NetBSD: pmap_clnt.c,v 1.19 2013/03/11 20:19:29 tron Exp $");
46 * Client interface to pmap rpc service.
48 * Copyright (C) 1984, Sun Microsystems, Inc.
51 #include "namespace.h"
56 #include <rpc/pmap_prot.h>
57 #include <rpc/pmap_clnt.h>
58 #include <rpc/nettype.h>
63 #include "rpc_internal.h"
66 __weak_alias(pmap_set
,_pmap_set
)
67 __weak_alias(pmap_unset
,_pmap_unset
)
71 pmap_set(u_long program
, u_long version
, int protocol
, int port
)
75 struct netconfig
*nconf
;
78 if ((protocol
!= IPPROTO_UDP
) && (protocol
!= IPPROTO_TCP
)) {
81 nconf
= __rpc_getconfip(protocol
== IPPROTO_UDP
? "udp" : "tcp");
85 snprintf(buf
, sizeof buf
, "0.0.0.0.%d.%d",
86 (((u_int32_t
)port
) >> 8) & 0xff, port
& 0xff);
87 na
= uaddr2taddr(nconf
, buf
);
89 freenetconfigent(nconf
);
92 rslt
= rpcb_set((rpcprog_t
)program
, (rpcvers_t
)version
, nconf
, na
);
94 freenetconfigent(nconf
);
99 * Remove the mapping between program, version and port.
100 * Calls the pmap service remotely to do the un-mapping.
103 pmap_unset(u_long program
, u_long version
)
105 struct netconfig
*nconf
;
106 bool_t udp_rslt
= FALSE
;
107 bool_t tcp_rslt
= FALSE
;
109 nconf
= __rpc_getconfip("udp");
111 udp_rslt
= rpcb_unset((rpcprog_t
)program
, (rpcvers_t
)version
,
113 freenetconfigent(nconf
);
115 nconf
= __rpc_getconfip("tcp");
117 tcp_rslt
= rpcb_unset((rpcprog_t
)program
, (rpcvers_t
)version
,
119 freenetconfigent(nconf
);
122 * XXX: The call may still succeed even if only one of the
123 * calls succeeded. This was the best that could be
124 * done for backward compatibility.
126 return (tcp_rslt
|| udp_rslt
);