Hi,

When using SNMP::Session->new() without a SecEngineId, it is probed.
However, there's no way to actually find the probed value from Perl
(which would be useful for e.g. storing it for faster later reconnect;
the probing is synchronous and can take a long time, especially if
the host is done). I've attached a patch that adds two new functions
for exactly this.

/* Steinar */
-- 
Homepage: http://www.sesse.net/
Index: net-snmp-5.7.2.1~dfsg/perl/SNMP/SNMP.pm
===================================================================
--- net-snmp-5.7.2.1~dfsg.orig/perl/SNMP/SNMP.pm	2014-10-19 22:12:02.852839926 +0200
+++ net-snmp-5.7.2.1~dfsg/perl/SNMP/SNMP.pm	2014-10-19 22:20:12.000000000 +0200
@@ -1243,6 +1243,16 @@
    return(wantarray() ? @res : $res[0]);
 }
 
+sub get_sec_engine_id {
+   my $this = shift;
+   return SNMP::_get_sec_engine_id($this);
+}
+
+sub get_context_engine_id {
+   my $this = shift;
+   return SNMP::_get_context_engine_id($this);
+}
+
 package SNMP::TrapSession;
 @SNMP::TrapSession::ISA = ('SNMP::Session');
 
@@ -2039,6 +2049,17 @@
 
 =back
 
+=item $sess->get_sec_engine_id
+
+Returns the security engine ID for the current session, whether probed
+or provided by the client, in hex format suitable for the SecEngineId
+parameter when creating a session in the future. Returns undef if we have not
+had not had any contact with the remote agent yet.
+
+=item $sess->get_context_engine_id
+
+Like get_sec_engine_id, but for the context engine ID (ContextEngineId).
+
 =back
 
 =head1 SNMP::TrapSession
Index: net-snmp-5.7.2.1~dfsg/perl/SNMP/SNMP.xs
===================================================================
--- net-snmp-5.7.2.1~dfsg.orig/perl/SNMP/SNMP.xs	2014-10-19 22:20:12.000000000 +0200
+++ net-snmp-5.7.2.1~dfsg/perl/SNMP/SNMP.xs	2014-10-19 22:22:18.732965363 +0200
@@ -4740,6 +4740,50 @@
 
 
 char *
+snmp_get_sec_engine_id(sess_ref)
+        SV *	sess_ref
+	CODE:
+	{
+           RETVAL = NULL;
+           if (SvROK(sess_ref)) {
+              SV **sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1);
+	      SnmpSession *ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv));
+              if (ss->securityEngineIDLen > 0) {
+                 binary_to_hex(ss->securityEngineID,
+                               ss->securityEngineIDLen,
+                               &RETVAL);
+              }
+           }
+	}
+	OUTPUT:
+        RETVAL
+        CLEANUP:
+        netsnmp_free(RETVAL);
+
+
+char *
+snmp_get_context_engine_id(sess_ref)
+        SV *	sess_ref
+	CODE:
+	{
+           RETVAL = NULL;
+           if (SvROK(sess_ref)) {
+              SV **sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1);
+	      SnmpSession *ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv));
+              if (ss->contextEngineIDLen > 0) {
+                 binary_to_hex(ss->contextEngineID,
+                               ss->contextEngineIDLen,
+                               &RETVAL);
+              }
+           }
+	}
+	OUTPUT:
+        RETVAL
+        CLEANUP:
+        netsnmp_free(RETVAL);
+
+
+char *
 snmp_get_type(tag, best_guess)
 	char *		tag
         int             best_guess
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to