blib/lib/Net/Connection.pm

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