diff options
-rw-r--r-- | lib/BER.pm | 2 | ||||
-rw-r--r-- | lib/SNMP_Session.pm | 23 | ||||
-rw-r--r-- | lib/SNMP_util.pm | 7 |
3 files changed, 19 insertions, 13 deletions
@@ -17,7 +17,7 @@ ### Contributions and fixes by: ### ### Andrzej Tobola <san@iem.pw.edu.pl>: Added long String decode -### Tobias Oetiker <oetiker@ee.ethz.ch>: Added 5 Byte Integer decode ... +### Tobias Oetiker <tobi@oetiker.ch>: Added 5 Byte Integer decode ... ### Dave Rand <dlr@Bungi.com>: Added SysUpTime decode ### Philippe Simonet <sip00@vg.swissptt.ch>: Support larger subids ### Yufang HU <yhu@casc.com>: Support even larger subids diff --git a/lib/SNMP_Session.pm b/lib/SNMP_Session.pm index 8521a52..4b9ccf9 100644 --- a/lib/SNMP_Session.pm +++ b/lib/SNMP_Session.pm @@ -62,7 +62,7 @@ sub map_table_start_end ($$$$$$); sub index_compare ($$); sub oid_diff ($$); -$VERSION = '1.12'; +$VERSION = '1.13'; @ISA = qw(Exporter); @@ -153,7 +153,11 @@ BEGIN { eval 'local $SIG{__DIE__};local $SIG{__WARN__};$dont_wait_flags = MSG_DONTWAIT();'; } -my $the_socket; +### Cache for reusable sockets. This is indexed by socket (address) +### family, so that we don't try to reuse an IPv4 socket for IPv6 or +### vice versa. +### +my %the_socket = (); $SNMP_Session::errmsg = ''; $SNMP_Session::suppress_warnings = 0; @@ -633,15 +637,15 @@ sub open { $remote_addr = inet_aton ($remote_hostname) or return $this->error_return ("can't resolve \"$remote_hostname\" to IP address"); } - if ($SNMP_Session::recycle_socket && defined $the_socket) { - $socket = $the_socket; + if ($SNMP_Session::recycle_socket && exists $the_socket{$sockfamily}) { + $socket = $the_socket{$sockfamily}; } else { $socket = IO::Socket::INET->new(Proto => 17, Type => SOCK_DGRAM, LocalAddr => $local_hostname, LocalPort => $local_port) || return $this->error_return ("creating socket: $!"); - $the_socket = $socket + $the_socket{$sockfamily} = $socket if $SNMP_Session::recycle_socket; } $remote_addr = pack_sockaddr_in ($port, $remote_addr) @@ -662,8 +666,8 @@ sub open { return $this->error_return ("can't resolve \"$remote_hostname\" to IPv6 address"); } - if ($SNMP_Session::recycle_socket && defined $the_socket) { - $socket = $the_socket; + if ($SNMP_Session::recycle_socket && exists $the_socket{$sockfamily}) { + $socket = $the_socket{$sockfamily}; } elsif ($sockfamily == AF_INET) { $socket = IO::Socket::INET->new(Proto => 17, Type => SOCK_DGRAM, @@ -676,7 +680,7 @@ sub open { LocalAddr => $local_hostname, LocalPort => $local_port) || return $this->error_return ("creating socket: $!"); - $the_socket = $socket + $the_socket{$sockfamily} = $socket if $SNMP_Session::recycle_socket; } } @@ -728,7 +732,8 @@ sub close { my($this) = shift; ## Avoid closing the socket if it may be shared with other session ## objects. - if (! defined $the_socket || $this->sock ne $the_socket) { + if (! exists $the_socket{$this->{sockfamily}} + or $this->sock ne $the_socket{$this->{sockfamily}}) { close ($this->sock) || $this->error ("close: $!"); } } diff --git a/lib/SNMP_util.pm b/lib/SNMP_util.pm index c3ea43e..20226f5 100644 --- a/lib/SNMP_util.pm +++ b/lib/SNMP_util.pm @@ -2,7 +2,7 @@ ###################################################################### ### SNMP_util -- SNMP utilities using SNMP_Session.pm and BER.pm ###################################################################### -### Copyright (c) 1998-2007, Mike Mitchell. +### Copyright (c) 1998-2008, Mike Mitchell. ### ### This program is free software; you can redistribute it under the ### "Artistic License 2.0" included in this distribution @@ -44,7 +44,7 @@ use BER "1.02"; use SNMP_Session "1.00"; use Socket; -$VERSION = '1.12'; +$VERSION = '1.13'; @ISA = qw(Exporter); @@ -1199,6 +1199,7 @@ sub snmpMIB_to_OID ($) { $buf =~ s/OBJECT-IDENTITY/OBJECT IDENTIFIER/; $buf =~ s/OBJECT-GROUP/OBJECT IDENTIFIER/; $buf =~ s/MODULE-IDENTITY/OBJECT IDENTIFIER/; + $buf =~ s/NOTIFICATION-TYPE/OBJECT IDENTIFIER/; $buf =~ s/ IMPORTS .*\;//; $buf =~ s/ SEQUENCE *{.*}//; $buf =~ s/ SYNTAX .*//; @@ -1275,7 +1276,7 @@ sub MIB_fill_OID ($) } } if ($val =~ /^[\d\.]+$/) { - $val =~ s/^\.//; + $val =~ s/^\.+//; if (!exists($SNMP_util::OIDS{$var}) || (length($val) > length($SNMP_util::OIDS{$var}))) { $SNMP_util::OIDS{$var} = $val; |