1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS TCP/IP protocol driver
4  * FILE:        include/checksum.h
5  * PURPOSE:     Checksum routine definitions
6  */
7 
8 #pragma once
9 
10 ULONG ChecksumFold(
11   ULONG Sum);
12 
13 ULONG ChecksumCompute(
14     PVOID Data,
15     UINT Count,
16     ULONG Seed);
17 
18 unsigned int
19 csum_partial(
20   const unsigned char * buff,
21   int len,
22   unsigned int sum);
23 
24 ULONG
25 UDPv4ChecksumCalculate(
26   PIPv4_HEADER IPHeader,
27   PUCHAR PacketBuffer,
28   ULONG DataLength);
29 
30 #define IPv4Checksum(Data, Count, Seed)(~ChecksumFold(ChecksumCompute(Data, Count, Seed)))
31 #define TCPv4Checksum(Data, Count, Seed)(~ChecksumFold(csum_partial(Data, Count, Seed)))
32 //#define TCPv4Checksum(Data, Count, Seed)(~ChecksumFold(ChecksumCompute(Data, Count, Seed)))
33 
34 /*
35  * Macro to check for a correct checksum
36  * BOOLEAN IPv4CorrectChecksum(PVOID Data, UINT Count)
37  */
38 #define IPv4CorrectChecksum(Data, Count) \
39     (BOOLEAN)(IPv4Checksum(Data, Count, 0) == DH2N(0x0000FFFF))
40 
41 /*
42  * Macro to check for a correct checksum
43  * BOOLEAN TCPv4CorrectChecksum(PTCPv4_PSEUDO_HEADER TcpPseudoHeader,
44  *   PVOID Data, UINT Count)
45  */
46 #define TCPv4CorrectChecksum(TcpPseudoHeader, Data, Count) \
47     (BOOLEAN)(TCPv4Checksum(Data, Count, \
48       TCPv4Checksum(TcpPseudoHeader, sizeof(TCPv4_PSEUDO_HEADER), \
49       0)) == DH2N(0x0000FFFF))
50