-/* Copyright (C) 1997, 1998, 2000, 2001, 2010, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
+ <https://www.gnu.org/licenses/>. */
#include <string.h>
#include <time.h>
struct findserv_req
{
struct sockaddr_in sin;
- u_int32_t xid;
+ uint32_t xid;
u_int server_nr;
u_int server_ep;
};
struct findserv_req *pings;
struct sockaddr_in sin, saved_sin;
int found = -1;
- u_int32_t xid_seed;
+ uint32_t xid_seed;
int sock, dontblock = 1;
CLIENT *clnt;
u_long i, j, pings_count, pings_max, fastest = -1;
for multihomed hosts */
pings_count = 0;
pings = malloc (sizeof (struct findserv_req) * pings_max);
- xid_seed = (u_int32_t) (time (NULL) ^ getpid ());
+ xid_seed = (uint32_t) (time (NULL) ^ getpid ());
- if (__builtin_expect (pings == NULL, 0))
+ if (__glibc_unlikely (pings == NULL))
return -1;
memset (&sin, '\0', sizeof (sin));
for (i = 0; i < bind->server_len; i++)
for (j = 0; j < bind->server_val[i].ep.ep_len; ++j)
if (strcmp (bind->server_val[i].ep.ep_val[j].family, "inet") == 0)
- if ((bind->server_val[i].ep.ep_val[j].proto == NULL) ||
- (bind->server_val[i].ep.ep_val[j].proto[0] == '-') ||
- (bind->server_val[i].ep.ep_val[j].proto[0] == '\0'))
+ if ((bind->server_val[i].ep.ep_val[j].proto == NULL)
+ || (bind->server_val[i].ep.ep_val[j].proto[0] == '-')
+ || (bind->server_val[i].ep.ep_val[j].proto[0] == '\0'))
{
sin.sin_addr.s_addr =
inetstr2int (bind->server_val[i].ep.ep_val[j].uaddr);
pings_max += 10;
new_pings = realloc (pings, sizeof (struct findserv_req) *
pings_max);
- if (__builtin_expect (new_pings == NULL, 0))
+ if (__glibc_unlikely (new_pings == NULL))
{
free (pings);
return -1;
}
memcpy ((char *) &pings[pings_count].sin, (char *) &sin,
sizeof (sin));
- memcpy ((char *)&saved_sin, (char *)&sin, sizeof(sin));
+ memcpy ((char *)&saved_sin, (char *)&sin, sizeof (sin));
pings[pings_count].xid = xid_seed + pings_count;
pings[pings_count].server_nr = i;
pings[pings_count].server_ep = j;
}
/* Create RPC handle */
- sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ sock = socket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
clnt = clntudp_create (&saved_sin, NIS_PROG, NIS_VERSION, *timeout, &sock);
if (clnt == NULL)
{
for (i = 0; i < pings_count; ++i)
{
/* clntudp_call() will increment, subtract one */
- *((u_int32_t *) (cu->cu_outbuf)) = pings[i].xid - 1;
+ *((uint32_t *) (cu->cu_outbuf)) = pings[i].xid - 1;
memcpy ((char *) &cu->cu_raddr, (char *) &pings[i].sin,
sizeof (struct sockaddr_in));
/* Transmit to NULLPROC, return immediately. */
(xdrproc_t) xdr_void, (caddr_t) 0,
*timeout);
if (RPC_SUCCESS == rc) {
- u_int32_t val;
- memcpy (&val, cu->cu_inbuf, sizeof (u_int32_t));
+ uint32_t val;
+ memcpy (&val, cu->cu_inbuf, sizeof (uint32_t));
fastest = val - xid_seed;
if (fastest < pings_count) {
bind->server_used = pings[fastest].server_nr;