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?
FreeRTOS+TCP uses LLMR which uses a UDP broadcast. See how that is implemented.
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 )
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 ) );
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( "220.127.116.11" );
/* 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.
> 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.
Thanks guys for such a good explanation :) :)
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.