From 8e17a1bb6bd604f93a01f6187e400cfe827aff2d Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Mon, 18 Mar 2019 08:12:58 +0100 Subject: [PATCH] WIP --- SNMPEngine.cs | 3 ++- SNMPInterface.cs | 6 ++++-- endpoint/USMEndpoint.cs | 2 +- rfc1213/RFC1213.cs | 14 ++++++++------ types/Unsigned32.cs | 28 ++++++++++++++++++++++++++-- types/Variable.cs | 2 ++ 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/SNMPEngine.cs b/SNMPEngine.cs index 0b8fc55..5b39a3b 100644 --- a/SNMPEngine.cs +++ b/SNMPEngine.cs @@ -53,6 +53,7 @@ namespace ln.snmp { shutdown = true; LocalEndpoint.Close(); + ReceiverThread.Interrupt(); } private void Receiver() @@ -64,7 +65,7 @@ namespace ln.snmp IPEndPoint remoteEndpoint = null; byte[] datagram = LocalEndpoint.Receive(ref remoteEndpoint); - Logging.Log(LogLevel.DEBUG,"SNMPClient: Received: {0}", BitConverter.ToString(datagram)); + Logging.Log(LogLevel.DEBUGDETAIL,"SNMPClient: Received: {0}", BitConverter.ToString(datagram)); ASN1Value asn = new ASN1Value(datagram); SnmpMessage snmpMessage = asn; diff --git a/SNMPInterface.cs b/SNMPInterface.cs index 472ad86..3d7e996 100644 --- a/SNMPInterface.cs +++ b/SNMPInterface.cs @@ -41,7 +41,7 @@ namespace ln.snmp List results = new List(); foreach (Variable varBind in varBinds.Items) { - results.Add(varBind as Sequence); + results.Add(varBind as Sequence); } return results; } @@ -214,13 +214,15 @@ namespace ln.snmp { cont = true; row[n] = next[n]; + row[n].Items = new Variable[] { OIDs[n].IndexTo(lastOIDs[n]), next[n].Items[1] }; } else { row[n] = null; } } - results.Add(row); + if (cont) + results.Add(row); } return results.ToArray(); } diff --git a/endpoint/USMEndpoint.cs b/endpoint/USMEndpoint.cs index a162363..6f53b9c 100644 --- a/endpoint/USMEndpoint.cs +++ b/endpoint/USMEndpoint.cs @@ -224,7 +224,7 @@ namespace ln.snmp.endpoint } Logging.Log(LogLevel.DEBUGDETAIL, "Authenticating Message: {0}",BitConverter.ToString(wholeMsg)); - Logging.Log(LogLevel.DEBUG, "Authenticated Message: {0}", BitConverter.ToString(((ASN1Value)message).AsByteArray)); + Logging.Log(LogLevel.DEBUGDETAIL, "Authenticated Message: {0}", BitConverter.ToString(((ASN1Value)message).AsByteArray)); return true; } diff --git a/rfc1213/RFC1213.cs b/rfc1213/RFC1213.cs index 0294355..0dead63 100644 --- a/rfc1213/RFC1213.cs +++ b/rfc1213/RFC1213.cs @@ -14,6 +14,7 @@ using ln.snmp.endpoint; using ln.snmp.types; using System.Linq; using ln.types; +using ln.logging; namespace ln.snmp.rfc1213 { public static class RFC1213 @@ -22,20 +23,21 @@ namespace ln.snmp.rfc1213 public static Interface[] GetInterfaces(SnmpEndpoint endpoint) { Dictionary interfaces = new Dictionary(); + ObjectIdentifier baseOID = new ObjectIdentifier("1.3.6.1.2.1.2.2.1.2"); Sequence[][] ifTable = endpoint.snmpWalk(new String[] { "1.3.6.1.2.1.2.2.1.2", - "1.3.6.1.2.1.2.2.1.10", - "1.3.6.1.2.1.2.2.1.16", - "1.3.6.1.2.1.2.2.1.14", - "1.3.6.1.2.1.2.2.1.20" + "1.3.6.1.2.1.2.2.1.6" }); foreach (Sequence[] row in ifTable) { ObjectIdentifier index = (row[0].Items[0] as ObjectIdentifier); + Interface intf = new Interface(); intf.Name = (row[0].Items[1] as OctetString).StringValue; + intf.HWAddr = BitConverter.ToString((row[1].Items[1] as OctetString).Bytes); + interfaces.Add(index.OIDValue[0],intf); } @@ -66,11 +68,11 @@ namespace ln.snmp.rfc1213 public class Interface { public String Name { get; set; } + public String HWAddr { get => hwaddr; set => hwaddr = value; } public CIDR[] IPAddresses => _IPAddresses.ToArray(); - private List _IPAddresses = new List(); - + private String hwaddr; public Interface() { diff --git a/types/Unsigned32.cs b/types/Unsigned32.cs index 265e789..e28b11f 100644 --- a/types/Unsigned32.cs +++ b/types/Unsigned32.cs @@ -15,7 +15,7 @@ namespace ln.snmp.types public uint UIntValue { get; set; } public Unsigned32() - :base(new Identifier(IdentifierClass.APPLICATION, false, 0x02)) + :base(new Identifier(IdentifierClass.APPLICATION, false, 0x102)) { } @@ -57,7 +57,31 @@ namespace ln.snmp.types { } public Counter32(uint value) - : base(new Identifier(IdentifierClass.APPLICATION, false, 0x01),value) + : base(new Identifier(IdentifierClass.APPLICATION, false, 0x01), value) + { + } + } + + public class Gauge32 : Unsigned32 + { + public Gauge32() + : base(new Identifier(IdentifierClass.APPLICATION, false, 0x02)) + { + } + public Gauge32(uint value) + : base(new Identifier(IdentifierClass.APPLICATION, false, 0x02), value) + { + } + } + + public class TimeTicks : Unsigned32 + { + public TimeTicks() + : base(new Identifier(IdentifierClass.APPLICATION, false, 0x03)) + { + } + public TimeTicks(uint value) + : base(new Identifier(IdentifierClass.APPLICATION, false, 0x03), value) { } } diff --git a/types/Variable.cs b/types/Variable.cs index b0725f9..562edf3 100644 --- a/types/Variable.cs +++ b/types/Variable.cs @@ -120,6 +120,8 @@ namespace ln.snmp.types registerKnownType(); registerKnownType(); registerKnownType(); + registerKnownType(); + registerKnownType(); registerKnownType(); registerKnownType(); registerKnownType();