- Implement UDP checksum calculation
[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 ULONG
26 UDPv4ChecksumCalculate(
27 PIPv4_HEADER IPHeader,
28 PUCHAR PacketBuffer,
29 ULONG DataLength);
30
31 #define IPv4Checksum(Data, Count, Seed)(~ChecksumFold(ChecksumCompute(Data, Count, Seed)))
32 #define TCPv4Checksum(Data, Count, Seed)(~ChecksumFold(csum_partial(Data, Count, Seed)))
33 //#define TCPv4Checksum(Data, Count, Seed)(~ChecksumFold(ChecksumCompute(Data, Count, Seed)))
34
35 /*
36 * Macro to check for a correct checksum
37 * BOOLEAN IPv4CorrectChecksum(PVOID Data, UINT Count)
38 */
39 #define IPv4CorrectChecksum(Data, Count) \
40 (BOOLEAN)(IPv4Checksum(Data, Count, 0) == DH2N(0x0000FFFF))
41
42 /*
43 * Macro to check for a correct checksum
44 * BOOLEAN TCPv4CorrectChecksum(PTCPv4_PSEUDO_HEADER TcpPseudoHeader,
45 * PVOID Data, UINT Count)
46 */
47 #define TCPv4CorrectChecksum(TcpPseudoHeader, Data, Count) \
48 (BOOLEAN)(TCPv4Checksum(Data, Count, \
49 TCPv4Checksum(TcpPseudoHeader, sizeof(TCPv4_PSEUDO_HEADER), \
50 0)) == DH2N(0x0000FFFF))
51
52 #endif /* __CHECKSUM_H */