Link to home
Start Free TrialLog in
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMPFlag for United States of America

asked on

CRC TCP/IP Lean

Hi All,

Can someone explain what the following code is doing?  I'm assuming it has something to do with CRC and overflow.  

The full function and some hints can be found here but don't have the book as of yet.

http://books.google.com/books?id=NOLVo6KjmVIC&pg=PA310&lpg=PA310&dq=void+check_byte(BYTE+b)&source=bl&ots=jMj-Xp3B0R&sig=loy2s4WwaqiJl3WT7i350g3xqUc&hl=en&ei=tAm6S5C_KYv88wSJutDqAw&sa=X&oi=book_result&ct=result&resnum=4&ved=0CBEQ6AEwAw#v=onepage&q=void%20check_byte(BYTE%20b)&f=false


void check_byte(BYTE b)
{
    if (checkflag)
    {
        if ((checklo = b+checklo) < b)
        {
            if (++checkhi == 0)
                checklo++;
        }
    }
    else
    {
        if ((checkhi = b+checkhi) < b)
        {
            if (++checklo == 0)
                checkhi++;
        }
    }
    checkflag = !checkflag;
}

Open in new window

Avatar of Infinity08
Infinity08
Flag of Belgium image

It calculates a 16bit checksum.

This function is called for every byte of the input data. The resulting checksum will be in the chackhi and checklo BYTEs. The checkflag is just used to alternate between the checkhi and checklo BYTEs.
Avatar of Kyle Abrahams, PMP

ASKER

Still not seeing how this is working:

The code passes in IP's (LWORD) for the b parameter.

I get the checkflag is alternating between low and high but assuming checklo is 0.

checklo = b+ checklo < b will always evaluate to false.

It's been a while since I've been this low (mainly .Net now). . . what's an LWORD and how is it cast to a byte again?

ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.