Reply To: Modify packet [DELPHI]

Home Forums Discussions Support Portal Modify packet [DELPHI] Reply To: Modify packet [DELPHI]

#5579

PLY
Participant

@ply wrote:

Why i can’y calc TCP checksum? Please help

first, i declare this


TIPHeaderPtr = ^TIPHeader;
TIPHeader = packed record
VerLen: Byte; //HL
TOS: Byte;
TotalLen: Word;
Identifer: Word;
FragOffsets: Word;
TTL: Byte;
Protocol: Byte;
CheckSum: Word;
SourceIp: DWORD;
DestIp: DWORD;
// Options: DWORD;
end;

TTCPHeaderPtr = ^TTCPHeader;
TTCPHeader = packed record
SourcePort:Word;
DestPort:Word;
SequenceNumber:DWord;
AcknowledgementNumber:DWord;
Offset:Byte; //only left 4 bits. Header length in 32-bit segments
Flags:Byte;
Window:Word;
Checksum:Word; //includes speudo header instead of TCP header.
UrgentPointer:Word;
end;

pTCPData: PChar;

after that i get IP header and calc IP check sum is collect but why i can’t calc TCP checksum. the code like below.


pTCPHeader.Checksum := 00;
pTCPHeader.Checksum := htons(Checksum(Pword(pTCPHeader), (sizeof(TTCPHeader)+length(pTCPData)) div 2));

i forgot something? or i should not use PChar for get the TCP data?