-/* 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.
#include <sys/param.h>
#include <sys/socket.h>
#include <unistd.h>
+#include <errno.h>
#include "nss.h"
/*
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 = 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);
}
-void
+static void
output_netent (const char *call, struct netent *nptr)
{
char **pptr;
}
}
-void
+static void
test_network (void)
{
struct netent *nptr;
}
-void
+static void
output_protoent (const char *call, struct protoent *prptr)
{
char **pptr;
}
-void
+static void
test_protocols (void)
{
struct protoent *prptr;
}
-void
+static void
output_rpcent (const char *call, struct rpcent *rptr)
{
char **pptr;
}
}
-void
+static void
test_rpc (void)
{
struct rpcent *rptr;
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))
else
printf ("No visible errors occurred!\n");
- exit (error_count);
+ return (error_count != 0);
}