Debian Codegraph @

extra/tirpc/libtirpc-1.3.5/src/pmap_getport.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2009, Sun Microsystems, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28 /*
29 * pmap_getport.c
30 * Client interface to pmap rpc service.
31 *
32 * Copyright (C) 1984, Sun Microsystems, Inc.
33 */
34
35 #include <sys/types.h>
36 #include <sys/socket.h>
37
38 #include <arpa/inet.h>
39 #include <net/if.h>
40
41 #include <assert.h>
42 #include <unistd.h>
43
44 #include <rpc/rpc.h>
45 #include <rpc/pmap_prot.h>
46 #include <rpc/pmap_clnt.h>
47
48 static const struct timeval timeout = { 5, 0 };
49 static const struct timeval tottimeout = { 60, 0 };
50
51 /*
52 * Find the mapped port for program,version.
53 * Calls the pmap service remotely to do the lookup.
54 * Returns 0 if no map exists.
55 */
56 u_short
57 pmap_getport(address, program, version, protocol)
58 struct sockaddr_in *address;
59 u_long program;
60 u_long version;
61 u_int protocol;
62 {
63 u_short port = 0;
64 int sock = -1;
65 CLIENT *client;
66 struct pmap parms;
67
68 assert(address != NULL);
69
70 address->sin_port = htons(PMAPPORT);
71 client = clntudp_bufcreate(address, PMAPPROG,
72 PMAPVERS, timeout, &sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
73 if (client != NULL) {
74 parms.pm_prog = program;
75 parms.pm_vers = version;
76 parms.pm_prot = protocol;
77 parms.pm_port = 0; /* not needed or used */
78 if (CLNT_CALL(client, (rpcproc_t)PMAPPROC_GETPORT,
79 (xdrproc_t)xdr_pmap,
80 &parms, (xdrproc_t)xdr_u_short, &port, tottimeout) !=
81 RPC_SUCCESS){
82 rpc_createerr.cf_stat = RPC_PMAPFAILURE;
83 clnt_geterr(client, &rpc_createerr.cf_error);
84 } else if (port == 0) {
85 rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
86 }
87 CLNT_DESTROY(client);
88 }
89 address->sin_port = 0;
90 return (port);
91 }