Am Freitag, Juni 07, 2019 23:46 CEST, Stuart Henderson <stu@spacehopper.org> schrieb:
> On 2019/06/07 23:08, Sebastian Reitenbach wrote:
> > Hi,
> >
> > tcl 8.6 has binary encode/decode functions [1], so I'm trying to convert a hex string representation of an IPv4 or IPv6 address into binary and back to the hex representation.
> >
> > I'd have expected that this decode hex to binary and back should always be reversible, but
> > doesn't seem to be the case:
> >
> > # tclsh8.6 test3.tcl
> > 4 10.22.66.138
> > a16428a
>
> binary decode/encode works with pairs of hex digits, but you don't
> have pairs here. (if you use an address with the first octet >=16 it
> will work).
>
> > puts "$ipv $i"
> > if { $ipv == 4 } {
> > set normalized [format %x [ip::toInteger $i]]
>
> format %08x
>
sometimes the solutions is sooo simple, works like a charm.
thanks so much for the cluebat!
cheers,
Sebastian
No comments:
Post a Comment