in reply to SNMP String format

does your encode_string look like this?

sub encode_string { pack 'C*', map {hex} split /\s/, shift }

it probably should (i've never used SNMP_Session, prefering Net::SNMP or plain old SNMP modules).

Replies are listed 'Best First'.
Re: Re: SNMP String format
by traveler (Parson) on Mar 11, 2003 at 21:57 UTC
    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

      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", ]);
        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

        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".