Blame inet/tst-gethnm.c

Packit 6c4009
/* Based on a test case by grd@algonet.se.  */
Packit 6c4009
Packit 6c4009
#include <netdb.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <sys/param.h>
Packit 6c4009
#include <sys/socket.h>
Packit 6c4009
#include <netinet/in.h>
Packit 6c4009
#include <arpa/inet.h>
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  struct hostent *ent;
Packit 6c4009
  struct in_addr hostaddr;
Packit 6c4009
  int result = 0;
Packit 6c4009
Packit 6c4009
  inet_aton ("127.0.0.1", (struct in_addr *) &hostaddr.s_addr);
Packit 6c4009
  ent = gethostbyaddr (&hostaddr, sizeof (hostaddr), AF_INET);
Packit 6c4009
  if (ent == NULL)
Packit 6c4009
    puts ("gethostbyaddr (...) == NULL");
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      puts ("Using gethostbyaddr(..):");
Packit 6c4009
      printf ("h_name: %s\n", ent->h_name);
Packit 6c4009
Packit 6c4009
      if (ent->h_aliases == NULL)
Packit 6c4009
	puts ("ent->h_aliases == NULL");
Packit 6c4009
      else
Packit 6c4009
	printf ("h_aliases[0]: %s\n", ent->h_aliases[0]);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  ent = gethostbyname ("127.0.0.1");
Packit 6c4009
  if (ent == NULL)
Packit 6c4009
    {
Packit 6c4009
      puts ("gethostbyname (\"127.0.0.1\") == NULL");
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      printf ("\nNow using gethostbyname(..):\n");
Packit 6c4009
      printf ("h_name: %s\n", ent->h_name);
Packit 6c4009
      if (strcmp (ent->h_name, "127.0.0.1") != 0)
Packit 6c4009
	{
Packit 6c4009
	  puts ("ent->h_name != \"127.0.0.1\"");
Packit 6c4009
	  result = 1;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      if (ent->h_aliases == NULL)
Packit 6c4009
	{
Packit 6c4009
	  puts ("ent->h_aliases == NULL");
Packit 6c4009
	  result = 1;
Packit 6c4009
	}
Packit 6c4009
      else
Packit 6c4009
	{
Packit 6c4009
	  printf ("h_aliases[0]: %s\n", ent->h_aliases[0]);
Packit 6c4009
	  result |= ent->h_aliases[0] != NULL;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"