]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nss/test-netdb.c
Replace FSF snail mail address with URLs.
[thirdparty/glibc.git] / nss / test-netdb.c
index afce9587ca8932e383836985167ac6840fb47d99..6554776443684833a942a682fd1a543065569b09 100644 (file)
@@ -1,21 +1,20 @@
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1998,99,2000,01 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    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
+   <http://www.gnu.org/licenses/>.  */
 
 /*
   Testing of some network related lookup functions.
@@ -40,6 +39,7 @@
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <unistd.h>
+#include <errno.h>
 #include "nss.h"
 
 /*
@@ -51,7 +51,7 @@
 
 int error_count;
 
-void
+static void
 output_servent (const char *call, struct servent *sptr)
 {
   char **pptr;
@@ -68,7 +68,7 @@ output_servent (const char *call, struct servent *sptr)
 }
 
 
-void
+static void
 test_services (void)
 {
   struct servent *sptr;
@@ -112,7 +112,7 @@ test_services (void)
 }
 
 
-void
+static void
 output_hostent (const char *call, struct hostent *hptr)
 {
   char **pptr;
@@ -134,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");
@@ -176,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 = realloc (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);
@@ -202,7 +210,7 @@ test_hosts (void)
 }
 
 
-void
+static void
 output_netent (const char *call, struct netent *nptr)
 {
   char **pptr;
@@ -222,7 +230,7 @@ output_netent (const char *call, struct netent *nptr)
     }
 }
 
-void
+static void
 test_network (void)
 {
   struct netent *nptr;
@@ -253,7 +261,7 @@ test_network (void)
 }
 
 
-void
+static void
 output_protoent (const char *call, struct protoent *prptr)
 {
   char **pptr;
@@ -270,7 +278,7 @@ output_protoent (const char *call, struct protoent *prptr)
 }
 
 
-void
+static void
 test_protocols (void)
 {
   struct protoent *prptr;
@@ -292,7 +300,7 @@ test_protocols (void)
 }
 
 
-void
+static void
 output_rpcent (const char *call, struct rpcent *rptr)
 {
   char **pptr;
@@ -308,7 +316,7 @@ output_rpcent (const char *call, struct rpcent *rptr)
     }
 }
 
-void
+static void
 test_rpc (void)
 {
   struct rpcent *rptr;
@@ -329,11 +337,9 @@ test_rpc (void)
   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))
@@ -368,5 +374,5 @@ main (void)
   else
     printf ("No visible errors occurred!\n");
 
-  exit (error_count);
+  return (error_count != 0);
 }