Ndis calculation of tcp checksum

Discussion in 'Windows Vista Drivers' started by fkhg1, Jul 30, 2008.

  1. fkhg1

    fkhg1 Guest

    Hi,
    i have a problem to calculate tcp checksums over XXX byte
    with 260 byte its no problem, but the following packet that i send has 386
    byte and wireshark and other tools report that the checksum is incorrect
    does somebody have an idea what iam doing wrong with the checksum
    calculation?

    thanks for any ideas or some help


    code:
    ------------------------------------------------------------------------
    USHORT TcpCheckSumCalcC(PIPHeader buffer) {
    unsigned short size, sizetemp;
    unsigned char * pSize;
    unsigned char tempchar;
    unsigned long cksum = 0;
    unsigned short * TempAddr;
    unsigned short * TempAddr1;
    int i = 0;
    unsigned short uIpLen;

    TempAddr = (unsigned short *)(&(buffer->ipSource));
    for(i=0;i<4;i++) {
    cksum += *TempAddr;
    TempAddr++;
    }
    cksum += 0x0600;
    uIpLen = (buffer->ipLength >> 8) + ((buffer->ipLength & 0xff00) << 8);
    size = uIpLen - (buffer->iphVerLen&0x0f)*4;
    sizetemp = size ;
    pSize = (unsigned char *)(&sizetemp);
    tempchar = pSize[0];
    pSize[0] = pSize[1];
    pSize[1] = tempchar;
    cksum += sizetemp;
    *(TempAddr + 8) = 0;

    TempAddr1 = TempAddr;
    while (size > 1) {
    cksum = cksum + *TempAddr ;
    TempAddr = TempAddr + 1;
    size = size - sizeof(unsigned short);
    }
    if (size)
    cksum += *(unsigned char*)TempAddr;
    cksum = (cksum >> 16) + (cksum & 0xffff);
    cksum += (cksum >>16);
    return (unsigned short)(~cksum);
    }
     
    fkhg1, Jul 30, 2008
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.