]>
Commit | Line | Data |
---|---|---|
28f540f4 RM |
1 | /* |
2 | * pmap_getmap.c | |
3 | * Client interface to pmap rpc service. | |
4 | * contains pmap_getmaps, which is only tcp service involved | |
5 | * | |
a7ab6ec8 UD |
6 | * Copyright (c) 2010, Oracle America, Inc. |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are | |
10 | * met: | |
11 | * | |
12 | * * Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | |
14 | * * Redistributions in binary form must reproduce the above | |
15 | * copyright notice, this list of conditions and the following | |
16 | * disclaimer in the documentation and/or other materials | |
17 | * provided with the distribution. | |
18 | * * Neither the name of the "Oracle America, Inc." nor the names of its | |
19 | * contributors may be used to endorse or promote products derived | |
20 | * from this software without specific prior written permission. | |
21 | * | |
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
26 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | |
29 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28f540f4 RM |
34 | */ |
35 | ||
36 | #include <rpc/rpc.h> | |
37 | #include <rpc/pmap_prot.h> | |
38 | #include <rpc/pmap_clnt.h> | |
39 | #include <sys/socket.h> | |
40 | #include <netdb.h> | |
faf10b95 | 41 | #include <stdbool.h> |
28f540f4 RM |
42 | #include <stdio.h> |
43 | #include <errno.h> | |
4360eafd | 44 | #include <libintl.h> |
faf10b95 | 45 | #include <unistd.h> |
7b57bfe5 | 46 | #include <not-cancel.h> |
faf10b95 | 47 | |
25f9784e | 48 | |
28f540f4 RM |
49 | /* |
50 | * Get a copy of the current port maps. | |
51 | * Calls the pmap service remotely to do get the maps. | |
52 | */ | |
53 | struct pmaplist * | |
e7fd8a39 | 54 | pmap_getmaps (struct sockaddr_in *address) |
28f540f4 | 55 | { |
e7fd8a39 | 56 | struct pmaplist *head = (struct pmaplist *) NULL; |
e7fd8a39 UD |
57 | struct timeval minutetimeout; |
58 | CLIENT *client; | |
faf10b95 | 59 | bool closeit = false; |
28f540f4 | 60 | |
e7fd8a39 UD |
61 | minutetimeout.tv_sec = 60; |
62 | minutetimeout.tv_usec = 0; | |
63 | address->sin_port = htons (PMAPPORT); | |
faf10b95 | 64 | |
c179df4e | 65 | /* Don't need a reserved port to get ports from the portmapper. */ |
faf10b95 UD |
66 | int socket = __get_socket (address); |
67 | if (socket != -1) | |
68 | closeit = true; | |
69 | ||
7b57bfe5 | 70 | client = clnttcp_create (address, PMAPPROG, PMAPVERS, &socket, 50, 500); |
e7fd8a39 UD |
71 | if (client != (CLIENT *) NULL) |
72 | { | |
7b57bfe5 UD |
73 | if (CLNT_CALL (client, PMAPPROC_DUMP, (xdrproc_t)xdr_void, NULL, |
74 | (xdrproc_t)xdr_pmaplist, (caddr_t)&head, | |
e7fd8a39 UD |
75 | minutetimeout) != RPC_SUCCESS) |
76 | { | |
11bf311e | 77 | clnt_perror (client, _("pmap_getmaps.c: rpc problem")); |
28f540f4 | 78 | } |
e7fd8a39 UD |
79 | CLNT_DESTROY (client); |
80 | } | |
faf10b95 UD |
81 | /* We only need to close the socket here if we opened it. */ |
82 | if (closeit) | |
7b57bfe5 | 83 | close_not_cancel (socket); |
e7fd8a39 UD |
84 | address->sin_port = 0; |
85 | return head; | |
28f540f4 | 86 | } |
021db4be | 87 | libc_hidden_nolink_sunrpc (pmap_getmaps, GLIBC_2_0) |