checksum() is expecting the payload to be a str, not an array.array('B').  
IIRC, the NOX packet library basically always ends up with a str 
(struct.pack()ing the header fields and concatenating with the payload after 
possibly calling .tostring() on it).  This is the kind of thing that it calls 
checksum() on, so the assumption that it's passed a str is probably a decent 
one, so I don't think it's a bug.

This raises the question of how you're building the packets and where you are 
calling checksum() from, but in any event, you can just call .tostring() on 
your array before passing it to checksum(), or run your own version of 
checksum(), or modify checksum() to see if it's passed an array.array('B') 
since apparently creating an array from an array doesn't re-pack the values.

-- Murphy

On Aug 24, 2011, at 10:43 AM, ibrahim mun wrote:

> The reason is that wireshark shows checksum error in received packets (I've 
> built). in python prompt I tried:
> data=array.array('B',"example")
> arr=array.array('H', data)
> and the result was an array of bytes! modifying the code I don't receive any 
> erroneous packets.
> 
> Is this my special casa or maybe a python issue?
> Thanks,
> 
> Ibrahim
> 
> Subject: Re: [nox-dev] FW: Checksum calculation bug?
> From: jam...@nau.edu
> Date: Wed, 24 Aug 2011 04:35:20 -0700
> CC: nox-dev@noxrepo.org
> To: ibrahim.me...@alumnos.upm.es
> 
> Do you have any reason to suspect that it isn't functioning correctly?
> 
> It seems like you are assuming that arr is an array of bytes.  However, if 
> you look at the top of the function, you'll see that it's actually an 
> array.array of "H" values, which are unsigned two-byte values.
> 
> -- Murphy
> 
> On Aug 24, 2011, at 4:19 AM, ibrahim mun wrote:
> 
> 
> Hi,
> 
> I think we have a bug in packet_utils.checksum, please check it:
> =============================
> def checksum(data, start, skip_word = 0):
> 
>     if len(data) % 2 != 0:
>         arr = array.array('H', data[:-1])
>     else:
>         arr = array.array('H', data)
> 
>     if skip_word:
>         for i in range(0, len(arr)):
>             if i == skip_word:
>                 continue
>             start +=  arr[i]
>     else:        
>        for i in range(0,len(arr)): # BUG?   
>             start +=  arr[i]        # BUG? 
>        # IT should be :
>        # for i in range(0, len(arr)-1,2):
>        # start +=  arr[i]*0x100 +arr[i+1]
> 
>     if len(data) % 2 != 0:
>         start += struct.unpack('H', data[-1]+'\0')[0]
> 
>     start  = (start >> 16) + (start & 0xffff)
>     start += (start >> 16);
> 
>     return ntohs(~start & 0xffff)
> ===============================
> 
> Thanks,
> 
> Ibrahim
> 
> 
> _______________________________________________
> nox-dev mailing list
> nox-dev@noxrepo.org
> http://noxrepo.org/mailman/listinfo/nox-dev
> 
> 

_______________________________________________
nox-dev mailing list
nox-dev@noxrepo.org
http://noxrepo.org/mailman/listinfo/nox-dev

Reply via email to