Reputation: 9
I am developing a SNMP utility in C# which can fetch data from a specified device OID using the SNMP version 1 packet format.
I have almost completed it but their is a problem that I am not able to resolve.
I am successfully querying one variable by sending a single "Get" packet but I need to query multiple variables by sending a single packet.
I tried it in this way:
//variable bindings
p[bytepos++] = 0x30; //variable bindings sequence
p[bytepos++] = Convert.ToByte(6 + oid_len - 1 + 6 + oid_len2 - 1); // Size of variable binding
p[bytepos++] = 0x30; //first variable bindings sequence
p[bytepos++] = Convert.ToByte(4 + oid_len - 1); // size
p[bytepos++] = 0x06; //Object type
p[bytepos++] = Convert.ToByte(oid_len - 1 ); //length
//Start of MIB
p[bytepos++] = 0x2b;
for (i = 2; i < oid_len; i++)
p[bytepos++] = Convert.ToByte(oid[i]);
p[bytepos++] = 0x05; //Null object value
p[bytepos++] = 0x00; //Null
//start of second variable bindings sequence
p[bytepos++] = 0x30; //Second variable bindings sequence
p[bytepos++] = Convert.ToByte(4 + oid_len2 - 1); // size
p[bytepos++] = 0x06; //Object type
p[bytepos++] = Convert.ToByte(oid_len2 - 1); //length
//Start of MIB
p[bytepos++] = 0x2b;
//Place MIB array in packet
for (i2 = 2; i2 < oid_len2; i2++)
p[bytepos++] = Convert.ToByte(oid2[i2]);
p[bytepos++] = 0x05; //Null object value
p[bytepos++] = 0x00; //Null
I googled a lot but could not find any thing relevant.
Upvotes: 0
Views: 1787
Reputation: 63264
Parsing SNMP PDU from raw bytes, is never as simple as the code segment you pasted.
To seriously use SNMP in C#, you need to consider one of the following libraries,
https://docs.lextudio.com/blog/product-review-snmp-libraries-for-net-evaluation-report-e13f25991cad
Upvotes: 3