Quality RTOS & Embedded Software

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




Loading

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:

#define ipconfigETHERNET_DRIVER_FILTERS_PACKETS   	1

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( "255.255.255.255" );

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

/* 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 192.168.1.255 ).

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 224.0.0.252.

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

Regards.


UDP broadcast

Posted by alainm3 on October 31, 2017

Thanks guys for such a good explanation :) :)


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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