/*
 * $Id: askhost.c,v 1.2 1994/02/08 11:48:00 too Exp $
 *
 * Author: Tomi Ollila <too@cs.hut.fi>
 *
 * Copyright (c) 1993, 1994  AmiTCP/IP Group, <amitcp-group@hut.fi>
 *                           Helsinki University of Technology, Finland.
 *                           All rights reserved.
 *
 * Created: Fri May 28 15:22:12 1993 too
 * Last modified: Tue Feb  8 13:35:27 1994 too
 *
 * HISTORY
 * $Log: askhost.c,v $
 * Revision 1.2  1994/02/08  11:48:00  too
 * Now copies h_addr_list[i] to aligned struct in_addr buffer
 *
 * Revision 1.1  1994/02/02  17:48:57  too
 * Initial revision
 */

#ifndef AMIGA	/* no stdio for AMIGA version for smaller executable size. */
#include <stdio.h>
#else
#include "amiga.h"
#endif

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

int main(int argc, char *argv[])
{
  struct hostent * host;
  int i;

  if (argc < 2) {
    printf("Usage: askhost (<name>|<addr>)\n");
    return 1;
  }
  
  if (argv[1][0] >= '0' && argv[1][0] <= '9') {
    unsigned long ia;
    if ((ia = inet_addr(argv[1])) == -1) {
      printf("inet_addr: malformed request\n");
      return 1;
    }
    if ((host = gethostbyaddr((char *)&ia, 4, AF_INET)) == NULL) {
      herror("gethostbyaddr");
      return 1;
    }
  }
  else {
    if ((host = gethostbyname(argv[1])) == NULL) {
      herror("gethostbyname");
      return 1;
    }
  }	
    
  printf("\nhost: %s   addrtype: %ld   length: %ld\n"
	 "aliases:\n", host->h_name, host->h_addrtype, host->h_length);

  for (i = 0; host->h_aliases[i]; i++)
    printf("    %s\n", host->h_aliases[i]);

  printf("address list:\n");

  for (i = 0; host->h_addr_list[i]; i++) {
    struct in_addr addr;

    bcopy(host->h_addr_list[i], (char *)&addr, sizeof addr); 
    printf("    %s\n", inet_ntoa(addr));
  }
  printf("\n");

  return 0;
}	
