Re: ? scotty how to transform OCTET STRING to IpAddress

Juergen Schoenwaelder (schoenw@cs.utwente.nl)
Wed, 10 Jul 1996 11:48:37 +0200

frs0139@trt-philips.fr (Damien WETZEL) wrote:

> I would like to if there is a scotty primitive to transform a string
> of the OCTET STRING value to the classical ipAddress format.
> EXAMPLE :
> foo (C0:02:03:66) ----> 192.2.3.102

No, there is no primitive for this conversion (which is basically a
cast of primitive SNMP data types).

> I tried with mib scan and mib format without success
> thanks for any clues

These commands usually apply display-hints or convert enumerations to
primitive INTEGER values. You can use the mib scan and mib format
commands if you supply a textual convention with a display-hint like
"1d.1d.1d.1d" but this is probably not the right way to do this
conversion if you can't write a new MIB definition. So you will most
likely write a small Tcl proc like:

proc octets2ip {octets} {
scan $octets "%x:%x:%x:%x" a b c d
format "%d.%d.%d.%d" $a $b $c $d
}

Of course, this is slower than a primitive but I guess that this type
of conversion is not used too often.
Juergen