FAaBbiii February 2016

snmpsharpnet Opaque Float

I query a Synlogy NAS via snmpsharpnet in c# and get the following Value for the UPS Battery:

OID: Type: Opaque Data: 9F 78 04 42 C8 00 00

However, it should be a float value => 100.00

Same at the Voltage:

OID: Type: Opaque Data: 9F 78 04 43 65 00 00

float value => 230.00

How can I get the value?

My Code:

        // SNMP community name
        OctetString communityo = new OctetString(community);
        // Define agent parameters class
        AgentParameters param = new AgentParameters(communityo);
        // Set SNMP version to 1 (or 2)
        param.Version = SnmpVersion.Ver1;
        // Construct the agent address object
        // IpAddress class is easy to use here because
        //  it will try to resolve constructor parameter if it doesn't
        //  parse to an IP address
        IpAddress agent = new IpAddress(host);

        // Construct target
        UdpTarget target = new UdpTarget((IPAddress)agent, 161, 2000, 1);

        // Pdu class used for all requests
        Pdu pdu = new Pdu(PduType.Get);
        pdu.VbList.Add(batteryoid); //
        pdu.VbList.Add(voltageoid); //
        pdu.VbList.Add(statusoid); //

        // Make SNMP request
        SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param);

        // If result is null then agent didn't reply or we couldn't parse the reply.
        if (result != null)
            // ErrorStatus other then 0 is an error returned by 
            // the Agent - see SnmpConstants for error definitions
            if (result.Pdu.ErrorStatus != 0)
                // agent reported an error with the request
                Console.WriteLine("Error in SNMP reply. Error {0} index {1}",
                // Reply variables are         


antiduh February 2016

Opaque data from SNMP means that the value for some field is itself BER-encoded ASN.1 data - it's encoded in the same language that SNMP queries themselves are encoded in.

For some quick background ASN.1 is a standard for modeling data - it defines how to structure data in a standard way such that the structure can be understood by other programs. ASN.1 is not a system for encoding that structure in bits and bytes - that is the job of either the BER or DER encoding standards.

The data you have - 9F 78 04 42 C8 00 00 - is BER-encoded data. BER data is separated into three parts: type, length, and value.

If we disassemble your bytes using that template, we come up with 9f78 is the type; 04 is the length, and 42c80000 is the value.

According to some of NetSnmp's documentation, a 'type' code of 9f78, in BER, means "FLOATTYPE". Looks promising.

The next byte is the length byte, 04 in this case. This means that we have a 4-byte float in the value.

Lastly, we have the value code 42c80000. According to RFC 6340, this value is to be interpreted as a standard IEEE 754 32-bit float. IEEE 754 is the most widely used standard for encoding floating point values into bits - it's what most computers and programming languages use. C#'s float type is defined as an IEEE 754 32-bit single precision floating point value, and double is an IEEE 754 64-bit double precision floating point value, for instance

If we use a handy-dandy online converter to convert the raw byte

Post Status

Asked in February 2016
Viewed 3,936 times
Voted 9
Answered 1 times


Leave an answer