Compare commits

...

5 Commits

3 changed files with 32 additions and 17 deletions

View File

@ -1,5 +1,14 @@
Revision history for Net-Connection-lsof
0.3.0 2023-06-01/13:15
- Redirect stderr to dev null to prevent pointless warning about kern diffferences from lsof.
0.2.0 2019-08-16/16:40
- WChan support added to Linux.
0.1.1 2019-08-13/06:00
- Only call sysctl on BSD.
0.1.0 2019-08-12/05:45
- Add support for process information.

View File

@ -1,3 +1,4 @@
package Net::Connection::lsof;
use 5.006;
@ -16,11 +17,11 @@ Net::Connection::lsof - This uses lsof to generate a array of Net::Connection ob
=head1 VERSION
Version 0.1.0
Version 0.3.0
=cut
our $VERSION = '0.1.0';
our $VERSION = '0.3.0';
=head1 SYNOPSIS
@ -99,7 +100,7 @@ sub lsof_to_nc_objects{
$func_args{proc_info}=1;
}
my $output_raw=`lsof -i UDP -i TCP -n -l -P`;
my $output_raw=`lsof -i UDP -i TCP -n -l -P 2> /dev/null`;
if (
( $? ne 0 ) &&
(
@ -125,9 +126,11 @@ sub lsof_to_nc_objects{
if ( $func_args{proc_info} ){
my $pt=Proc::ProcessTable->new;
$proc_table=$pt->table;
$physmem=`/sbin/sysctl -a hw.physmem`;
chomp( $physmem );
$physmem=~s/^.*\: //;
if ( $^O =~ /bsd/ ){
$physmem=`/sbin/sysctl -a hw.physmem`;
chomp( $physmem );
$physmem=~s/^.*\: //;
}
}
my $line_int=1;
@ -235,8 +238,19 @@ sub lsof_to_nc_objects{
}
$pid_proc{ $args->{pid} }=$args->{proc};
$args->{wchan}=$proc_table->[ $proc_int ]->{wchan};
$pid_wchan{ $args->{pid} }=$args->{wchan};
# linux has shit wchan reporting and apparently if you want more than
# the address you need to use the ass backwards /proc
if ( $^O =~ /linux/ ){
if ( -e '/proc/'.$args->{pid}.'/wchan'){
open( my $wchan_fh, '<', '/proc/'.$args->{pid}.'/wchan' );
$args->{wchan}=readline( $wchan_fh );
close( $wchan_fh );
$pid_wchan{ $args->{pid} }=$args->{wchan};
}
}else{
$args->{wchan}=$proc_table->[ $proc_int ]->{wchan};
$pid_wchan{ $args->{pid} }=$args->{wchan};
}
$args->{pid_start}=$proc_table->[ $proc_int ]->{pid_start};
$pid_start{ $args->{pid} }=$args->{pid_start};
@ -293,14 +307,6 @@ You can also look for information at:
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-lsof>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Net-Connection-lsof>
=item * CPAN Ratings
L<https://cpanratings.perl.org/d/Net-Connection-lsof>
=item * Search CPAN
L<https://metacpan.org/release/Net-Connection-lsof>

View File

@ -11,7 +11,7 @@ BEGIN {
}
my $output_raw=`lsof -i UDP -i TCP -n -l -P`;
my $output_raw=`lsof -i UDP -i TCP -n -l -P 2> /dev/null`;
if (
( $? eq 0 ) ||
(