Witam, ma moze ktos z was funkcje pod delphi do liczenia checksumy naglowka ip ?

pozdrawiam

Znalazlem w necie taka funkcje tylko ze w C

================================================

u16 ip_sum_calc(u16 len_ip_header, u16 buff[])
{
u16 word16;
u32 sum=0;
u16 i;

// make 16 bit words out of every two adjacent 8 bit words in the packet
// and add them up
for (i=0;i<len_ip_header;i=i+2){
	word16 =((buff[i]<<8)&0xFF00)+(buff[i+1]&0xFF);
	sum = sum + (u32) word16;	
}

// take only 16 bits out of the 32 bit sum and add up the carries
while (sum>>16)
  sum = (sum & 0xFFFF)+(sum >> 16);

// one's complement the result
sum = ~sum;

return ((u16) sum);
}

================================================

ort! ja przelozyc na DELPHI, jest to zupelna amatorka wiec na pewno sie pomyilem, poprawcie mnie prosze.. szczegolnie nie rozumiem tego sum = ~sum;
(ominolem to :) ) oraz "while (sum>>16)" to nie jest wartosc Boolean wiec delphi tego tak nie lyknie

Oto moja nieudolna <ort>pruba..</ort> tylko sie nie smiejcie PLZ bo sie <ort>w ogóle</ort> na tym nie znam

=====================================================

function tmainform.suma(var buffer:string; size:integer):word;
var w:word;
sum:longword;
i:integer;
begin
sum:=0;
for i:=1 to 10 do begin
w:=((byte(buffer[i2-1]) shl 8)and $00FF)+(byte(buffer[i2])and $FF);
showmessage(inttostr(integer(w)));
sum:=sum+longword(w);
end;

while (sum shr 16)<>0 do
sum:= (sum and $FFFF) + (sum shl 16);

result:=word(sum);
end;

=================================================
W kodzie C jest petla ze od o do ip_header_len ale naglowek ma 20 bajtow wiec wrzucilem to na sztywno (od 1 to 10) i analizuje po 2 bajty ;

POMOCY :)