2157c50f797334d895629cae983755d40480f672
[reactos.git] / reactos / drivers / network / tcpip / include / checksum.h
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 #ifndef __CHECKSUM_H
8 #define __CHECKSUM_H
9
10
11 ULONG ChecksumFold(
12 ULONG Sum);
13
14 ULONG ChecksumCompute(
15 PVOID Data,
16 UINT Count,
17 ULONG Seed);
18
19 unsigned int
20 csum_partial(
21 const unsigned char * buff,
22 int len,
23 unsigned int sum);
24
25 #define IPv4Checksum(Data, Count, Seed)(~ChecksumFold(ChecksumCompute(Data, Count, Seed)))
26 #define TCPv4Checksum(Data, Count, Seed)(~ChecksumFold(csum_partial(Data, Count, Seed)))
27 //#define TCPv4Checksum(Data, Count, Seed)(~ChecksumFold(ChecksumCompute(Data, Count, Seed)))
28
29 /*
30 * Macro to check for a correct checksum
31 * BOOLEAN IPv4CorrectChecksum(PVOID Data, UINT Count)
32 */
33 #define IPv4CorrectChecksum(Data, Count) \
34 (BOOLEAN)(IPv4Checksum(Data, Count, 0) == DH2N(0x0000FFFF))
35
36 /*
37 * Macro to check for a correct checksum
38 * BOOLEAN TCPv4CorrectChecksum(PTCPv4_PSEUDO_HEADER TcpPseudoHeader,
39 * PVOID Data, UINT Count)
40 */
41 #define TCPv4CorrectChecksum(TcpPseudoHeader, Data, Count) \
42 (BOOLEAN)(TCPv4Checksum(Data, Count, \
43 TCPv4Checksum(TcpPseudoHeader, sizeof(TCPv4_PSEUDO_HEADER), \
44 0)) == DH2N(0x0000FFFF))
45
46 #endif /* __CHECKSUM_H */