Hi all,

I need to re-caculate the UDP checksum in the recieved packet due to my
modification in the packet context. Has NDIS already provided convenient
utility to caculate the checksum? Or I should follow the procedure from the
presudo header as instructed in "TCP/IP Illustrated" ?

Many Thanks!

RE: How to caculate the UDP checksum in NDIS? by LiangChen

LiangChen
Tue Jul 05 22:22:04 CDT 2005

Or can I set the checksum to 0 and hand up to the upper layer directly, so
that the upper layer in Windows does not verify the checksum becasue it
assumes that the sender does not caculate the checksum?

Regards,

Liang

"Liang Chen" wrote:

> Hi all,
>
> I need to re-caculate the UDP checksum in the recieved packet due to my
> modification in the packet context. Has NDIS already provided convenient
> utility to caculate the checksum? Or I should follow the procedure from the
> presudo header as instructed in "TCP/IP Illustrated" ?
>
> Many Thanks!

Re: How to caculate the UDP checksum in NDIS? by Calvin

Calvin
Tue Jul 05 22:22:10 CDT 2005

AFAIK, ndis doesn't have helper function to calculate csum. You need to do
it yourself.

--
Calvin Guan Windows DDK MVP
Staff SW Engineer, NetXtreme MINIPORT
Enterprise Network Controller Engineering
Broadcom Corporation www.broadcom.com


"Liang Chen" <LiangChen@discussions.microsoft.com> wrote in message
news:521D3128-6C20-4F29-818A-8D30479BDC27@microsoft.com...
> Hi all,
>
> I need to re-caculate the UDP checksum in the recieved packet due to my
> modification in the packet context. Has NDIS already provided convenient
> utility to caculate the checksum? Or I should follow the procedure from
> the
> presudo header as instructed in "TCP/IP Illustrated" ?
>
> Many Thanks!



Re: How to caculate the UDP checksum in NDIS? by Arkady

Arkady
Wed Jul 06 02:02:40 CDT 2005

You can take it from ping example of PSDK :
C:\Program Files\Microsoft Platform SDK\Samples\NetDS\WinSock\Ping
Pay attention that new example show calculation wrappers for both IPv4 or
IPv6 too
Arkady

"Calvin Guan" <hguan@nospam.broadcom.com> wrote in message
news:%23cyMpndgFHA.3296@TK2MSFTNGP10.phx.gbl...
> AFAIK, ndis doesn't have helper function to calculate csum. You need to do
> it yourself.
>
> --
> Calvin Guan Windows DDK MVP
> Staff SW Engineer, NetXtreme MINIPORT
> Enterprise Network Controller Engineering
> Broadcom Corporation www.broadcom.com
>
>
> "Liang Chen" <LiangChen@discussions.microsoft.com> wrote in message
> news:521D3128-6C20-4F29-818A-8D30479BDC27@microsoft.com...
>> Hi all,
>>
>> I need to re-caculate the UDP checksum in the recieved packet due to my
>> modification in the packet context. Has NDIS already provided convenient
>> utility to caculate the checksum? Or I should follow the procedure from
>> the
>> presudo header as instructed in "TCP/IP Illustrated" ?
>>
>> Many Thanks!
>
>



Re: How to caculate the UDP checksum in NDIS? by fat_boy

fat_boy
Wed Jul 06 03:20:29 CDT 2005

Hi,

this should do it:

PUSHORT buf = the buffer;
USHORT iUdpChecksumSize = sizeof(PSEUDO_IP) +
ShortEndianSwap(pDHCPpacket->udp.length);
ULONG summer=0;
if(iUdpChecksumSize % 2)
{
iUdpChecksumSize++;
}

for(i = 0 ; i < iUdpChecksumSize/2 ; i++)
{
summer = summer + ShortEndianSwap(buf[i]);
}

summer = (summer >> 16) + (summer & 0xFFFF);

summer += (summer >> 16);

summer = ~summer;

pDHCPpacket->udp.checkSum = ShortEndianSwap((USHORT)summer);

Endian swapping is as you would expect.

Have a look at RFC 1071, from itef.org for more info.

ATB


Re: How to caculate the UDP checksum in NDIS? by LiangChen

LiangChen
Wed Jul 06 06:20:02 CDT 2005

Thanks.

I got it. The NDIS accept the UDP packet with zero checksum. So I can
avoid the tricky checksum caculation.

"fat_boy" wrote:

> Hi,
>
> this should do it:
>
> PUSHORT buf = the buffer;
> USHORT iUdpChecksumSize = sizeof(PSEUDO_IP) +
> ShortEndianSwap(pDHCPpacket->udp.length);
> ULONG summer=0;
> if(iUdpChecksumSize % 2)
> {
> iUdpChecksumSize++;
> }
>
> for(i = 0 ; i < iUdpChecksumSize/2 ; i++)
> {
> summer = summer + ShortEndianSwap(buf[i]);
> }
>
> summer = (summer >> 16) + (summer & 0xFFFF);
>
> summer += (summer >> 16);
>
> summer = ~summer;
>
> pDHCPpacket->udp.checkSum = ShortEndianSwap((USHORT)summer);
>
> Endian swapping is as you would expect.
>
> Have a look at RFC 1071, from itef.org for more info.
>
> ATB
>
>

Re: How to caculate the UDP checksum in NDIS? by fat_boy

fat_boy
Wed Jul 06 06:57:36 CDT 2005

NDIS is just the facilitator in moving packets between NICs and
protocols. NDIS couldnt care less what the data in the packet is.

But I'll bet TCPIP.sys does. If it receives a bad packet I bet it will
discard it.


Re: How to caculate the UDP checksum in NDIS? by LiangChen

LiangChen
Wed Jul 06 07:46:04 CDT 2005

Acctually, I get the modified packet from socket in user mode. I bet the
TCPIP.sys also admit the setting of zero checksum.

"fat_boy" wrote:

> NDIS is just the facilitator in moving packets between NICs and
> protocols. NDIS couldnt care less what the data in the packet is.
>
> But I'll bet TCPIP.sys does. If it receives a bad packet I bet it will
> discard it.
>
>

Re: How to caculate the UDP checksum in NDIS? by Maxim

Maxim
Wed Jul 06 15:07:45 CDT 2005

For UDP, TCPIP can IIRC skip checksum check at all, this is governed by the
socket option set by the app.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com

"fat_boy" <m.sykes@option.com> wrote in message
news:1120651055.976720.256540@g49g2000cwa.googlegroups.com...
> NDIS is just the facilitator in moving packets between NICs and
> protocols. NDIS couldnt care less what the data in the packet is.
>
> But I'll bet TCPIP.sys does. If it receives a bad packet I bet it will
> discard it.
>