]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nss/test-netdb.c
[powerpc] No need to enter "Ignore Exceptions Mode"
[thirdparty/glibc.git] / nss / test-netdb.c
index 01056a69d7817007b1e5ee71b019cce6451299c5..d4b0f68635dbe30e47887337ac97ef36bb55c50b 100644 (file)
@@ -1,21 +1,20 @@
-/* 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 necessary for glibc 2.0.6
 */
@@ -49,7 +51,7 @@
 
 int error_count;
 
-void
+static void
 output_servent (const char *call, struct servent *sptr)
 {
   char **pptr;
@@ -66,7 +68,7 @@ output_servent (const char *call, struct servent *sptr)
 }
 
 
-void
+static void
 test_services (void)
 {
   struct servent *sptr;
@@ -110,7 +112,7 @@ test_services (void)
 }
 
 
-void
+static void
 output_hostent (const char *call, struct hostent *hptr)
 {
   char **pptr;
@@ -132,12 +134,12 @@ output_hostent (const char *call, struct hostent *hptr)
     }
 }
 
-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");
@@ -174,15 +176,23 @@ test_hosts (void)
   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);
@@ -200,7 +210,7 @@ test_hosts (void)
 }
 
 
-void
+static void
 output_netent (const char *call, struct netent *nptr)
 {
   char **pptr;
@@ -220,11 +230,11 @@ output_netent (const char *call, struct netent *nptr)
     }
 }
 
-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:
@@ -251,7 +261,7 @@ test_network (void)
 }
 
 
-void
+static void
 output_protoent (const char *call, struct protoent *prptr)
 {
   char **pptr;
@@ -268,7 +278,7 @@ output_protoent (const char *call, struct protoent *prptr)
 }
 
 
-void
+static void
 test_protocols (void)
 {
   struct protoent *prptr;
@@ -290,48 +300,9 @@ test_protocols (void)
 }
 
 
-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))
@@ -343,13 +314,12 @@ setdb (const char *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");
@@ -358,7 +328,6 @@ main (void)
   test_hosts ();
   test_network ();
   test_protocols ();
-  test_rpc ();
   test_services ();
 
   if (error_count)
@@ -366,5 +335,7 @@ main (void)
   else
     printf ("No visible errors occurred!\n");
 
-  exit (error_count);
+  return (error_count != 0);
 }
+
+#include <support/test-driver.c>