|
Packit |
fd8b60 |
/* @(#)pmap_getport.c 2.2 88/08/01 4.0 RPCSRC */
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Copyright (c) 2010, Oracle America, Inc.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* All rights reserved.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
fd8b60 |
* modification, are permitted provided that the following conditions are met:
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* * Redistributions of source code must retain the above copyright
|
|
Packit |
fd8b60 |
* notice, this list of conditions and the following disclaimer.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* * Redistributions in binary form must reproduce the above copyright
|
|
Packit |
fd8b60 |
* notice, this list of conditions and the following disclaimer in
|
|
Packit |
fd8b60 |
* the documentation and/or other materials provided with the
|
|
Packit |
fd8b60 |
* distribution.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* * Neither the name of the "Oracle America, Inc." nor the names of
|
|
Packit |
fd8b60 |
* its contributors may be used to endorse or promote products
|
|
Packit |
fd8b60 |
* derived from this software without specific prior written permission.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
Packit |
fd8b60 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
Packit |
fd8b60 |
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
Packit |
fd8b60 |
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
Packit |
fd8b60 |
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
Packit |
fd8b60 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
Packit |
fd8b60 |
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
Packit |
fd8b60 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
Packit |
fd8b60 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
Packit |
fd8b60 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
Packit |
fd8b60 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
#if !defined(lint) && defined(SCCSIDS)
|
|
Packit |
fd8b60 |
static char sccsid[] = "@(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro";
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* pmap_getport.c
|
|
Packit |
fd8b60 |
* Client interface to pmap rpc service.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#include <unistd.h>
|
|
Packit |
fd8b60 |
#include <gssrpc/rpc.h>
|
|
Packit |
fd8b60 |
#include <gssrpc/pmap_prot.h>
|
|
Packit |
fd8b60 |
#include <gssrpc/pmap_clnt.h>
|
|
Packit |
fd8b60 |
#include <sys/socket.h>
|
|
Packit |
fd8b60 |
#ifdef OSF1
|
|
Packit |
fd8b60 |
#include <net/route.h>
|
|
Packit |
fd8b60 |
#include <sys/mbuf.h>
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
#include <net/if.h>
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static struct timeval timeout = { 5, 0 };
|
|
Packit |
fd8b60 |
static struct timeval tottimeout = { 60, 0 };
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Find the mapped port for program,version.
|
|
Packit |
fd8b60 |
* Calls the pmap service remotely to do the lookup.
|
|
Packit |
fd8b60 |
* Returns 0 if no map exists.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
u_short
|
|
Packit |
fd8b60 |
pmap_getport(
|
|
Packit |
fd8b60 |
struct sockaddr_in *address,
|
|
Packit |
fd8b60 |
rpcprog_t program,
|
|
Packit |
fd8b60 |
rpcvers_t version,
|
|
Packit |
fd8b60 |
rpcprot_t protocol)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
unsigned short port = 0;
|
|
Packit |
fd8b60 |
int sock = -1;
|
|
Packit |
fd8b60 |
CLIENT *client;
|
|
Packit |
fd8b60 |
struct pmap parms;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
address->sin_port = htons(PMAPPORT);
|
|
Packit |
fd8b60 |
client = clntudp_bufcreate(address, PMAPPROG,
|
|
Packit |
fd8b60 |
PMAPVERS, timeout, &sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
|
|
Packit |
fd8b60 |
if (client != (CLIENT *)NULL) {
|
|
Packit |
fd8b60 |
parms.pm_prog = program;
|
|
Packit |
fd8b60 |
parms.pm_vers = version;
|
|
Packit |
fd8b60 |
parms.pm_prot = protocol;
|
|
Packit |
fd8b60 |
parms.pm_port = 0; /* not needed or used */
|
|
Packit |
fd8b60 |
if (CLNT_CALL(client, PMAPPROC_GETPORT, xdr_pmap, &parms,
|
|
Packit |
fd8b60 |
xdr_u_short, &port, tottimeout) != RPC_SUCCESS){
|
|
Packit |
fd8b60 |
rpc_createerr.cf_stat = RPC_PMAPFAILURE;
|
|
Packit |
fd8b60 |
clnt_geterr(client, &rpc_createerr.cf_error);
|
|
Packit |
fd8b60 |
} else if (port == 0) {
|
|
Packit |
fd8b60 |
rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
CLNT_DESTROY(client);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
(void)close(sock);
|
|
Packit |
fd8b60 |
address->sin_port = 0;
|
|
Packit |
fd8b60 |
return (port);
|
|
Packit |
fd8b60 |
}
|