long tftp_use();
short noddt = 0;

char host_name_buf[80];
char default_host[] = "18.68.0.9"; /* Achilles */
/*char default_host[] = "18.10.0.65"; /* Borax */
char *host_name = 0;
long host = 0;

char file_buf[80];
char *default_file = "";
char *file = 0;

char gfile_buf[80];
char *gfile = 0;

long gateway = 0;
long in_me = 0;

#ifdef ndef
test_read()
{
  unsigned char *mladdr, *net_init();
  char buf[500];
  int cc;

  mladdr = net_init();
  for (;;) {
    cc = et_read (buf, sizeof(buf));
  }
}
#endif

main()
{
	extern int flags;
	unsigned char *mladdr;
	unsigned char *net_init();
#ifdef ibm032
#ifdef ATHENA_INSTALL
	gfile = "athena_rt";
#endif
#endif
#ifdef vax
	extern int sid, sid_ext;
	if (sid != 0x08000000) {
		printf("Non-Microvax processors not supported (sorry)\n");
		return 1;
	}
	printf("sid_ext = %x\n", sid_ext);
#ifdef ATHENA_INSTALL
	switch (sid_ext) {
	case 1:
		gfile = "athena_vs2";
		break;
	case 4:
		gfile = "athena_vs2k";
	}
	printf("gfile = %s\n", gfile);
#endif
#endif
#ifdef ndef
	if (flags == 0xff) test_read();
#endif
	mladdr = net_init();
    
    if (host_name == 0) {
	host_name = default_host;
	host = res_name(host_name);
    }
    if (file == 0) file = default_file;
    if (gfile == 0) gfile = default_file;

    in_me = 0;
    puts("\nTFTP Boot\n\n");
#ifdef ETHER
    if (flags & 0x8) {
	    nip_set_address();
    }
#endif
    puts ("boot flags = "); 
    phex (flags);
    puts ("\n");
    printf("gfile = %s\n", gfile);
    if ((flags&(0x8|0x4)) == 0) {
	    do_bootp(gfile, mladdr, &in_me, &host, &gateway, &file);
    }
    else if (flags & 0x8) {
	puts("Enter generic boot file (");
	puts(gfile);
	puts("):\n");
	if (gets(gfile_buf) != 0)
	  gfile = gfile_buf;
	do_bootp(gfile, mladdr, &in_me, &host, &gateway, &file);
    }
    else {
	if ((flags & 0x4) != 0) {
	    puts("My address");
	    if (in_me == 0)
	      puts("\n");
	    else {
		puts(" (");
		phex(in_me);
		puts("):\n");
	    }
	    if (gets(host_name_buf) != 0)
	      in_me = res_name(host_name_buf);
	}
	else
	  do_bootp(gfile, mladdr, &in_me, &host, &gateway, &file);

	puts("Enter boot file (");
	puts(file);
	puts("):\n");
	if (gets(file_buf) != 0)
	  file = file_buf;

	puts("Enter boot host (");
	phex(host);
	puts("):\n");
	if (gets(host_name_buf) != 0) {
	    host = res_name(host_name_buf);
	    if (host == 0) {
		puts("couldn't parse host ");
		puts(host_name_buf);
		return;
	    }
	}
    }
    
    printf("Booting %s from ", file);
    print_ip_addr (host);
    if (gateway == 0) puts ("\n");
       else {
          printf (" via gateway");
	  print_ip_addr (gateway);
          puts ("\n");
	  }

    tftp_use(host, file);
    puts("\ntftp done\n");
}

/* XXX this doesn't belong here */

#ifndef ETHER
void bzero (ptr, len)
	register char *ptr;
	register int len;
{
	while (len--) *ptr++ = 0;
}
#endif	

/* neither does this */

print_ip_addr (a)
     unsigned long a;
{
  unsigned char *ac;

  ac = (usigned char) &a;

  printf ("%u.%u.%u.%u",
	  ac[0] & 0xff, ac[1] & 0xff,
	  ac[2] & 0xff, ac[3] & 0xff);
}
 
