#!/mit/watchmaker/@sys/perl

push(@INC,"/afs/athena.mit.edu/user/m/marc/perl");

require 'zsend.pl';

($prog = $0) =~ s,^.*/([^/]+)$,$1,;

if (@ARGV != 1) { die "usage: $prog host\n"; }

@addr = unpack("CCCC",(gethostbyname($ARGV[0]))[4] ||
	       die "$prog: host unknown: $ARGV[0]\n");

print "addr: ",@addr,"\n";

&zsend'zinit; #'

sub zackpacket {
	local($uid, $class, $inst, $opcode, $sender, $recip, $default, $msg)
		= @_;
	local($packet);

	if (! $uid) {
		$localaddr = ((gethostbyname(&thechop(`hostname`)))[4])
				if (! $localaddr);
		$uidinc = 0 if ($oldtime != time);
		$uidinc++;
		$uid = pack("a4 N N",$localaddr,$oldtime=time,$uidinc);
	}

	$packet .= "ZEPH0.2\0";
	$packet .= &zlong(17);
	$packet .= &zlong(2);			# ACKED
	$packet .= &zascii($uid)."\0";
	$packet .= &zascii(pack("n",0))."\0";	# no response port
	$packet .= &zlong(0);			# no auth
	$packet .= &zlong(0);			# authlen = 0
	$packet .= "\0";			# no authdata
	$packet .= $class."\0";
	$packet .= $inst."\0";
	$packet .= $opcode."\0";
	$packet .= $sender."\0";
	$packet .= $recip."\0";
	$packet .= $default."\0";
	$packet .= &zlong(0);			# no checksum
	$packet .= "\0";			# no fragmentation
	$packet .= &zascii($uid)."\0";
	$packet .= $msg;
}

$i=1;
while ($i<65536) {
	$zsend'zhm = pack("S n C4 x8",&AF_INET,$i,@addr);
	print "Port $i...\n" if ($i%100 == 0);
	&zsend("ZEPH0.2\0This is a bogon packet...\0");
#	&zsend(&zpacket(undef,		# figure out uid
#		"message",
#		"personal",
#		"", # opcode
#		"marc@ATHENA.MIT.EDU",
#		"marc@ATHENA.MIT.EDU",
#		"message from \$sender\n\n\$message",
#		"Signature\0number $i\0"));

	$i++;
}
