RE: canonical / non-canonical conversion

From: Scott Morris (swm@emanon.com)
Date: Wed Nov 16 2005 - 18:25:38 GMT-3


Call me silly.. But wouldn't it be easier to simply do your own conversions
on paper than learn/remember how to create the TCL script to do it?

Just a thought.

Scott
 

-----Original Message-----
From: nobody@groupstudy.com [mailto:nobody@groupstudy.com] On Behalf Of
Danny Cox
Sent: Wednesday, November 16, 2005 3:25 PM
To: FORUM
Subject: canonical / non-canonical conversion

given that tcl is available in IOS, albeit an ancient version, I thought it
might be interesting to see how it could be used. This might be of interest
to those who just want to use their router to check their conversions. I'd
have preferred to do something a bit more bit-savvy to avoid setting up the
array in the first place, but tcl 7.1 is, as I say, pretty old and doesn't
seem to support the bit operations. I've not time to spend too much on
doing this sort of thing, but it was interesting.

The first part just sets up an array called hexies to map between the
options. I know that's half the battle in doing the conversion between
canonical and non-canonical, but I still think it's useful as a doublecheck,
given that it stays stored in memory

enjoy.
Danny

R1# tcl
R1(tcl)# proc flip MAC {
 set hexies(0) 0
 set hexies(1) 8
 set hexies(2) 4
 set hexies(3) c
 set hexies(4) 2
 set hexies(5) a
 set hexies(6) 6
 set hexies(7) e
 set hexies(8) 1
 set hexies(9) 9
 set hexies(a) 5
 set hexies(b) d
 set hexies(c) 3
 set hexies(d) b
 set hexies(e) 7
 set hexies(f) f

 set CAM ""

 for {set i 1} {$i < 13} {incr i 1} {
  if {$i % 2} {
    set j [expr $i +1]
    set CAM $CAM$hexies([ string index $MAC $i ])
    set CAM $CAM$hexies([ string index $MAC [expr $i -1] ])
  }
 }

 return $CAM
}

To use this call it with

puts [ flip 080012345678 ]

or whatever the MAC address is you want to convert.



This archive was generated by hypermail 2.1.4 : Thu Dec 01 2005 - 09:12:07 GMT-3