Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


UDP broadcast

Posted by alainm3 on October 30, 2017

Hi, a colleague is using FreeRTOS+TCP... He is abandoning it saying that it is not possible to make an UDP broadcast !!!

Could you please give me a clue of where I can find that specific command?

Thanks, Alain

UDP broadcast

Posted by davedoors on October 30, 2017

FreeRTOS+TCP uses LLMR which uses a UDP broadcast. See how that is implemented.

UDP broadcast

Posted by heinbali01 on October 31, 2017

Indeed, UDP broadcasts can be sent and received using the FreeRTOS+TCP library.

Here is an example of sending a UDP broadcast:

~~~ BaseTypet xSendBroadcast( Sockett xSocket, uint32t ulIPAddress, uint16t usPort, uint8t *pucMessage, sizet uxLength ) { BaseTypet xResult; struct freertossockaddr xAddress;

memest( &xAddress, '\0', sizeof( xAddress ) );
xAddress.sin_addr = FreeRTOS_htonl( ulIPAddress );
xAddress.sin_port = FreeRTOS_htons( usPort );

xResult = FreeRTOS_sendto( xSocket, ( void * )pucMessage, uxLength, 0, &xAddress, sizeof( xAddress ) );

return xResult;

} ~~~

Some remarks about UDP broadcasts:

1) Usually a broadcast won't be routed towards neighbouring networks. I have a LAN here with switches and a router. The router does pass broadcasts to all local (192.168.1.x) segments, but it will not forward them to the Internet. Which is logical.

2) In some companies, the network administrator may also limit the usage of UDP broadcasts, in order to decrease network usage, or in order to increase security. Frequent Broadcast packets can be very disturbing.

The earlier an unsolicited packet can be filtered-out, the less it will disturb. I have seen FreeRTOS+TCP devices in factories that sometime became unreachable because of thousands of unwanted broadcasts. I solved this by setting:


and do the filtering at the earliest possible moment in the driver.

3) When sending a broadcast, the library will use a special MAC address, existing of all one's. The IP-address must be chosen by you. You can choose either of these:

~~~ /* The generic broadcast IP address: */ uint32t ulIPAddress = FreeRTOSinet_addr( "" );

/* A network-specific broadcast IP address, which is preferred: */
uint32_t ulIPAddress = FreeRTOS_inet_addr( "" );
uint32_t ulIPAddress = FreeRTOS_inet_addr( "" );

/* In a generic way: */
uint32_t ulIPAddress = ( ulMyIPAddress & ulNetMask ) |  ~ulNetMask;


4) UDP broadcasts do not traverse the Internet, but normal UDP packets do! Think of the Network Time Protocol (NTP).

5) Beside UDP broadcasts, multi-casting is often used. It is kind of replacing the broadcasting. What is the difference?

A broadcast is unspecified. The packet wants to be spread out to every node in the network. The MAC address is ff:ff:ff:ff:ff:ff and the IP address may indicate the desired network ( as in ).

Multicast packets look very much like broadcast packets, except that they use special MAC- and IP-addresses. Ethernet adapters can use hardware filters to stop multi-cast packets if they like. Multicasting is to be preferred above broadcasting.

Dave wrote: > FreeRTOS+TCP uses LLMR which uses a UDP broadcast. See how that is implemented.

LLMNR is actually a multi-cast protocol. It uses the MAC address 01:00:5e:00:00:fc and the IP address

If anyone would like to use multi-casting with FreeRTOS+TCP, please say so and I will think of making some extensions.


UDP broadcast

Posted by alainm3 on October 31, 2017

Thanks guys for such a good explanation :) :)

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner