Proper way to receive packets in MAC RAW on W5100 w/ Arduino?

A project I’m currently working on requires that I use MAC RAW instead of TCP, and I’m noticing that if multiple packets have been received since the last query, it gives it to you all in one large chunk, combining the packets.

I am assuming the proper way to do this is to start by just reading 2 bytes from the buffer, which would give you the size of the first waiting packet, then read the length specified there, next pull the actual packet from the buffer based on that size, and repeat for remaining packets. Is this accurate? There’s not much detail about MAC RAW in the documentation for the W5100.

Does something like this look correct? I would expect it to, but it seems to screw up the receive buffer somehow. It’ll start acting like the buffer isn’t emptying at all.

[code] while (W5100.getRXReceivedSize(s)) {
W5100.recv_data_processing(s, rbuf, 2); //get MAC RAW header, giving us the size of the next waiting packet
W5100.execCmdSn(s, Sock_RECV);
rbuflen = rbuf[1] | ((uint16_t)rbuf[0] << 8); //seems to be big-endian

W5100.recv_data_processing(s, rbuf, rbuflen); //get the actual packet
W5100.execCmdSn(s, Sock_RECV);

process_packet(rbuf, rbuflen); //go do something with it...


Thanks for any help you can offer!

Is correct.
From DHCP/DNS examples Socket.c source file, recvfrom function :

    ptr = IINCHIP_READ(Sn_RX_RD0(s));
    ptr = ((ptr & 0x00ff) << 8) + IINCHIP_READ(Sn_RX_RD0(s) + 1);
    switch (IINCHIP_READ(Sn_MR(s)) & 0x07)
    case Sn_MR_MACRAW :
        data_len = head[0];
        data_len = (data_len<<8) + head[1] - 2;

        read_data(s,(uint8*) ptr,buf,data_len);
        ptr += data_len;
        IINCHIP_WRITE(Sn_RX_RD0(s),(uint8)((ptr & 0xff00) >> 8));
        IINCHIP_WRITE((Sn_RX_RD0(s) + 1),(uint8)(ptr & 0x00ff));
    while( IINCHIP_READ(Sn_CR(s)) )