#!/usr/bin/perl
#
# bin/udpscan.saint
#
# version 1, Mon Mar 20 18:46:18 1995, last mod by wietse
#

#
# Report UDP services.
#
require 'config/paths.pl';
require 'perl/misc.pl';
require 'perllib/getopts.pl';

print "BEGIN\n";
$usage = "usage $0 [-v] ports target";

&Getopts("v") || die $usage;
die $usage unless ($#ARGV <= 2);

($services = $ARGV[0]) =~ tr /,/ /;
$target = $ARGV[1];

$severity = "x";
$status = "a";

$| = 1; 

open(SERVICES, $SERVICES) || die "$0: cannot open $SERVICES: $!\n";
while (<SERVICES>) {
	$service_name{$2} = $1 if /(\S+)\s+([0-9]+)\/udp/;
}

$command = "$UDP_SCAN $target $services";

print "$command\n" if $opt_v;

open(UDP_SCAN, "$command|")
	|| die "$0: cannot run $UDP_SCAN";

while(<UDP_SCAN>) {
	if (defined($opt_v)) {
	    print;
	}
	chop;
	($port, $port_service) = split(/:/, $_);
	$service = $service_name{$port};
	if ($service eq "chargen") {
	    $service = "chargen:UDP";
	    $text = "offers $service ($port:UDP)";
	}
	elsif ($service) {
	    $text = "offers $service ($port:UDP)";
	}
	else {
	    $service = "$port:UDP";
	    $text = "offers $service";
	}
	$service_output = "";
	&saint_print();
}
