local port sorting works

This commit is contained in:
Zane C. B-H 2019-07-24 03:12:15 -05:00
parent 99283af7a2
commit 6f88aadf54
4 changed files with 45 additions and 43 deletions

View File

@ -6,7 +6,7 @@ use warnings;
=head1 NAME
Net::Connection::Sort::port_l - Sorts the connections via the foreign port numerically.
Net::Connection::Sort::port_l - Sorts the connections via the local port numerically.
=head1 VERSION
@ -30,7 +30,7 @@ This currently implements numeric sorting only. For non-numeric sorting using po
'foreign_host' => '3.3.3.3',
'local_host' => '4.4.4.4',
'foreign_port' => '23',
'local_port' => '11132',
'local_port' => '1133',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -52,7 +52,7 @@ This currently implements numeric sorting only. For non-numeric sorting using po
'foreign_host' => '5.5.5.5',
'local_host' => '6.6.6.6',
'foreign_port' => '80',
'local_port' => '11132',
'local_port' => '11131',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -63,7 +63,7 @@ This currently implements numeric sorting only. For non-numeric sorting using po
'foreign_host' => '3.3.3.3',
'local_host' => '4.4.4.4',
'foreign_port' => '21',
'local_port' => '11132',
'local_port' => '11133',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -129,7 +129,7 @@ sub sorter{
}
@objects=sort {
$a->foreign_port <=> $b->foreign_port
$a->local_port <=> $b->local_port
} @objects;
return @objects;

View File

@ -6,7 +6,7 @@ use warnings;
=head1 NAME
Net::Connection::Sort::port_la - Sorts the connections via the foreign port alphabetically.
Net::Connection::Sort::port_la - Sorts the connections via the local port alphabetically.
=head1 VERSION
@ -19,9 +19,9 @@ our $VERSION = '0.0.0';
=head1 SYNOPSIS
This currently implements cmp sorting only. For numeric sorting using port_f.
This currently implements cmp sorting only. For numeric sorting using port_l.
use Net::Connection::Sort::port_f;
use Net::Connection::Sort::port_la;
use Net::Connection;
use Data::Dumper;
@ -29,8 +29,8 @@ This currently implements cmp sorting only. For numeric sorting using port_f.
Net::Connection->new({
'foreign_host' => '3.3.3.3',
'local_host' => '4.4.4.4',
'foreign_port' => 'FTP',
'local_port' => '11132',
'local_port' => 'FTP',
'foriegn_port' => '11132',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -40,8 +40,8 @@ This currently implements cmp sorting only. For numeric sorting using port_f.
Net::Connection->new({
'foreign_host' => '1.1.1.1',
'local_host' => '2.2.2.2',
'foreign_port' => 'SSH',
'local_port' => '11132',
'local_port' => 'SSH',
'foreign_port' => '11132',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -51,8 +51,8 @@ This currently implements cmp sorting only. For numeric sorting using port_f.
Net::Connection->new({
'foreign_host' => '5.5.5.5',
'local_host' => '6.6.6.6',
'foreign_port' => 'HTTP',
'local_port' => '11132',
'local_port' => 'HTTP',
'foreign_port' => '11132',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -62,8 +62,8 @@ This currently implements cmp sorting only. For numeric sorting using port_f.
Net::Connection->new({
'foreign_host' => '3.3.3.3',
'local_host' => '4.4.4.4',
'foreign_port' => 'HTTPS',
'local_port' => '11132',
'local_port' => 'HTTPS',
'foreign_port' => '11132',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -137,13 +137,15 @@ sub sorter{
=head2 helper
A internal helper function.
=cut
sub helper{
if ( !defined( $_[0]->foreign_port_name ) ){
return $_[0]->foreign_port;
if ( !defined( $_[0]->local_port_name ) ){
return $_[0]->local_port;
}
return $_[0]->foreign_port_name;
return $_[0]->local_port_name;
}
=head1 AUTHOR

View File

@ -9,8 +9,8 @@ my @objects=(
Net::Connection->new({
'foreign_host' => '3.3.3.3',
'local_host' => '4.4.4.4',
'foreign_port' => '1',
'local_port' => '11132',
'local_port' => '1',
'foreign_port' => '11132',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -20,8 +20,8 @@ my @objects=(
Net::Connection->new({
'foreign_host' => '1.1.1.1',
'local_host' => '2.2.2.2',
'foreign_port' => '80',
'local_port' => '11132',
'local_port' => '80',
'foreign_port' => '11132',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -31,8 +31,8 @@ my @objects=(
Net::Connection->new({
'foreign_host' => '5.5.5.5',
'local_host' => '6.6.6.6',
'foreign_port' => '22',
'local_port' => '11132',
'local_port' => '22',
'foreign_port' => '11132',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -42,8 +42,8 @@ my @objects=(
Net::Connection->new({
'foreign_host' => '3.3.3.3',
'local_host' => '4.4.4.4',
'foreign_port' => '21',
'local_port' => '11132',
'local_port' => '21',
'foreign_port' => '11132',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -74,9 +74,9 @@ eval{
};
ok( $worked eq 1, 'sort') or die ('Net::Connection::Sort::host_f->sorter(@objects) resulted in... '.$@);
ok( $sorted[0]->foreign_port eq '1', 'sort order 0') or die ('The first foreign port value was not 1');
ok( $sorted[1]->foreign_port eq '21', 'sort order 1') or die ('The last foreign port value was not 21');
ok( $sorted[2]->foreign_port eq '22', 'sort order 2') or die ('The middle foreign port value was not 22');
ok( $sorted[3]->foreign_port eq '80' , 'sort order 2') or die ('The middle foreign port value was not 80');
ok( $sorted[0]->local_port eq '1', 'sort order 0') or die ('The first local port value was not 1');
ok( $sorted[1]->local_port eq '21', 'sort order 1') or die ('The last local port value was not 21');
ok( $sorted[2]->local_port eq '22', 'sort order 2') or die ('The middle local port value was not 22');
ok( $sorted[3]->local_port eq '80' , 'sort order 2') or die ('The middle local port value was not 80');
done_testing(7);

View File

@ -9,8 +9,8 @@ my @objects=(
Net::Connection->new({
'foreign_host' => '3.3.3.3',
'local_host' => '4.4.4.4',
'foreign_port' => 'FTP',
'local_port' => '11132',
'local_port' => 'FTP',
'foreign_port' => '11132',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -20,8 +20,8 @@ my @objects=(
Net::Connection->new({
'foreign_host' => '1.1.1.1',
'local_host' => '2.2.2.2',
'foreign_port' => 'HTTP',
'local_port' => '11132',
'local_port' => 'HTTP',
'foreign_port' => '11132',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -31,8 +31,8 @@ my @objects=(
Net::Connection->new({
'foreign_host' => '5.5.5.5',
'local_host' => '6.6.6.6',
'foreign_port' => 'SSH',
'local_port' => '11132',
'local_port' => 'SSH',
'foreign_port' => '11132',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -42,8 +42,8 @@ my @objects=(
Net::Connection->new({
'foreign_host' => '3.3.3.3',
'local_host' => '4.4.4.4',
'foreign_port' => 'HTTPS',
'local_port' => '11132',
'local_port' => 'HTTPS',
'foreign_port' => '11132',
'sendq' => '1',
'recvq' => '0',
'state' => 'ESTABLISHED',
@ -74,9 +74,9 @@ eval{
};
ok( $worked eq 1, 'sort') or die ('Net::Connection::Sort::host_f->sorter(@objects) resulted in... '.$@);
ok( $sorted[0]->foreign_port =~ 'FTP', 'sort order 0') or die ('The first foreign port value was not FTP');
ok( $sorted[1]->foreign_port =~ 'HTTP', 'sort order 1') or die ('The last foreign port value was not HTTP');
ok( $sorted[2]->foreign_port =~ 'HTTPS', 'sort order 2') or die ('The middle foreign port value was not HTTPS');
ok( $sorted[3]->foreign_port =~ 'SSH' , 'sort order 2') or die ('The middle foreign port value was not SSH');
ok( $sorted[0]->local_port =~ 'FTP', 'sort order 0') or die ('The first local port value was not FTP');
ok( $sorted[1]->local_port =~ 'HTTP', 'sort order 1') or die ('The last local port value was not HTTP');
ok( $sorted[2]->local_port =~ 'HTTPS', 'sort order 2') or die ('The middle local port value was not HTTPS');
ok( $sorted[3]->local_port =~ 'SSH' , 'sort order 2') or die ('The middle local port value was not SSH');
done_testing(7);