Re: Problem with [binary scan] and sign in Tcl 8.4
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: Problem with [binary scan] and sign in Tcl 8.4

From: Christopher Nelson <cnelson@nycap.rr.com>
Date: Wed May 25 2005 - 19:20:06 CEST

Michael Schlenker wrote:
> Christopher Nelson wrote:
> > I'm trying to parse MAC addresses out of binary buffers with [binary
> > scan] but negative signs keep creeping in:
> >
> > ...
> >
> > I can't find an option to tell [binary scan] to treat the bytes as
> > unsigned. Am I missing something?
> >
> There is no option for unsigned..., read the man page, there is an
> example how to mask with & to get unsigned values, but this works only
> up to 63 bit values (as Tcl has no larger internal type).

Ahh, just the thing:

  proc parse_ether { msg aName } {
    upvar $aName a

    binary scan $msg "c6 c6 S a*" dst src a(tl) a(data)
    foreach f {dst src} {
        set a($f) {}
        foreach e [set $f] {
            lappend a($f) [expr {$e & 0xff}]
        }
    }
  }

Thanks.
Received on Thu Sep 29 14:19:00 2005