How to convert MAC address to a link-local IPV6 address in TCL -


i trying convert mac address link-local ipv6 address using tcl. have code snippet works integer based mac address not hex based ones, start non-numeral character. current code:

set newmac ac:de:48:1d:27:6d  lassign $newmac __o1 __o2 __o3 __o4 __o5 __o6  set __o1 [expr $__o1 ^ 0x02]  ;# universal bit flip  set __ip fe80::${__o1}${__o2}:${__o3}ff:fe${__o4}:${__o5}${__o6} 

the bit flipping/inverting part not work address, think expr expects integer, although same code works fine other addresses example - 55:12:34:26:21:97

can suggest me way improve code works cases?

first, lassign have not work. have included original lassign in code below can see happens. have wanted:

lassign [split $newmac :] __o1 __o2 __o3 __o4 __o5 __o6 

to achieve wanted. correct expr expects integers. use scan command scan hex values string. , use format convert hex.

set newmac ac:de:48:1d:27:6d lassign $newmac __o1 __o2 __o3 __o4 __o5 __o6 puts "$__o1 - $__o2 - $__o3 - $__o4 - $__o5 - $__o6" scan $newmac {%02x:%02x:%02x:%02x:%02x:%02x} __o1 __o2 __o3 __o4 __o5 __o6 puts "$__o1 $__o2 $__o3 $__o4 $__o5 $__o6" set __o1 [expr $__o1 ^ 0x02] ;# universal bit flip set __ip [format {fe80::%02x%02x:%02xff:fe%02x:%02x%02x} \     $__o1 $__o2 $__o3 $__o4 $__o5 $__o6] puts "$__ip" 

output:

ac:de:48:1d:27:6d -  -  -  -  -  172 222 72 29 39 109 fe80::aede:48ff:fe1d:276d 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -