0

Sending Multicast UDP

When sending a multicast packet, you should use a specific multicast MAC (not from a real host). There is a reserved range of MACs for this purpose: 01-00-5E-00-00-00 with the least 23 bits set to the 23 LSBs of the multicast IP address.

This simple patch should do the trick:

--- Downloads/FreeRTOSv9.0.0/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c       2016-09-19 12:47:35.239661700 +0200
+++ ./FreeRTOS_ARP.c    2016-11-27 18:07:23.884735000 +0100
@@ -412,6 +412,16 @@
                memcpy( pxMACAddress->ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) );
                eReturn = eARPCacheHit;
        }
+       else if( (*pulIPAddress & 0xF0) == 0xE0UL )             /* a class D address beginning with 0b1110 is a multicast */
+       {                                                       /* ATTENTION: IP addresses are already in network byte order! */
+               pxMACAddress->ucBytes[0] = 0x01;
+               pxMACAddress->ucBytes[1] = 0x00;
+               pxMACAddress->ucBytes[2] = 0x5E;
+               pxMACAddress->ucBytes[3] = (*pulIPAddress >> 8) & 0x7F;
+               pxMACAddress->ucBytes[4] = (*pulIPAddress >> 16) & 0xFF;
+               pxMACAddress->ucBytes[5] = (*pulIPAddress >> 24) & 0xFF;
+               eReturn = eARPCacheHit;
+       }
        else if( *ipLOCAL_IP_ADDRESS_POINTER == 0UL )
        {
                /* The IP address has not yet been assigned, so there is nothing that

Remember: This is a quick solution for little endian processors and should probably changed with an #ifdef to also support big endian.

0 comments

Please sign in to leave a comment.