blib/lib/Net/Connection.pm

filter: Statementstmt 55.6% 64 / 115 Branchbran 50.0% 37 / 74 Conditioncond 61.1% 33 / 54 MC/DCmcdc 46.8% 15 / 32 Subroutinesub 29.1% 7 / 24 Podpod 100% 20 / 20 totaltotal 55.1% 176 / 319 SCAR 58.3
CC
56
Cov
55%
new
316.0
foreign_host
2.0
foreign_port
2.0
CRAP 339.0
↑ Summary
1 package Net::Connection;
2  
3 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Net::DNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Net::Connection - Represents a network connection as a object.
11  
12 =head1 VERSION
13  
14 Version 0.2.0
15  
16 =cut
17  
18 2 our $VERSION = '0.2.0';
19  
20  
21 =head1 SYNOPSIS
22  
23 use Net::Connection;
24  
25 #create a hash ref with the desired values
26 my $args={
27 'foreign_host' => '1.2.3.4',
28 'local_host' => '4.3.2.1',
29 'foreign_port' => '22',
30 'local_port' => '11132',
31 'sendq' => '1',
32 'recvq' => '0',
33 'pid' => '34342',
34 'uid' => '1000',
35 'state' => 'ESTABLISHED',
36 'proto' => 'tcp4'
37 };
38
39 # create the new object using the hash ref
40 my $conn=Net::Connection->new( $args );
41
42 # the same thing, but this time resolve the UID to a username
43 $args->{'uid_resolve'}='1';
44 $conn=Net::Connection->new( $args );
45
46 # now with PTR lookup
47 $args->{'ptrs'}='1';
48 $conn=Net::Connection->new( $args );
49
50 # prints a bit of the connection information...
51 print "L Host:".$conn->local_host."\n".
52 "L Port:".$conn->local_host."\n".
53 "F Host:".$conn->foreign_host."\n".
54 "F Port:".$conn->foreign_host."\n";
55  
56 =head1 Methods
57  
58 =head2 new
59  
60 This initiates a new connection object.
61  
62 One argument is taken is taken and it is a hash reference.
63 The minimum number of arguements is as below.
64  
65 local_host
66 local_port
67 foreign_host
68 foreign_port
69 proto
70 state
71  
72 =head3 keys
73  
74 =head4 foreign_host
75  
76 The local host of the connection.
77  
78 This can either be a IP or hostname. Max utility is achieved via a
79 IP though as that allows PTR lookup to be done.
80  
81 If appears to be a hostname, it is copied to local_ptr and even
82 if asked to resolve PTRs it won't attempt to.
83  
84 =head4 foreign_port
85  
86 This is the foreign port of the connection.
87  
88 For best utility, using numeric here is best.
89  
90 If ports is true it will attempt to resolve it,
91 including reverse resolving if it is a port name instead.
92  
93 If ports is false or not set and this value is
94 non-numeric, it will be copied to foreign_port_name.
95  
96 =head4 foreign_port_name
97  
98 This is the name of foreign port, if one exists in the
99 service records.
100  
101 =head4 foreign_ptr
102  
103 This is the PTR address for foreign_host.
104  
105 If ptrs is not true and foreign_host appears to be
106 a hostname, then it is set to the same as foreign_host.
107  
108 =head4 local_port
109  
110 This is the local port of the connection.
111  
112 For best utility, using numeric here is best.
113  
114 If ports is true it will attempt to resolve it,
115 including reverse resolving if it is a port name instead.
116  
117 If ports is false or not set and this value is
118 non-numeric, it will be copied to local_port_name.
119  
120 =head4 local_port_name
121  
122 This is the name of local port, if one exists in the
123 service records.
124  
125 =head4 local_ptr
126  
127 This is the PTR address for local_host.
128  
129 If ptrs is not true and local_host appears to be
130 a hostname, then it is set to the same as local_host.
131  
132 =head2 pctcpu
133  
134 Percent of CPU usage by the PID for this connection.
135  
136 =head2 pctmem
137  
138 Percent of memory usage by the PID for this connection.
139  
140 =head4 pid
141  
142 This is the pid for a connection.
143  
144 If defined, it needs to be numeric.
145  
146 =head4 pid_start
147  
148 The start time in seconds of the PID for the connection.
149  
150 =head4 ports
151  
152 If true, it will attempt to resolve the port names.
153  
154 =head4 proto
155  
156 This is the protocol type.
157  
158 This needs to be defined, but unfortunately no real checking is done
159 as of currently as various OSes uses varrying capitalizations and slightly
160 different forms of TCP, TCP4, tcp4, tcpv4, and the like.
161  
162 =head4 proc
163  
164 Either the command line or fname if that is blank for the PID.
165  
166 =head4 ptrs
167  
168 If is true, then attempt to look up the PTRs for the hosts.
169  
170 =head4 recvq
171  
172 This is the recieve queue size.
173  
174 If set, it must be numeric.
175  
176 =head4 sendq
177  
178 This is the send queue size.
179  
180 If set, it must be numeric.
181  
182 =head4 state
183  
184 This is the current state of the connection.
185  
186 This needs to be defined, but unfortunately no real checking is
187 done as of currently as there are minor naming differences between
188 OSes as well as some including states that are not found in others.
189  
190 =head4 uid
191  
192 The UID is the of the user the has the connection open.
193  
194 This must be numeric.
195  
196 If uid_resolve is set to true then the UID will be resolved
197 and stored in username.
198  
199 If this is not defined, uid_resolve is true, and username is defined
200 then it will attempt to resolve the UID from the username.
201  
202 =head4 uid_resolve
203  
204 If set to true and uid is given, then a attempt will be made to
205 resolve the UID to a username.
206  
207 =head4 username
208  
209 This is the username for a connection.
210  
211 If uid_resolve is true and uid is defined, then this
212 will attempt to be automatically contemplated.
213  
214 If uid_resolve is true and uid is defined, then this
215 will attempt to be automatically contemplated.
216  
217 =head4 wchan
218  
219 The current wait channel for the PID of the connection in question.
220  
221 =cut
222  
223 sub new{
224 16 ▶ my %args;
Subroutine new: called CC=56 SCAR=57.6
Pod documented
225 16 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 16 0 16
226 16 %args= %{$_[1]};
227 };
228  
229 # make sure we got the required bits
230 16 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"foreign_host"} and defined $args{"local_host"} and defined $args{"foreign_port"} and defined $args{"local_port"} and defined $args{"state"} and defined $args{"proto"}) 2 9 11
Condition100%15/15
defined $args{"foreign_host"} and defined $args{"local_host"} and defined $args{"foreign_port"} and defined $args{"local_port"} and defined $args{"state"} and defined $args{"proto"}
!ll&&!rl&&r
619
defined $args{"foreign_host"} and defined $args{"local_host"} and defined $args{"foreign_port"} and defined $args{"local_port"} and defined $args{"state"}
!ll&&!rl&&r
5110
defined $args{"foreign_host"} and defined $args{"local_host"} and defined $args{"foreign_port"} and defined $args{"local_port"}
!ll&&!rl&&r
4111
defined $args{"foreign_host"} and defined $args{"local_host"} and defined $args{"foreign_port"}
!ll&&!rl&&r
3112
defined $args{"foreign_host"} and defined $args{"local_host"}
!ll&&!rl&&r
2113
MC/DC100%6/6
defined $args{"foreign_host"} and defined $args{"local_host"} and defined $args{"foreign_port"} and defined $args{"local_port"} and defined $args{"state"} and defined $args{"proto"}
defined $args{"foreign_host"} defined $args{"local_host"} defined $args{"foreign_port"} defined $args{"local_port"} defined $args{"state"} defined $args{"proto"}
Truth table100%7/7
A and B and C and D and E and F
A= defined $args{"foreign_host"}B= defined $args{"local_host"}C= defined $args{"foreign_port"}D= defined $args{"local_port"}E= defined $args{"state"}F= defined $args{"proto"}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
231 (!defined( $args{'foreign_host'}) ) ||
232 (!defined( $args{'local_host'}) ) ||
233 (!defined( $args{'foreign_port'}) ) ||
234 (!defined( $args{'local_port'}) ) ||
235 (!defined( $args{'state'}) ) ||
236 (!defined( $args{'proto'}) )
237 ){
238 7 die "One or more of the required arguments is not defined";
239 }
240  
241 # PID must be numeric if given
242 9 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"pid"} and not $args{"pid"} =~ /^[0-9]+$/) 1 8 9
Condition100%3/3
defined $args{"pid"} and not $args{"pid"} =~ /^[0-9]+$/
!ll&&!rl&&r
351
MC/DC100%2/2
defined $args{"pid"} and not $args{"pid"} =~ /^[0-9]+$/
defined $args{"pid"} not $args{"pid"} =~ /^[0-9]+$/
Truth table100%3/3
A and not(B)
A= defined $args{"pid"}B= not $args{"pid"} =~ /^[0-9]+$/
ABresult
0X0
100
111
243 defined( $args{'pid'} ) &&
244 ( $args{'pid'} !~ /^[0-9]+$/ )
245 ){
246 1 die '$args{"pid"} is not numeric';
247 }
248  
249 # UID must be numeric if given
250 8 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"uid"} and not $args{"uid"} =~ /^[0-9]+$/) 1 7 8
Condition100%3/3
defined $args{"uid"} and not $args{"uid"} =~ /^[0-9]+$/
!ll&&!rl&&r
521
MC/DC100%2/2
defined $args{"uid"} and not $args{"uid"} =~ /^[0-9]+$/
defined $args{"uid"} not $args{"uid"} =~ /^[0-9]+$/
Truth table100%3/3
A and not(B)
A= defined $args{"uid"}B= not $args{"uid"} =~ /^[0-9]+$/
ABresult
0X0
100
111
251 defined( $args{'uid'} ) &&
252 ( $args{'uid'} !~ /^[0-9]+$/ )
253 ){
254 1 die '$args{"uid"} is not numeric';
255 }
256  
257 # set the sendq/recvq and make sure they are numeric if given
258 7 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"sendq"} and not $args{"sendq"} =~ /^[0-9]+$/) 1 6 7
Condition66%2/3
defined $args{"sendq"} and not $args{"sendq"} =~ /^[0-9]+$/
!ll&&!rl&&r
061
MC/DC50%1/2
defined $args{"sendq"} and not $args{"sendq"} =~ /^[0-9]+$/
defined $args{"sendq"} not $args{"sendq"} =~ /^[0-9]+$/
Truth table66%2/3
A and not(B)
A= defined $args{"sendq"}B= not $args{"sendq"} =~ /^[0-9]+$/
ABresult
0X0
100
111
259 defined( $args{'sendq'} ) &&
260 ( $args{'sendq'} !~ /^[0-9]+$/ )
261 ){
262 1 die '$args{"sendq"} is not numeric';
263 }
264 6 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"recvq"} and not $args{"recvq"} =~ /^[0-9]+$/) 1 5 6
Condition66%2/3
defined $args{"recvq"} and not $args{"recvq"} =~ /^[0-9]+$/
!ll&&!rl&&r
051
MC/DC50%1/2
defined $args{"recvq"} and not $args{"recvq"} =~ /^[0-9]+$/
defined $args{"recvq"} not $args{"recvq"} =~ /^[0-9]+$/
Truth table66%2/3
A and not(B)
A= defined $args{"recvq"}B= not $args{"recvq"} =~ /^[0-9]+$/
ABresult
0X0
100
111
265 defined( $args{'recvq'} ) &&
266 ( $args{'recvq'} !~ /^[0-9]+$/ )
267 ){
268 1 die '$args{"recvq"} is not numeric';
269 }
270  
271 my $self={
272 'foreign_host' => $args{'foreign_host'},
273 'local_host' => $args{'local_host'},
274 'foreign_port' => $args{'foreign_port'},
275 'foreign_port_name' => $args{'foreign_port_name'},
276 'local_port' => $args{'local_port'},
277 'local_port_name' => $args{'local_port_name'},
278 'sendq' => undef,
279 'recvq' => undef,
280 'pid' => undef,
281 'uid' => undef,
282 'username' => undef,
283 'state' => $args{'state'},
284 5 'proto' => $args{'proto'},
285 'local_ptr' => undef,
286 'foreign_ptr' => undef,
287 'pctcpu' => undef,
288 'pctmem' => undef,
289 'proc' => undef,
290 'wchan' => undef,
291 };
292 5 bless $self;
293  
294 # Set these if defined
295 5 ▶ if (defined( $args{'sendq'} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"sendq"}) 5 0 5
296 5 $self->{'sendq'}=$args{'sendq'};
297 }
298 5 ▶ if (defined( $args{'recvq'} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"recvq"}) 5 0 5
299 5 $self->{'recvq'}=$args{'recvq'};
300 }
301 5 ▶ if (defined( $args{'local_ptr'} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"local_ptr"}) 0 5 5
302 0 $self->{'local_ptr'}=$args{'local_ptr'};
303 }
304 5 ▶ if (defined( $args{'foreign_ptr'} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"foreign_ptr"}) 0 5 5
305 0 $self->{'foreign_ptr'}=$args{'foreign_ptr'};
306 }
307 5 ▶ if (defined( $args{'uid'} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"uid"}) 2 3 5
308 2 $self->{'uid'}=$args{'uid'};
309 }
310 5 ▶ if (defined( $args{'pid'} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"pid"}) 4 1 5
311 4 $self->{'pid'}=$args{'pid'};
312 }
313 5 ▶ if (defined( $args{'username'} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"username"}) 1 4 5
314 1 $self->{'username'}=$args{'username'};
315 }
316 5 ▶ if (defined( $args{'proc'} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"proc"}) 0 5 5
317 0 $self->{'proc'}=$args{'proc'};
318 }
319 5 ▶ if (defined( $args{'wchan'} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"wchan"}) 0 5 5
320 0 $self->{'wchan'}=$args{'wchan'};
321 }
322 5 ▶ if (defined( $args{'pctmem'} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"pctmem"}) 0 5 5
323 0 $self->{'pctmem'}=$args{'pctmem'};
324 }
325 5 ▶ if (defined( $args{'pctcpu'} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"pctcpu"}) 0 5 5
326 0 $self->{'pctcpu'}=$args{'pctcpu'};
327 }
328  
329 # resolve port names if asked to
330 5 ▶ if ( $args{ports} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'ports'}) { } 0 5 5
331 # If the port is non-numeric, set the name and attempt to resolve it.
332 0 ▶ if ( $self->{'local_port'} =~ /[A-Za-z]/ ){
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'local_port'} =~ /[A-Za-z]/) { } 0 0 0
elsif ($self->{'local_port'} =~ /^[0-9]+$/) { } 0 0 0
333 0 $self->{'local_port_name'}=$self->{'local_port'};
334 0 my $service=getservbyname($self->{'local_port_name'}, undef);
335 0 ▶ if (defined( $service )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $service) 0 0 0
336 0 $self->{'local_port'}=$service;
337 }
338 }elsif( $self->{'local_port'} =~ /^[0-9]+$/ ){
339 0 $self->{'local_port_name'}=getservbyport( $self->{'local_port'}, 'tcp' );
340 }
341 0 ▶ if ( $self->{'foreign_port'} =~ /[A-Za-z]/ ){
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'foreign_port'} =~ /[A-Za-z]/) { } 0 0 0
elsif ($self->{'foreign_port'} =~ /^[0-9]+$/) { } 0 0 0
342 0 $self->{'foreign_port_name'}=$self->{'foreign_port'};
343 0 my $service=getservbyname($self->{'foreign_port_name'}, undef);
344 0 ▶ if (defined( $service )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $service) 0 0 0
345 0 $self->{'foreign_port'}=$service;
346 }
347 }elsif( $self->{'foreign_port'} =~ /^[0-9]+$/ ){
348 0 $self->{'foreign_port_name'}=getservbyport( $self->{'foreign_port'}, 'tcp' );
349 }
350 }else{
351 # If the port is non-numeric, set it as the port name
352 5 ▶ if ( $self->{'local_port'} =~ /[A-Za-z]/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"local_port"} =~ /[A-Za-z]/) 0 5 5
353 0 $self->{'local_port_name'}=$self->{'local_port'};
354 }
355 5 ▶ if ( $self->{'foreign_port'} =~ /[A-Za-z]/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"foreign_port"} =~ /[A-Za-z]/) 0 5 5
356 0 $self->{'foreign_port_name'}=$self->{'foreign_port'};
357 }
358 }
359  
360 5 my $dns=Net::DNS::Resolver->new;
361  
362 # resolve PTRs if asked to
363 5 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'ptrs'} and $args{'ptrs'}) { } 0 5 5
Condition33%1/3
defined $args{"ptrs"} and $args{"ptrs"}
!ll&&!rl&&r
500
MC/DC0%0/2
defined $args{"ptrs"} and $args{"ptrs"}
defined $args{"ptrs"} $args{"ptrs"}
Truth table33%1/3
A and B
A= defined $args{"ptrs"}B= $args{"ptrs"}
ABresult
0X0
100
111
364 defined( $args{ptrs} ) &&
365 $args{ptrs}
366 ){
367 # process foreign_host
368 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'foreign_host'} =~ /[A-Za-z]/ and not $self->{'foreign_host'} =~ /\:/) { } 0 0 0
Condition0%0/3
$self->{"foreign_host"} =~ /[A-Za-z]/ and not $self->{"foreign_host"} =~ /\:/
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"foreign_host"} =~ /[A-Za-z]/ and not $self->{"foreign_host"} =~ /\:/
$self->{"foreign_host"} =~ /[A-Za-z]/ not $self->{"foreign_host"} =~ /\:/
Truth table0%0/3
A and not(B)
A= $self->{"foreign_host"} =~ /[A-Za-z]/B= not $self->{"foreign_host"} =~ /\:/
ABresult
0X0
100
111
369 ( $self->{'foreign_host'} =~ /[A-Za-z]/ ) &&
370 ( $self->{'foreign_host'} !~ /\:/ )
371 ){
372 # appears to be a hostname already
373 0 $self->{'foreign_ptr'}=$self->{'foreign_host'};
374 }else{
375 # attempt to resolve it
376 0 eval{
377 0 my $answer=$dns->search( $self->{'foreign_host'} );
378 0 ▶ if ( defined( $answer->{answer}[0] ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $answer->{"answer"}[0] and ref $answer->{"answer"}[0] eq "Net::DNS::RR::PTR") 0 0 0
Condition0%0/3
defined $answer->{"answer"}[0] and ref $answer->{"answer"}[0] eq "Net::DNS::RR::PTR"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $answer->{"answer"}[0] and ref $answer->{"answer"}[0] eq "Net::DNS::RR::PTR"
defined $answer->{"answer"}[0] ref $answer->{"answer"}[0] eq "Net::DNS::RR::PTR"
Truth table0%0/3
A and B
A= defined $answer->{"answer"}[0]B= ref $answer->{"answer"}[0] eq "Net::DNS::RR::PTR"
ABresult
0X0
100
111
379 ( ref( $answer->{answer}[0] ) eq 'Net::DNS::RR::PTR' )
380 ){
381 0 $self->{'foreign_ptr'}=lc($answer->{answer}[0]->ptrdname);
382 }
383 }
384 }
385 # process local_host
386 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'local_host'} =~ /[A-Za-z]/ and not $self->{'local_host'} =~ /\:/) { } 0 0 0
Condition0%0/3
$self->{"local_host"} =~ /[A-Za-z]/ and not $self->{"local_host"} =~ /\:/
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"local_host"} =~ /[A-Za-z]/ and not $self->{"local_host"} =~ /\:/
$self->{"local_host"} =~ /[A-Za-z]/ not $self->{"local_host"} =~ /\:/
Truth table0%0/3
A and not(B)
A= $self->{"local_host"} =~ /[A-Za-z]/B= not $self->{"local_host"} =~ /\:/
ABresult
0X0
100
111
387 ( $self->{'local_host'} =~ /[A-Za-z]/ ) &&
388 ( $self->{'local_host'} !~ /\:/ )
389 ){
390 # appears to be a hostname already
391 0 $self->{'local_ptr'}=$self->{'local_host'};
392 }else{
393 # attempt to resolve it
394 0 eval{
395 0 my $answer=$dns->search( $self->{'local_host'} );
396 0 ▶ if ( defined( $answer->{answer}[0] ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $answer->{"answer"}[0] and ref $answer->{"answer"}[0] eq "Net::DNS::RR::PTR") 0 0 0
Condition0%0/3
defined $answer->{"answer"}[0] and ref $answer->{"answer"}[0] eq "Net::DNS::RR::PTR"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $answer->{"answer"}[0] and ref $answer->{"answer"}[0] eq "Net::DNS::RR::PTR"
defined $answer->{"answer"}[0] ref $answer->{"answer"}[0] eq "Net::DNS::RR::PTR"
Truth table0%0/3
A and B
A= defined $answer->{"answer"}[0]B= ref $answer->{"answer"}[0] eq "Net::DNS::RR::PTR"
ABresult
0X0
100
111
397 ( ref( $answer->{answer}[0] ) eq 'Net::DNS::RR::PTR' )
398 ){
399 0 $self->{'local_ptr'}=lc($answer->{answer}[0]->ptrdname);
400 }
401 }
402 }
403 }else{
404 # We are not doing auto PTR resolving...
405 # just set them if it appears to be a hostname
406 5 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"foreign_host"} =~ /[A-Za-z]/ and not $self->{"foreign_host"} =~ /\:/) 0 5 5
Condition33%1/3
$self->{"foreign_host"} =~ /[A-Za-z]/ and not $self->{"foreign_host"} =~ /\:/
!ll&&!rl&&r
500
MC/DC0%0/2
$self->{"foreign_host"} =~ /[A-Za-z]/ and not $self->{"foreign_host"} =~ /\:/
$self->{"foreign_host"} =~ /[A-Za-z]/ not $self->{"foreign_host"} =~ /\:/
Truth table33%1/3
A and not(B)
A= $self->{"foreign_host"} =~ /[A-Za-z]/B= not $self->{"foreign_host"} =~ /\:/
ABresult
0X0
100
111
407 ( $self->{'foreign_host'} =~ /[A-Za-z]/ ) &&
408 ( $self->{'foreign_host'} !~ /\:/ )
409 ){
410 0 $self->{'foreign_ptr'}=$self->{'foreign_host'};
411 }
412 5 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"local_host"} =~ /[A-Za-z]/ and not $self->{"local_host"} =~ /\:/) 0 5 5
Condition33%1/3
$self->{"local_host"} =~ /[A-Za-z]/ and not $self->{"local_host"} =~ /\:/
!ll&&!rl&&r
500
MC/DC0%0/2
$self->{"local_host"} =~ /[A-Za-z]/ and not $self->{"local_host"} =~ /\:/
$self->{"local_host"} =~ /[A-Za-z]/ not $self->{"local_host"} =~ /\:/
Truth table33%1/3
A and not(B)
A= $self->{"local_host"} =~ /[A-Za-z]/B= not $self->{"local_host"} =~ /\:/
ABresult
0X0
100
111
413 ( $self->{'local_host'} =~ /[A-Za-z]/ ) &&
414 ( $self->{'local_host'} !~ /\:/ )
415 ){
416 0 $self->{'local_ptr'}=$self->{'local_host'};
417 }
418 }
419  
420 # resolve the UID/username if asked
421 5 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'uid_resolve'} and defined $self->{'uid'}) { } 1 4 5
elsif ($args{'uid_resolve'} and not defined $self->{'uid'}) { } 1 6 7
Condition100%3/3
$args{"uid_resolve"} and defined $self->{"uid"}
!ll&&!rl&&r
311
MC/DC100%2/2
$args{"uid_resolve"} and defined $self->{"uid"}
$args{"uid_resolve"} defined $self->{"uid"}
Truth table100%3/3
A and B
A= $args{"uid_resolve"}B= defined $self->{"uid"}
ABresult
0X0
100
111
422 $args{'uid_resolve'} &&
423 defined( $self->{'uid'} )
424 ){
425 1 eval{
426 1 my @pwline=getpwuid( $self->{'uid'} );
427 1 ▶ if ( defined( $pwline[0] ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pwline[0]) 1 0 1
428 1 $self->{'username'}=$pwline[0];
429 }
430 }
431 ▶ }elsif (
Condition66%2/3
$args{"uid_resolve"} and not defined $self->{"uid"}
!ll&&!rl&&r
301
MC/DC50%1/2
$args{"uid_resolve"} and not defined $self->{"uid"}
$args{"uid_resolve"} not defined $self->{"uid"}
Truth table66%2/3
A and not(B)
A= $args{"uid_resolve"}B= not defined $self->{"uid"}
ABresult
0X0
100
111
432 $args{'uid_resolve'} &&
433 ( ! defined( $self->{'uid'} ) )
434 ){
435 1 eval{
436 1 my @pwline=getpwnam( $self->{'username'} );
437 1 ▶ if ( defined( $pwline[2] ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pwline[2]) 1 0 1
438 1 $self->{'uid'}=$pwline[2];
439 }
440 }
441 }
442  
443 5 return $self;
444 }
445  
446 =head2 foreign_host
447  
448 Returns the foreign host.
449  
450 my $f_host=$conn->foreign_host;
451  
452 =cut
453  
454 sub foreign_host{
455 0 ▶ return $_[0]->{'foreign_host'};
Subroutine foreign_host: not called CC=1 SCAR=6.9
Pod documented
456 }
457  
458 =head2 foreign_port
459  
460 This returns the foreign port.
461  
462 my $f_port=$conn->foreign_port;
463  
464 =cut
465  
466 sub foreign_port{
467 0 ▶ return $_[0]->{'foreign_port'};
Subroutine foreign_port: not called CC=1 SCAR=6.9
Pod documented
468 }
469  
470 =head2 foreign_port_name
471  
472 This returns the foreign port name.
473  
474 This may potentially return undef if one is
475 not set/unknown.
476  
477 my $f_port=$conn->foreign_port;
478  
479 =cut
480  
481 sub foreign_port_name{
482 0 ▶ return $_[0]->{'foreign_port_name'};
Subroutine foreign_port_name: not called CC=1 SCAR=6.9
Pod documented
483 }
484  
485 =head2 foreign_ptr
486  
487 This returns the PTR for the foreign host.
488  
489 If one was not supplied or if it could not be found
490 if resolving was enabled then undef will be returned.
491  
492 my $f_ptr=$conn->foreign_ptr;
493  
494 =cut
495  
496 sub foreign_ptr{
497 0 ▶ return $_[0]->{'foreign_ptr'};
Subroutine foreign_ptr: not called CC=1 SCAR=6.9
Pod documented
498 }
499  
500 =head2 local_host
501  
502 Returns the local host.
503  
504 my $l_host=$conn->local_host;
505  
506 =cut
507  
508 sub local_host{
509 0 ▶ return $_[0]->{'local_host'};
Subroutine local_host: not called CC=1 SCAR=6.9
Pod documented
510 }
511  
512 =head2 local_port
513  
514 This returns the local port.
515  
516 my $l_port=$conn->local_port;
517  
518 =cut
519  
520 sub local_port{
521 0 ▶ return $_[0]->{'local_port'};
Subroutine local_port: not called CC=1 SCAR=6.9
Pod documented
522 }
523  
524 =head2 local_port_name
525  
526 This returns the local port name.
527  
528 This may potentially return undef if one is
529 not set/unknown.
530  
531 my $l_port=$conn->local_port;
532  
533 =cut
534  
535 sub local_port_name{
536 0 ▶ return $_[0]->{'local_port_name'};
Subroutine local_port_name: not called CC=1 SCAR=6.9
Pod documented
537 }
538  
539 =head2 local_ptr
540  
541 This returns the PTR for the local host.
542  
543 If one was not supplied or if it could not be found
544 if resolving was enabled then undef will be returned.
545  
546 my $l_ptr=$conn->local_ptr;
547  
548 =cut
549  
550 sub local_ptr{
551 0 ▶ return $_[0]->{'local_ptr'};
Subroutine local_ptr: not called CC=1 SCAR=6.9
Pod documented
552 }
553  
554 =head2 pctcpu
555  
556 Returns the percent of memory in use by the process
557 that has connection.
558  
559 This may not be if it was not set. Please see new
560 for more information.
561  
562 my $pctcpu=$conn->pctcpu;
563  
564 =cut
565  
566 sub pctcpu{
567 0 ▶ return $_[0]->{'pctcpu'};
Subroutine pctcpu: not called CC=1 SCAR=6.9
Pod documented
568 }
569  
570 =head2 pctmem
571  
572 Returns the percent of memory in use by the process
573 that has connection.
574  
575 This may not be if it was not set. Please see new
576 for more information.
577  
578 my $pctmem=$conn->pctmem;
579  
580 =cut
581  
582 sub pctmem{
583 0 ▶ return $_[0]->{'pctmem'};
Subroutine pctmem: not called CC=1 SCAR=6.9
Pod documented
584 }
585  
586 =head2 pid
587  
588 This returns the pid of a connection.
589  
590 This may return undef.
591  
592 my $pid=$conn->pid;
593  
594 =cut
595  
596 sub pid{
597 0 ▶ return $_[0]->{'pid'};
Subroutine pid: not called CC=1 SCAR=6.9
Pod documented
598 }
599  
600 =head2 proc
601  
602 Returns the command line or fname for the process
603 that has the connection.
604  
605 This may not be if it was not set. Please see new
606 for more information.
607  
608 my $proc=$conn->proc;
609  
610 =cut
611  
612 sub proc{
613 0 ▶ return $_[0]->{'proc'};
Subroutine proc: not called CC=1 SCAR=6.9
Pod documented
614 }
615  
616 =head2 proto
617  
618 Returns the protocol in use by the connection.
619  
620 Please note this value with vary slightly between OSes.
621  
622 my $proto=$conn->proto;
623  
624 =cut
625  
626 sub proto{
627 0 ▶ return $_[0]->{'proto'};
Subroutine proto: not called CC=1 SCAR=6.9
Pod documented
628 }
629  
630 =head2 recvq
631  
632 Returns the size of the recieve queue the connection.
633  
634 This may return undef.
635  
636 my $recvq=$conn->recvq;
637  
638 =cut
639  
640 sub recvq{
641 0 ▶ return $_[0]->{'recvq'};
Subroutine recvq: not called CC=1 SCAR=6.9
Pod documented
642 }
643  
644  
645 =head2 sendq
646  
647 Returns the size of the send queue the connection.
648  
649 This may return undef.
650  
651 my $sendq=$conn->sendq;
652  
653 =cut
654  
655 sub sendq{
656 0 ▶ return $_[0]->{'sendq'};
Subroutine sendq: not called CC=1 SCAR=6.9
Pod documented
657 }
658  
659 =head2 state
660  
661 Returns the state the connection is currently in.
662  
663 Please note this value with vary slightly between OSes.
664  
665 my $state=$conn->state;
666  
667 =cut
668  
669 sub state{
670 0 ▶ return $_[0]->{'state'};
Subroutine state: not called CC=1 SCAR=6.9
Pod documented
671 }
672  
673 =head2 uid
674  
675 Returns the UID that has the connection.
676  
677 This may not be if it was not set. Please see new
678 for more information.
679  
680 my $uid=$conn->uid;
681  
682 =cut
683  
684 sub uid{
685 2 ▶ return $_[0]->{'uid'};
Subroutine uid: called CC=1 SCAR=0.0
Pod documented
686 }
687  
688 =head2 username
689  
690 Returns the username that has the connection.
691  
692 This may not be if it was not set. Please see new
693 for more information.
694  
695 my $username=$conn->username;
696  
697 =cut
698  
699 sub username{
700 2 ▶ return $_[0]->{'username'};
Subroutine username: called CC=1 SCAR=0.0
Pod documented
701 }
702  
703 =head2 wchan
704  
705 Returns the wchan for the process that has the connection.
706  
707 This may not be if it was not set. Please see new
708 for more information.
709  
710 my $wchan=$conn->wchan;
711  
712 =cut
713  
714 sub wchan{
715 0 ▶ return $_[0]->{'wchan'};
Subroutine wchan: not called CC=1 SCAR=6.9
Pod documented
716 }
717  
718 =head1 AUTHOR
719  
720 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
721  
722 =head1 BUGS
723  
724 Please report any bugs or feature requests to C<bug-net-connection at rt.cpan.org>, or through
725 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection>. I will be notified, and then you'll
726 automatically be notified of progress on your bug as I make changes.
727  
728  
729  
730  
731 =head1 SUPPORT
732  
733 You can find documentation for this module with the perldoc command.
734  
735 perldoc Net::Connection
736  
737  
738 You can also look for information at:
739  
740 =over 4
741  
742 =item * RT: CPAN's request tracker (report bugs here)
743  
744 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection>
745  
746 =item * AnnoCPAN: Annotated CPAN documentation
747  
748 L<http://annocpan.org/dist/Net-Connection>
749  
750 =item * CPAN Ratings
751  
752 L<https://cpanratings.perl.org/d/Net-Connection>
753  
754 =item * Search CPAN
755  
756 L<https://metacpan.org/release/Net-Connection>
757  
758 =item * Repository
759  
760 L<http://gitea.eesdp.org/vvelox/Net-Connection>
761  
762 =back
763  
764  
765 =head1 ACKNOWLEDGEMENTS
766  
767  
768 =head1 LICENSE AND COPYRIGHT
769  
770 This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
771  
772 This is free software, licensed under:
773  
774 The Artistic License 2.0 (GPL Compatible)
775  
776  
777 =cut
778  
779 2 1; # End of Net::Connection
↑ Summary