ReactOS 0.4.16-dev-297-gc569aee
checksum.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define IPv4Checksum(Data, Count, Seed)   (~ChecksumFold(ChecksumCompute(Data, Count, Seed)))
 
#define TCPv4Checksum(Data, Count, Seed)   (~ChecksumFold(csum_partial(Data, Count, Seed)))
 
#define IPv4CorrectChecksum(Data, Count)    (BOOLEAN)(IPv4Checksum(Data, Count, 0) == DH2N(0x0000FFFF))
 
#define TCPv4CorrectChecksum(TcpPseudoHeader, Data, Count)
 

Functions

ULONG ChecksumFold (ULONG Sum)
 
ULONG ChecksumCompute (PVOID Data, UINT Count, ULONG Seed)
 
unsigned int csum_partial (const unsigned char *buff, int len, unsigned int sum)
 
ULONG UDPv4ChecksumCalculate (PIPv4_HEADER IPHeader, PUCHAR PacketBuffer, ULONG DataLength)
 

Macro Definition Documentation

◆ IPv4Checksum

#define IPv4Checksum (   Data,
  Count,
  Seed 
)    (~ChecksumFold(ChecksumCompute(Data, Count, Seed)))

Definition at line 30 of file checksum.h.

◆ IPv4CorrectChecksum

#define IPv4CorrectChecksum (   Data,
  Count 
)     (BOOLEAN)(IPv4Checksum(Data, Count, 0) == DH2N(0x0000FFFF))

Definition at line 38 of file checksum.h.

◆ TCPv4Checksum

#define TCPv4Checksum (   Data,
  Count,
  Seed 
)    (~ChecksumFold(csum_partial(Data, Count, Seed)))

Definition at line 31 of file checksum.h.

◆ TCPv4CorrectChecksum

#define TCPv4CorrectChecksum (   TcpPseudoHeader,
  Data,
  Count 
)
Value:
TCPv4Checksum(TcpPseudoHeader, sizeof(TCPv4_PSEUDO_HEADER), \
0)) == DH2N(0x0000FFFF))
#define DH2N(dw)
Definition: addrconv.c:28
#define TCPv4Checksum(Data, Count, Seed)
Definition: checksum.h:31
int Count
Definition: noreturn.cpp:7
#define BOOLEAN
Definition: pedump.c:73

Definition at line 46 of file checksum.h.

Function Documentation

◆ ChecksumCompute()

ULONG ChecksumCompute ( PVOID  Data,
UINT  Count,
ULONG  Seed 
)

Definition at line 27 of file checksum.c.

40{
41 register ULONG Sum = Seed;
42
43 while (Count > 1)
44 {
45 Sum += *(PUSHORT)Data;
46 Count -= 2;
47 Data = (PVOID)((ULONG_PTR) Data + 2);
48 }
49
50 /* Add left-over byte, if any */
51 if (Count > 0)
52 {
53 Sum += *(PUCHAR)Data;
54 }
55
56 return Sum;
57}
void * PVOID
Definition: typedefs.h:50
uint16_t * PUSHORT
Definition: typedefs.h:56
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59

◆ ChecksumFold()

ULONG ChecksumFold ( ULONG  Sum)

Definition at line 15 of file checksum.c.

17{
18 /* Fold 32-bit sum to 16 bits */
19 while (Sum >> 16)
20 {
21 Sum = (Sum & 0xFFFF) + (Sum >> 16);
22 }
23
24 return Sum;
25}

◆ csum_partial()

unsigned int csum_partial ( const unsigned char buff,
int  len,
unsigned int  sum 
)

◆ UDPv4ChecksumCalculate()

ULONG UDPv4ChecksumCalculate ( PIPv4_HEADER  IPHeader,
PUCHAR  PacketBuffer,
ULONG  DataLength 
)

Definition at line 60 of file checksum.c.

64{
65 ULONG Sum = 0;
66 USHORT TmpSum;
67 ULONG i;
69
70 /* Pad the data if needed */
71 Pad = (DataLength & 1);
72 if (Pad)
73 DataLength++;
74
75 /* Add from the UDP header and data */
76 for (i = 0; i < DataLength; i += 2)
77 {
78 TmpSum = ((PacketBuffer[i] << 8) & 0xFF00) +
79 ((Pad && i == DataLength - 2) ? 0 : (PacketBuffer[i+1] & 0x00FF));
80 Sum += TmpSum;
81 }
82
83 /* Add the source address */
84 for (i = 0; i < sizeof(IPv4_RAW_ADDRESS); i += 2)
85 {
86 TmpSum = ((((PUCHAR)&IPHeader->SrcAddr)[i] << 8) & 0xFF00) +
87 (((PUCHAR)&IPHeader->SrcAddr)[i+1] & 0x00FF);
88 Sum += TmpSum;
89 }
90
91 /* Add the destination address */
92 for (i = 0; i < sizeof(IPv4_RAW_ADDRESS); i += 2)
93 {
94 TmpSum = ((((PUCHAR)&IPHeader->DstAddr)[i] << 8) & 0xFF00) +
95 (((PUCHAR)&IPHeader->DstAddr)[i+1] & 0x00FF);
96 Sum += TmpSum;
97 }
98
99 /* Add the proto number and length */
100 Sum += IPPROTO_UDP + (DataLength - (Pad ? 1 : 0));
101
102 /* Fold the checksum and return the one's complement */
103 return ~ChecksumFold(Sum);
104}
unsigned char BOOLEAN
char * Pad(char *Str, char PadChar, ULONG Length)
Definition: cabman.cxx:29
_In_ ULONG _In_opt_ WDFREQUEST _In_opt_ PVOID _In_ size_t _In_ PVOID _In_ size_t _Out_ size_t * DataLength
Definition: cdrom.h:1444
ULONG IPv4_RAW_ADDRESS
Definition: ip.h:15
#define IPPROTO_UDP
Definition: ip.h:197
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned short USHORT
Definition: pedump.c:61

Referenced by AddUDPHeaderIPv4(), and UDPReceive().