Re: Dangerous UDP Checksum code ?!?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Skybuck Flying

    Re: Dangerous UDP Checksum code ?!?

    Well anyway...

    I think the idea can still work.

    Assuming the maximum value for each word is: 65535.

    And assuming a packet is maximum of 65535 words then multiple these two
    should give the number of carries in the high word
    correctly... so no overflows will occur... I checked that yesterday ! ;)

    So to be on the safe side the code could be altered a little bit like so:

    Carries := Sum shr 16;
    Sum := Sum and $FFFF;
    while Carries 0 do
    begin
    Sum := Sum + Carries;
    Carries := Sum shr 16;
    Sum := Sum and $FFFF;
    end;

    Or alternatively (probably shorter, less intuitive though):

    Carries := 0;
    repeat
    Sum := Sum + Carries;
    Carries := Sum shr 16;
    Sum := Sum and $FFFF;
    until Carries = 0;

    Bye,
    Skybuck.


  • Skybuck Flying

    #2
    Re: Dangerous UDP Checksum code ?!?

    Actually the maximum number of words in a packet is probably more close to
    65535 div 2...

    So that's about 32767 carries or so...in the maximum case...

    So 32 bits more than enough to catch any possible carries ;)

    Bye,
    Skybuck.


    Comment

    Working...