[ENet-discuss] Nasty bug in packet fragmentation receive code

Tibor Klajnscek tibor at zootfly.com
Thu Apr 7 03:23:28 PDT 2005


Hi everyone!

Packet fragmentation seems to be totally broken.
I have the sources from the CVS (updated today).

The following code is broken (in protocol.c):

if ((startCommand -> fragments [fragmentNumber / 32] & (1 << 
(fragmentNumber & 32))) == 0)
    {
       -- startCommand -> fragmentsRemaining;

       startCommand -> fragments [fragmentNumber / 32] |= (1 << 
(fragmentNumber & 32));

       if (fragmentOffset + fragmentLength > startCommand -> packet -> 
dataLength)
         fragmentLength = startCommand -> packet -> dataLength - 
fragmentOffset;

       memcpy (startCommand -> packet -> data + fragmentOffset,
               (enet_uint8 *) command + sizeof (ENetProtocolSendFragment),
               fragmentLength);
    }

This is what works for me:

    int byteoffset = 0;
    int bitoffset = 0;

    // ..... other code

    byteoffset = fragmentNumber / 32;
    bitoffset = fragmentNumber % 32;

    if ((startCommand -> fragments [byteoffset] & (1 << bitoffset)) == 0)
    {
       -- startCommand -> fragmentsRemaining;

       startCommand -> fragments [byteoffset] |= (1 << bitoffset);
     
       if (fragmentOffset + fragmentLength > startCommand -> packet -> 
dataLength)
         fragmentLength = startCommand -> packet -> dataLength - 
fragmentOffset;

       memcpy (startCommand -> packet -> data + fragmentOffset,
               (enet_uint8 *) command + sizeof (ENetProtocolSendFragment),
               fragmentLength);
    }

Please reply to this message to let me know if I did something wrong and
if the original code should work.

Best regards,
Tibor


More information about the ENet-discuss mailing list