File Coverage

blib/lib/Net/SNMP/HostInfo/TcpConnEntry.pm
Criterion Covered Total %
statement 12 33 36.3
branch 0 8 0.0
condition 0 6 0.0
subroutine 4 6 66.6
pod 0 1 0.0
total 16 54 29.6


line stmt bran cond sub pod time code
1             package Net::SNMP::HostInfo::TcpConnEntry;
2            
3             =head1 NAME
4            
5             Net::SNMP::HostInfo::TcpConnEntry - An entry in the tcpConnTable of a MIB-II host
6            
7             =head1 SYNOPSIS
8            
9             use Net::SNMP::HostInfo;
10            
11             $host = shift || 'localhost';
12             $hostinfo = Net::SNMP::HostInfo->new(Hostname => $host);
13            
14             print "\nTcp Connection Table:\n";
15             printf "%-15s %-5s %-15s %-5s %s\n",
16             qw/LocalAddress Port RemAddress Port State/;
17             for $entry ($hostinfo->tcpConnTable) {
18             printf "%-15s %-5s %-15s %-5s %s\n",
19             $entry->tcpConnLocalAddress,
20             $entry->tcpConnLocalPort,
21             $entry->tcpConnRemAddress,
22             $entry->tcpConnRemPort,
23             $entry->tcpConnState;
24             }
25            
26             =head1 DESCRIPTION
27            
28             "Information about a particular current TCP
29             connection. An object of this type is transient,
30             in that it ceases to exist when (or soon after)
31             the connection makes the transition to the CLOSED
32             state."
33            
34             =cut
35            
36 1     1   17 use 5.006;
  1         3  
  1         38  
37 1     1   5 use strict;
  1         1  
  1         30  
38 1     1   5 use warnings;
  1         2  
  1         28  
39            
40 1     1   5 use Carp;
  1         1  
  1         788  
41            
42             #our $VERSION = '0.01';
43            
44             our $AUTOLOAD;
45            
46             my %oids = (
47             tcpConnState => '1.3.6.1.2.1.6.13.1.1',
48             tcpConnLocalAddress => '1.3.6.1.2.1.6.13.1.2',
49             tcpConnLocalPort => '1.3.6.1.2.1.6.13.1.3',
50             tcpConnRemAddress => '1.3.6.1.2.1.6.13.1.4',
51             tcpConnRemPort => '1.3.6.1.2.1.6.13.1.5',
52             );
53            
54             my %decodedObjects = (
55             tcpConnState => { qw/1 closed
56             2 listen
57             3 synSent
58             4 synReceived
59             5 established
60             6 finWait1
61             7 finWait2
62             8 closeWait
63             9 lastAck
64             10 closing
65             11 timeWait
66             12 deleteTCB/ },
67             );
68            
69             # Preloaded methods go here.
70            
71             =head1 METHODS
72            
73             =over
74            
75             =cut
76            
77             sub new
78             {
79 0     0 0   my $class = shift;
80            
81 0           my %args = @_;
82            
83 0           my $self = {};
84            
85 0           $self->{_session} = $args{Session};
86 0           $self->{_decode} = $args{Decode};
87 0           $self->{_index} = $args{Index};
88            
89 0           bless $self, $class;
90 0           return $self;
91             }
92            
93             =item tcpConnState
94            
95             "The state of this TCP connection.
96            
97             The only value which may be set by a management
98             station is deleteTCB(12). Accordingly, it is
99             appropriate for an agent to return a `badValue'
100             response if a management station attempts to set
101             this object to any other value.
102            
103             If a management station sets this object to the
104             value deleteTCB(12), then this has the effect of
105             deleting the TCB (as defined in RFC 793) of the
106             corresponding connection on the managed node,
107             resulting in immediate termination of the
108             connection.
109            
110             As an implementation-specific option, a RST
111             segment may be sent from the managed node to the
112             other TCP endpoint (note however that RST segments
113             are not sent reliably)."
114            
115             Possible values are:
116            
117             closed(1),
118             listen(2),
119             synSent(3),
120             synReceived(4),
121             established(5),
122             finWait1(6),
123             finWait2(7),
124             closeWait(8),
125             lastAck(9),
126             closing(10),
127             timeWait(11),
128             deleteTCB(12)
129            
130             =item tcpConnLocalAddress
131            
132             "The local IP address for this TCP connection. In
133             the case of a connection in the listen state which
134             is willing to accept connections for any IP
135             interface associated with the node, the value
136             0.0.0.0 is used."
137            
138             =item tcpConnLocalPort
139            
140             "The local port number for this TCP connection."
141            
142             =item tcpConnRemAddress
143            
144             "The remote IP address for this TCP connection."
145            
146             =item tcpConnRemPort
147            
148             "The remote port number for this TCP connection."
149            
150             =back
151            
152             =cut
153            
154             sub AUTOLOAD
155             {
156 0     0     my $self = shift;
157            
158 0 0         return if $AUTOLOAD =~ /DESTROY$/;
159            
160 0           my ($name) = $AUTOLOAD =~ /::([^:]+)$/;
161             #print "Called $name\n";
162            
163 0 0         if (!exists $oids{$name}) {
164 0           croak "Can't locate object method '$name'";
165             }
166            
167 0           my $oid = $oids{$name} . '.' . $self->{_index};
168            
169             #print "Trying $oid\n";
170            
171 0           my $response = $self->{_session}->get_request($oid);
172            
173 0 0         if ($response) {
174 0           my $value = $response->{$oid};
175            
176 0 0 0       if ($self->{_decode} &&
      0        
177             exists $decodedObjects{$name} &&
178             exists $decodedObjects{$name}{$value}) {
179 0           return $decodedObjects{$name}{$value}."($value)";
180             } else {
181 0           return $value;
182             }
183             } else {
184 0           return undef;
185             }
186             }
187            
188             1;
189            
190             __END__