Re: binary scan issue
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: binary scan issue

From: Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at>
Date: Mon Dec 12 2005 - 13:35:31 CET

Lisa Pearlson <no@spam.plz> wrote:
> proc parsebinpacketsize {bbody} {
> if {[string length $bbody] < 2} {
> return 0
> }
> binary scan [string range $bbody 0 1] S sz
> return $sz
> }
> set bin [binary format S 259]
> set hdr [string range $bin 0 1]
> binary scan $hdr S sz
> puts "Size: $sz"

two lines from your followup:
: the last line should've been:
: puts "Size: [parsebinpacketsize $hdr]"

> This should work, and display "Size: 259"
> But instead, I get an error:
> can't read "sz": no such variable

If you get a "no such variable"-error for a variable
specified as target of a [binary scan ...], then this
means, that the binary scan did not have enough data
to scan the requested type.

Based on your procedure, this shouldn't be possible,
since, if the bbody was shorter than the two bytes
necessary for the "S" type, then you explicitly return 0.

So, my guess is, that your tries were not the same as
what you posted.

If you're really sure about having posted your example
correctly, then we need to know your tcl-version,
platform and other environmental information
for debugging.
Received on Fri Dec 23 18:58:44 2005