nsswitch: use new internal API (callers)
[platform/upstream/glibc.git] / sunrpc / getrpcport.c
1 /* Obtain the RPC port number for an RPC service on a host.
2    Copyright (C) 2016-2020 Free Software Foundation, Inc.
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 <https://www.gnu.org/licenses/>.  */
18
19 /*
20  * Copyright (c) 2010, Oracle America, Inc.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions are
24  * met:
25  *
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.
35  *
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.
48  */
49
50 #include <alloca.h>
51 #include <errno.h>
52 #include <stdio.h>
53 #include <netdb.h>
54 #include <string.h>
55 #include <rpc/rpc.h>
56 #include <rpc/clnt.h>
57 #include <rpc/pmap_clnt.h>
58 #include <sys/socket.h>
59
60 int
61 getrpcport (const char *host, u_long prognum, u_long versnum, u_int proto)
62 {
63   struct sockaddr_in addr;
64
65   if (__libc_rpc_gethostbyname (host, &addr) != 0)
66     return 0;
67   return pmap_getport (&addr, prognum, versnum, proto);
68 }
69 #ifdef SHARED
70 # ifndef EXPORT_RPC_SYMBOLS
71 compat_symbol (libc, getrpcport, getrpcport, GLIBC_2_0);
72 # endif
73 #endif