[time-nuts] Oncore Checksums

Chris Kuethe chris.kuethe at gmail.com
Thu Apr 17 21:59:41 EDT 2008


On Thu, Apr 17, 2008 at 6:51 PM, Matthew Smith <matt at smiffytech.com> wrote:
> Quoth Chris Kuethe at 2008-04-18 10:59...
>
> > int
>  > oncore_checksum(char *buf, int len){
>  >       unsigned char a, b;
>  >       int i;
>  >
>  >       a = buf[len-3];
>  >       b = '\0';
>  >       for(i = 2; i < len - 3; i++)
>  >               b ^= buf[i];
>  >       if (a == b)
>  >               return 0;
>  >       return 1;
>  > }
>
>  'Scuse me for being something of a C newbie, but does that not return
>  either a 1 or a 0, but not the checksum?
>
>  Otherwise, I can follow the logic.  Thanks.

yeah, i should've mentioned, that's function i use to check the sum,
not compute it. return b instead, or just patch the buffer inside the
function:

void
oncore_add_checksum(char *buf, int len){
	unsigned char b;
	int i;

	b = '\0';
	for(i = 2; i < len - 3; i++)
		b ^= buf[i];
	buf[len-3] = b;
}


-- 
GDB has a 'break' feature; why doesn't it have 'fix' too?



More information about the time-nuts mailing list