/*
 * Vince version 1.0.1
 * 
 * 
 * +++++++++++
 *  V I N C E  ---  Vendor Independent Network Control Entity
 * +++++++++++
 * Copyright (c) 1994     Advanced Research Projects Agency (ARPA/CSTO)
 *                                   and the
 *                        Naval Research Laboratory (NRL/CCS)
 * All Rights Reserved.
 * 
 * Permission to use, copy, modify and distribute this software and its
 * documentation is hereby granted, provided that both the copyright
 * notice and this permission notice appear in all copies of the software,
 * derivative works or modified versions, and any portions thereof, and
 * that both notices appear in supporting documentation.
 * 
 * ARPA AND NRL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION
 * AND DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
 * RESULTING FROM THE USE OF THIS SOFTWARE.
 * 
 * ARPA and NRL request users of this software to return to:
 * 
 *                 vince-distribution@cmf.nrl.navy.mil
 * 
 *                            or
 * 
 *                 Naval Research Laboratory, Code 5590
 *                 Center for Computational Science
 *                 Washington, D.C. 20375-5000
 * 
 * any improvements or extensions that they make and grant ARPA and NRL 
 * the rights to redistribute these changes.
 * 
 */

#include <atmcore/atmcore.h>
#include <elib/command.h>
#include <elib/string.h>
#include <skip/skip.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <elib/memory.h>

static int interactive=0;
static list load=0;
static int flags=0;
static int inband=0;
static int startup=1;
static char *local_host=0;
extern skip_load_file();
static set_interactive() {interactive=1;}
static clear_startup() {startup=0;}

unsigned int unique_identifier;

static void my_load_file(char *s) 
{
  skip_load_file(skip_global_environment,s);
}

static void hostname(char *s)
{
  local_host= duplicate_string(s,string_length(s));
}


main(int argc, char **argv)
{
  command_space sp;
  virtual_switch new;
  list i,j,*k;
  port p;
  int switch_counter=0;
  struct hostent *he;
  char pathname[100];

  initialize_timer();
  debug_init();
  sp=create_command_space(0);
  command_type (sp,"s","string",command_parse_string,
		command_print_string,deallocate_memory);
  command_function(sp,set_interactive,"interactive","","");
  command_function(sp,clear_startup,"nostartup","","");
  command_function(sp,my_load_file,"load","","s");
  command_function(sp,hostname,"hostname","","s");
#if 0
#ifdef SKIP
  initialize_skip();
#endif

  command_line_dispatch(sp,argc,argv);
#endif
  if (!local_host){
    local_host=(char *)allocate_memory(255);
    gethostname (local_host,256);
  }
  he=gethostbyname(local_host);
  unique_identifier=he->h_addr_list[0][3]|(he->h_addr_list[0][2]<<8);  
  
#ifdef SKIP
  initialize_skip();
  init_vince_skip(local_host,LIBRARY);
#endif 

  init_address();
  init_atmcore();

#ifdef UNI
  uni_init();
#endif

#ifdef SPANS
  spans_init();
#endif

#ifdef SNMP
  /* Needs to get port creation messages */
  snmp_init();
#endif

#ifdef ILMI
  init_ilmi();
#endif

#ifdef SROUTE
  sroute_init();
#endif

#ifdef VTP
  vtp_init();
#endif

#ifdef CRYPTO
  crypto_init();
#endif

  command_line_dispatch(sp,argc,argv);

#ifdef SKIP
  if (interactive) assemble_stack(2,create_skip_layer(skip_global_environment),
				  create_filedesc(0,1,512,0));
  if (startup){
    sprintf (pathname,"%s/startup/%s",LIBRARY,local_host);
    my_load_file(pathname);
  }
#endif
  timer_loop(1,0);
}
