Re: Octet String

Robert Premuz (rpremuz@srce.hr)
Sat, 1 Jun 1996 13:17:58 +0200 (MET DST)

On Fri, 31 May 1996, Stuart Jones wrote:
>
> I'm fairly new to Scotty and SNMP, but I didn't see this information
> anywhere. The man page says that ..
>
> SNMP data types are mapped to a Tcl string representation
> automatically.
>
> So I tried to instance an OCTET string with binary data. It didn't
> seem to do the binhex conversion. Is this wrong?
>
> # read data from file into instance
> $s instance app_data.0 app_data [read $fileid]
>
> app_data is defined in the MIB as type "OCTET STRING". Any help would
> be greatly appreciated. Thanks.

Nothing is wrong if you can read the text hidden between the lines :)

Actually, in commands which return varbinds got in response to a SNMP
request, scotty converts the values of the MIB variables into a
textual representation (see the 'snmp# get' command in the example
script below).

On the other hand, when a MIB variable is created in an agent session
or when a set request is sent, the value of the MIB variable must be
specified in the textual representation which corresponds to its type.
For your case, it means:

OCTET STRING A primitive OCTET STRING is represented
as a number of hexadecimal octets
separated by colons, e.g. 6e:61:73:65.

The manual also says that the conversion between the textual
representation and the so called underlying format of a value can be
done by the 'mib scan' and 'mib format' commands. Unfortunately, is
seems that for OCTET STRING type, the textual representation and the
underlying format are the same: the above hexadecimal notation.

So, in your script, you'll have to convert the octets you read from
the file to the scotty's hex format -- see in the example script how
to do that.

------------------------------------------------------------------------
#!/usr/local/bin/scotty -f
#
# agent.tcl

# Report all errors to standard error including the complete backtrace.
#
proc tkerror {msg} {
global errorInfo argv0
puts stderr "$argv0: background error\n$errorInfo"
}

mib load rfc1213.mib ;# sysDescr is defined as DisplayString
mib load rfc1447.mib ;# viewMask is defined as OCTET STRING

set binary \x1\x2\x3 ;# some binary data
set hex [mib scan sysDescr $binary] ;# conversion to the hex representation

set sess [snmp session -port 11111 -agent ""]

if [catch {
$sess instance viewMask.1 viewMask(1) 61:62:63
$sess instance viewMask.2 viewMask(2) $hex

# Note that wrong hex values don't cause an error:
#
$sess instance viewMask.3 viewMask(3) 1:6x:
}] {
puts stderr $errorInfo
}
puts "The values in Tcl variables:"
puts [array get viewMask]

# Send get requests to myself and print the returned varbinds.
#
puts "Responses to the get requests:"
$sess get viewMask.1 {puts {%E %V}}
$sess get viewMask.2 {puts {%E %V}}
$sess get viewMask.3 {puts {%E %V}}

snmp wait
after idle exit
------------------------------------------------------------------------

Hope this helps.

v
-- rpr. : Robert B. Premuz
Internet: rpremuz@malik.srce.hr * Voice at home: +385 (0)1 687564