-/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
- Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1998.
+ Contributed by Andreas Jaeger <aj@suse.de>, 1998.
The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
+ Lesser General Public License for more details.
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
/*
Testing of some network related lookup functions.
- /etc/hosts
- /etc/networks
- /etc/protocols
- - /etc/rpc
The tests try to be fairly generic and simple so that they work on
every possible setup (and might therefore not detect some possible
errors).
*/
#include <netdb.h>
-#include <rpc/netdb.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <unistd.h>
+#include <errno.h>
#include "nss.h"
+#include <support/support.h>
+
/*
- The following define is neccessary for glibc 2.0.6
+ The following define is necessary for glibc 2.0.6
*/
#ifndef INET6_ADDRSTRLEN
# define INET6_ADDRSTRLEN 46
int error_count;
-void
+static void
output_servent (const char *call, struct servent *sptr)
{
char **pptr;
}
-void
+static void
test_services (void)
{
struct servent *sptr;
}
-void
+static void
output_hostent (const char *call, struct hostent *hptr)
{
char **pptr;
}
}
-void
+static void
test_hosts (void)
{
struct hostent *hptr1, *hptr2;
- char name[MAXHOSTNAMELEN];
- size_t namelen = sizeof(name);
+ char *name = NULL;
+ size_t namelen = 0;
struct in_addr ip;
hptr1 = gethostbyname ("localhost");
hptr1 = gethostbyname2 ("localhost", AF_INET);
output_hostent ("gethostbyname2 (\"localhost\", AF_INET)", hptr1);
+ while (gethostname (name, namelen) < 0 && errno == ENAMETOOLONG)
+ {
+ namelen += 2; /* tiny increments to test a lot */
+ name = xrealloc (name, namelen);
+ }
if (gethostname (name, namelen) == 0)
{
printf ("Hostname: %s\n", name);
- hptr1 = gethostbyname (name);
- output_hostent ("gethostbyname (gethostname(...))", hptr1);
+ if (name != NULL)
+ {
+ hptr1 = gethostbyname (name);
+ output_hostent ("gethostbyname (gethostname(...))", hptr1);
+ }
}
ip.s_addr = htonl (INADDR_LOOPBACK);
- hptr1 = gethostbyaddr ((char *)&ip, sizeof(ip), AF_INET);
+ hptr1 = gethostbyaddr ((char *) &ip, sizeof (ip), AF_INET);
if (hptr1 != NULL)
{
printf ("official name of 127.0.0.1: %s\n", hptr1->h_name);
}
-void
+static void
output_netent (const char *call, struct netent *nptr)
{
char **pptr;
}
}
-void
+static void
test_network (void)
{
struct netent *nptr;
- u_int32_t ip;
+ uint32_t ip;
/*
This test needs the following line in /etc/networks:
}
-void
+static void
output_protoent (const char *call, struct protoent *prptr)
{
char **pptr;
}
-void
+static void
test_protocols (void)
{
struct protoent *prptr;
}
-void
-output_rpcent (const char *call, struct rpcent *rptr)
-{
- char **pptr;
-
- if (rptr == NULL)
- printf ("Call: %s returned NULL\n", call);
- else
- {
- printf ("Call: %s, returned: r_name: %s, r_number: %d\n",
- call, rptr->r_name, rptr->r_number);
- for (pptr = rptr->r_aliases; *pptr != NULL; pptr++)
- printf (" alias: %s\n", *pptr);
- }
-}
-
-void
-test_rpc (void)
-{
- struct rpcent *rptr;
-
- rptr = getrpcbyname ("portmap");
- output_rpcent ("getrpcyname (\"portmap\")", rptr);
-
- rptr = getrpcbynumber (100000);
- output_rpcent ("getrpcbynumber (100000)", rptr);
-
- setrpcent (0);
- do
- {
- rptr = getrpcent ();
- output_rpcent ("getrpcent ()", rptr);
- }
- while (rptr != NULL);
- endrpcent ();
-}
-
-/*
- Override /etc/nsswitch.conf for this program.
- This is mainly useful for developers
-*/
-void
+/* Override /etc/nsswitch.conf for this program. This is mainly
+ useful for developers. */
+static void __attribute__ ((unused))
setdb (const char *dbname)
{
if (strcmp ("db", dbname))
__nss_configure_lookup ("networks", dbname);
}
__nss_configure_lookup ("protocols", dbname);
- __nss_configure_lookup ("rpc", dbname);
__nss_configure_lookup ("services", dbname);
}
-int
-main (void)
+static int
+do_test (void)
{
/*
setdb ("db");
test_hosts ();
test_network ();
test_protocols ();
- test_rpc ();
test_services ();
if (error_count)
- printf ("\n %d errors occured!\n", error_count);
+ printf ("\n %d errors occurred!\n", error_count);
else
- printf ("No visible errors occured!\n");
+ printf ("No visible errors occurred!\n");
- exit (error_count);
+ return (error_count != 0);
}
+
+#include <support/test-driver.c>