]>
Commit | Line | Data |
---|---|---|
5c6e6747 | 1 | /* Obtain the RPC port number for an RPC service on a host. |
04277e02 | 2 | Copyright (C) 2016-2019 Free Software Foundation, Inc. |
5c6e6747 FW |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public License as | |
7 | published by the Free Software Foundation; either version 2.1 of the | |
8 | License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; see the file COPYING.LIB. If | |
17 | not, see <http://www.gnu.org/licenses/>. */ | |
18 | ||
28f540f4 | 19 | /* |
a7ab6ec8 | 20 | * Copyright (c) 2010, Oracle America, Inc. |
cb636bb2 | 21 | * |
a7ab6ec8 UD |
22 | * Redistribution and use in source and binary forms, with or without |
23 | * modification, are permitted provided that the following conditions are | |
24 | * met: | |
e4cf5070 | 25 | * |
a7ab6ec8 UD |
26 | * * Redistributions of source code must retain the above copyright |
27 | * notice, this list of conditions and the following disclaimer. | |
28 | * * Redistributions in binary form must reproduce the above | |
29 | * copyright notice, this list of conditions and the following | |
30 | * disclaimer in the documentation and/or other materials | |
31 | * provided with the distribution. | |
32 | * * Neither the name of the "Oracle America, Inc." nor the names of its | |
33 | * contributors may be used to endorse or promote products derived | |
34 | * from this software without specific prior written permission. | |
e4cf5070 | 35 | * |
a7ab6ec8 UD |
36 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
37 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
38 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
39 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
40 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
41 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
42 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | |
43 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
44 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
45 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
46 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
47 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28f540f4 RM |
48 | */ |
49 | ||
e4cf5070 UD |
50 | #include <alloca.h> |
51 | #include <errno.h> | |
28f540f4 | 52 | #include <stdio.h> |
28f540f4 | 53 | #include <netdb.h> |
e7fd8a39 UD |
54 | #include <string.h> |
55 | #include <rpc/rpc.h> | |
56 | #include <rpc/clnt.h> | |
57 | #include <rpc/pmap_clnt.h> | |
28f540f4 RM |
58 | #include <sys/socket.h> |
59 | ||
e4cf5070 | 60 | int |
e7fd8a39 | 61 | getrpcport (const char *host, u_long prognum, u_long versnum, u_int proto) |
28f540f4 | 62 | { |
e7fd8a39 | 63 | struct sockaddr_in addr; |
28f540f4 | 64 | |
5c6e6747 FW |
65 | if (__libc_rpc_gethostbyname (host, &addr) != 0) |
66 | return 0; | |
e7fd8a39 | 67 | return pmap_getport (&addr, prognum, versnum, proto); |
28f540f4 | 68 | } |