From 0c1ea61a230dbc86d268d88ca1cc553cf40702ea Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Thu, 21 Mar 2019 07:43:35 +0100 Subject: [PATCH] WIP --- SNMPEngine.cs | 14 ++++++++++++++ SNMPInterface.cs | 4 ++-- rfc1213/RFC1213.cs | 2 +- types/ObjectIdentifier.cs | 6 +++--- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/SNMPEngine.cs b/SNMPEngine.cs index 5b39a3b..0b6c9cd 100644 --- a/SNMPEngine.cs +++ b/SNMPEngine.cs @@ -23,6 +23,20 @@ namespace ln.snmp { public static bool DEBUG = false; + private static SNMPEngine __default = null; + public static SNMPEngine DefaultEngine + { + get + { + if (__default == null) + __default = new SNMPEngine(); + return __default; + } + set => __default = value; + } + + + public UdpClient LocalEndpoint { get; private set; } public int Timeout { get; set; } = 1000; diff --git a/SNMPInterface.cs b/SNMPInterface.cs index 3d7e996..e13cc3f 100644 --- a/SNMPInterface.cs +++ b/SNMPInterface.cs @@ -134,7 +134,7 @@ namespace ln.snmp ObjectIdentifier oid = v.Items[0] as ObjectIdentifier; if (OIDs[c].Contains(oid)) { - row[c] = new Sequence(new Variable[] { oid.IndexTo(OIDs[c]), v.Items[1] }); + row[c] = new Sequence(new Variable[] { OIDs[c].IndexTo(oid), v.Items[1] }); inTree = true; } } @@ -174,7 +174,7 @@ namespace ln.snmp ObjectIdentifier oid = ps.Items[0] as ObjectIdentifier; if (objectIdentifier.Contains(oid)) { - results.Add(new Sequence(new Variable[] { oid.IndexTo(objectIdentifier), ps.Items[1] })); + results.Add(new Sequence(new Variable[] { objectIdentifier.IndexTo(oid), ps.Items[1] })); } else return results; diff --git a/rfc1213/RFC1213.cs b/rfc1213/RFC1213.cs index 0dead63..bc8b847 100644 --- a/rfc1213/RFC1213.cs +++ b/rfc1213/RFC1213.cs @@ -20,7 +20,7 @@ namespace ln.snmp.rfc1213 public static class RFC1213 { - public static Interface[] GetInterfaces(SnmpEndpoint endpoint) + public static Interface[] GetInterfaces(SnmpInterface endpoint) { Dictionary interfaces = new Dictionary(); ObjectIdentifier baseOID = new ObjectIdentifier("1.3.6.1.2.1.2.2.1.2"); diff --git a/types/ObjectIdentifier.cs b/types/ObjectIdentifier.cs index d4644e7..853336e 100644 --- a/types/ObjectIdentifier.cs +++ b/types/ObjectIdentifier.cs @@ -54,14 +54,14 @@ namespace ln.snmp.types public ObjectIdentifier IndexTo(ObjectIdentifier b) { - if (!b.Contains(this)) + if (!Contains(b)) throw new FormatException("OID is not below base OID"); int[] me = OIDValue; int[] you = b.OIDValue; - int[] result = new int[me.Length - you.Length]; - Array.Copy(me, you.Length, result, 0, result.Length); + int[] result = new int[you.Length - me.Length]; + Array.Copy(you, me.Length, result, 0, result.Length); return new ObjectIdentifier(result); }