master
Harald Wolff 2019-03-18 08:12:58 +01:00
parent 9a5acf3cbd
commit 8e17a1bb6b
6 changed files with 43 additions and 12 deletions

View File

@ -53,6 +53,7 @@ namespace ln.snmp
{ {
shutdown = true; shutdown = true;
LocalEndpoint.Close(); LocalEndpoint.Close();
ReceiverThread.Interrupt();
} }
private void Receiver() private void Receiver()
@ -64,7 +65,7 @@ namespace ln.snmp
IPEndPoint remoteEndpoint = null; IPEndPoint remoteEndpoint = null;
byte[] datagram = LocalEndpoint.Receive(ref remoteEndpoint); 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); ASN1Value asn = new ASN1Value(datagram);
SnmpMessage snmpMessage = asn; SnmpMessage snmpMessage = asn;

View File

@ -41,7 +41,7 @@ namespace ln.snmp
List<Sequence> results = new List<Sequence>(); List<Sequence> results = new List<Sequence>();
foreach (Variable varBind in varBinds.Items) foreach (Variable varBind in varBinds.Items)
{ {
results.Add(varBind as Sequence); results.Add(varBind as Sequence);
} }
return results; return results;
} }
@ -214,13 +214,15 @@ namespace ln.snmp
{ {
cont = true; cont = true;
row[n] = next[n]; row[n] = next[n];
row[n].Items = new Variable[] { OIDs[n].IndexTo(lastOIDs[n]), next[n].Items[1] };
} }
else else
{ {
row[n] = null; row[n] = null;
} }
} }
results.Add(row); if (cont)
results.Add(row);
} }
return results.ToArray(); return results.ToArray();
} }

View File

@ -224,7 +224,7 @@ namespace ln.snmp.endpoint
} }
Logging.Log(LogLevel.DEBUGDETAIL, "Authenticating Message: {0}",BitConverter.ToString(wholeMsg)); 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; return true;
} }

View File

@ -14,6 +14,7 @@ using ln.snmp.endpoint;
using ln.snmp.types; using ln.snmp.types;
using System.Linq; using System.Linq;
using ln.types; using ln.types;
using ln.logging;
namespace ln.snmp.rfc1213 namespace ln.snmp.rfc1213
{ {
public static class RFC1213 public static class RFC1213
@ -22,20 +23,21 @@ namespace ln.snmp.rfc1213
public static Interface[] GetInterfaces(SnmpEndpoint endpoint) public static Interface[] GetInterfaces(SnmpEndpoint endpoint)
{ {
Dictionary<int,Interface> interfaces = new Dictionary<int,Interface>(); Dictionary<int,Interface> interfaces = new Dictionary<int,Interface>();
ObjectIdentifier baseOID = new ObjectIdentifier("1.3.6.1.2.1.2.2.1.2");
Sequence[][] ifTable = endpoint.snmpWalk(new String[] { 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.2",
"1.3.6.1.2.1.2.2.1.10", "1.3.6.1.2.1.2.2.1.6"
"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"
}); });
foreach (Sequence[] row in ifTable) foreach (Sequence[] row in ifTable)
{ {
ObjectIdentifier index = (row[0].Items[0] as ObjectIdentifier); ObjectIdentifier index = (row[0].Items[0] as ObjectIdentifier);
Interface intf = new Interface(); Interface intf = new Interface();
intf.Name = (row[0].Items[1] as OctetString).StringValue; 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); interfaces.Add(index.OIDValue[0],intf);
} }
@ -66,11 +68,11 @@ namespace ln.snmp.rfc1213
public class Interface public class Interface
{ {
public String Name { get; set; } public String Name { get; set; }
public String HWAddr { get => hwaddr; set => hwaddr = value; }
public CIDR[] IPAddresses => _IPAddresses.ToArray(); public CIDR[] IPAddresses => _IPAddresses.ToArray();
private List<CIDR> _IPAddresses = new List<CIDR>(); private List<CIDR> _IPAddresses = new List<CIDR>();
private String hwaddr;
public Interface() public Interface()
{ {

View File

@ -15,7 +15,7 @@ namespace ln.snmp.types
public uint UIntValue { get; set; } public uint UIntValue { get; set; }
public Unsigned32() 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) 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)
{ {
} }
} }

View File

@ -120,6 +120,8 @@ namespace ln.snmp.types
registerKnownType<Integer>(); registerKnownType<Integer>();
registerKnownType<OctetString>(); registerKnownType<OctetString>();
registerKnownType<Unsigned32>(); registerKnownType<Unsigned32>();
registerKnownType<Gauge32>();
registerKnownType<TimeTicks>();
registerKnownType<Counter32>(); registerKnownType<Counter32>();
registerKnownType<Counter64>(); registerKnownType<Counter64>();
registerKnownType<Sequence>(); registerKnownType<Sequence>();