Path: blob/main/crypto/krb5/src/lib/rpc/pmap_getport.c
39536 views
/* @(#)pmap_getport.c 2.2 88/08/01 4.0 RPCSRC */1/*2* Copyright (c) 2010, Oracle America, Inc.3*4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions are met:8*9* * Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* * Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in14* the documentation and/or other materials provided with the15* distribution.16*17* * Neither the name of the "Oracle America, Inc." nor the names of18* its contributors may be used to endorse or promote products19* derived from this software without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS22* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED23* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A24* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT25* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,26* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED27* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR28* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF29* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING30* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS31* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.32*/33#if !defined(lint) && defined(SCCSIDS)34static char sccsid[] = "@(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro";35#endif3637/*38* pmap_getport.c39* Client interface to pmap rpc service.40*/4142#include <unistd.h>43#include <gssrpc/rpc.h>44#include <gssrpc/pmap_prot.h>45#include <gssrpc/pmap_clnt.h>46#include <sys/socket.h>47#ifdef OSF148#include <net/route.h>49#include <sys/mbuf.h>50#endif51#include <net/if.h>5253static struct timeval timeout = { 5, 0 };54static struct timeval tottimeout = { 60, 0 };5556/*57* Find the mapped port for program,version.58* Calls the pmap service remotely to do the lookup.59* Returns 0 if no map exists.60*/61u_short62pmap_getport(63struct sockaddr_in *address,64rpcprog_t program,65rpcvers_t version,66rpcprot_t protocol)67{68unsigned short port = 0;69int sock = -1;70CLIENT *client;71struct pmap parms;7273address->sin_port = htons(PMAPPORT);74client = clntudp_bufcreate(address, PMAPPROG,75PMAPVERS, timeout, &sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);76if (client != (CLIENT *)NULL) {77parms.pm_prog = program;78parms.pm_vers = version;79parms.pm_prot = protocol;80parms.pm_port = 0; /* not needed or used */81if (CLNT_CALL(client, PMAPPROC_GETPORT,82(xdrproc_t)xdr_pmap, &parms,83(xdrproc_t)xdr_u_short, &port,84tottimeout) != RPC_SUCCESS){85rpc_createerr.cf_stat = RPC_PMAPFAILURE;86clnt_geterr(client, &rpc_createerr.cf_error);87} else if (port == 0) {88rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;89}90CLNT_DESTROY(client);91}92(void)close(sock);93address->sin_port = 0;94return (port);95}969798