Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Thu, 31 Jul 2008 08:21:28 +0200,    group: microsoft.public.platformsdk.networking        back       


ndis tcp checksum calculation   
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);
}
date: Thu, 31 Jul 2008 08:21:28 +0200   author:   fkhg1

Re: ndis tcp checksum calculation   
Check that with standard func from ping example ( from SDK )
Arkady

"fkhg1"  wrote in message 
news:u7q84Wt8IHA.1200@TK2MSFTNGP04.phx.gbl...
> 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);
> }
date: Sat, 16 Aug 2008 13:30:51 +0300   author:   Arkady Frenkel

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us