Ungetested (aber im Prinzip ok
):
Delphi-Quellcode:
function InternetChecksum(PData: PWord; Count: Integer):integer;
begin
result := 0;
while Count > 1
do
begin
result := result + PData^;
Inc(PData);
Dec(Count, 2);
end;
// Add left-over byte, if any
if Count > 0
then
Result := Result + PByte(PData)^;
// Fold 32-bit sum to 16 bits
while (Result
and $FFFF000) <> 0
do
Result := (Result
and $FFFF) + (Result
shr 16);
Result :=
not Result;
end;
procedure CheckSumIcmpHeader(
var hdr:TIcmpHeader);
begin
hdr.usCheckSum := 0;
// nicht wegoptimieren !!!
hdr.usCheckSum := InternetCheckSum(PWord(@hdr), sizeof(TIcmpHeader));
end;