fix some port stuff and finish off the testing

This commit is contained in:
Zane C. B-H 2019-02-20 05:27:33 -06:00
parent 84f5d8b83b
commit d45adada64
2 changed files with 25 additions and 3 deletions

View File

@ -380,8 +380,8 @@ sub set_ports{
my $port=pop( @ports );
my %lookup_hash;
while( defined( $port ) ){
my $port_number;
if ( $port =~ /^\d+$/ ){
my $port_number=$port;
if ( $port !~ /^\d+$/ ){
# Find the first matching port number.
# Does not care what protocol comes up.
$port_number=(getservbyname( $port , '' ))[2];

View File

@ -134,5 +134,27 @@ ok( $#found eq '4', 'search, Protocol 2') or diag('"'.$#found.'" number of retur
$search->set_states( ['LISTEN'] );
@found=$search->search($res);
ok( $#found eq '0', 'search, Protocol+Listen') or diag('"'.$#found.'" number of returned connections for tcp4 protocol + LISTEN state instead of "0"');
$search->set_states;
$search->set_protocols;
@found=$search->search($res);
ok( $#found eq '5', 'search, protocol+state reset') or diag('"'.$#found.'" number of returned connections for a empty search instead of "5"... failed to reset the protocols and states');
done_testing(14);
#make sure we can search based on ports
$search->set_ports(['22']);
@found=$search->search($res);
ok( $#found eq '4', 'search, Port 1') or diag('"'.$#found.'" number of returned connections for port 22 instead of "4"');
$search->set_ports(['ssh']);
@found=$search->search($res);
ok( $#found eq '4', 'search, Port 2') or diag('"'.$#found.'" number of returned connections for port ssh instead of "4"');
$search->set_ports(['ssh', 22]);
@found=$search->search($res);
ok( $#found eq '4', 'search, Port 3') or diag('"'.$#found.'" number of returned connections for port ssh, 22 instead of "4"');
$search->set_states( ['LISTEN'] );
@found=$search->search($res);
ok( $#found eq '0', 'search, port+state') or diag('"'.$#found.'" number of returned connections for port 22, ssh and LISTEN state instead of "0"');
$search->set_states;
$search->set_ports;
@found=$search->search($res);
ok( $#found eq '5', 'search, port+state reset') or diag('"'.$#found.'" number of returned connections for a empty search instead of "5"... failed to reset the ports and states');
done_testing(20);