in reply to Re: SNMP String format
in thread SNMP String format

This would not encode the string. If it is to be an OCTET STRING (sorry, the name is always in caps), it would be encoded as 04 04 9A 20 FF 09 (for the first example). You need the type (04 == OCTET STRING), the length (4) and then the value. This is the TLV (Type, Length, Value) encoding used by SNMP. Other data types are also encoded with TLV, but the type (T) is different. (IIRC, as an IP address this would be 40 04 9A 20 FF 09 for 154.32.255.9).

--traveler

Replies are listed 'Best First'.
Re: Re: Re: SNMP String format
by zengargoyle (Deacon) on Mar 11, 2003 at 22:51 UTC

    the SNMP (or Net::SNMP) module will take care of that for you. at least it does for me.

    $res = $sess->set_request(-varbindlist => [ '1.3.6.1.4.1.5624.1.2.9.1.2.1.1.4.34603010', OCTET_STRING, "b +lahfoo", ]);

      then this:

      ($type eq 'string') && do { $value = encode_string($value); push @enoid, [$oid,$value]; next; };

      should probably be this:

      ($type eq 'string') && do { $value = encode_string( pack "C*" map {hex} split /\s/, $value ); push @enoid, [$oid,$value]; next; };

      because you likely want to encode "\xAA\xBB\xCC\xDD" and not "AA BB CC DD".

      Yes, but mugster has:
      use SNMP_Session; use BER;
      I dont't see any reference to SNMP or Net::SNMP. I think these modules must behave differently than Net::SNMP. BER probably has the encode functions that do the BER encoding.

      --traveler