[En-Nut-Discussion] UDP BroadCast

Harald Kipp harald.kipp at egnite.de
Mon Sep 23 19:49:49 CEST 2002


Avex,

Wow, big problem in the checksum routines. It appeared
once, but suddenly disappeared again for no know reason.

The broadcast telegrams in your code produce these wrong
checksums again.

Here's what the original author (Dave Hudson) wrote (see
ipcsum.c):

"This doesn't look particularly intuitive at
first sight - in fact it probably looks plain wrong.  It does work
however (take my word for it), but for some explanation the reader
is referred to RFC1071 where the maths is explained in detail."

Here's my comment:

"Yes, the GCC version looks wrong. I assume that
this will not work for all packet sizes. Not yet confirmed."

For a quick solution one may use the commented C code
routine (from Klaus Ummenhofer):

u_short NutIpChkSumPartial(u_short partial_csum, void *buf, u_short count)
{
	u_long sum = partial_csum;
	u_short *d2 = (u_short*) buf;
	while (count > 1)
	{
		sum += *d2++;	
		count -= 2;
	}
	if (count > 0)
		sum += *(u_char*) d2++;
		
	while (sum>>16)
		sum = (sum & 0xFFFF) + (sum >>16);

	partial_csum = sum;
     return partial_csum;
}

Using your sample this works here.

Harald




More information about the En-Nut-Discussion mailing list