Error: 'struct freertos_sockaddr' has no member named 'sin_address'; did you mean 'sin_addr'?

Hello!

I’m trying to create a very basic UDP client based on the example in Git FreeRTOS/FreeRTOS/tree/main/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2 (I tried to put a link here but the forum software “doesn’t allow new users to post links”) and this code snippet freertos . org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Networking_Tutorial_Sending_UDP_Data.html (again sorry for the broken link)

I have code like this:

#include "FreeRTOS_IP.h"
#include "FreeRTOS_sockets.h"

/* skipped some boilerplate code here*/

static void vUDPSendUsingStandardInterface(void *pvParameters)
{
    Socket_t xSocket;
    struct freertos_sockaddr xDestinationAddress;
    uint8_t cString[50];
    uint32_t ulCount = 0UL;
    const TickType_t x1000ms = 1000UL / portTICK_PERIOD_MS;

    /* Send strings to port 10000 on IP address 192.168.0.50. */
    xDestinationAddress.sin_address = FreeRTOS_inet_addr("192.168.0.50");
    xDestinationAddress.sin_port = FreeRTOS_htons(10000);

    /* Create the socket. */
    xSocket = FreeRTOS_socket(FREERTOS_AF_INET4,   /* Used for IPv4 UDP socket. */
                                                   /* FREERTOS_AF_INET6 can be used for IPv6 UDP socket. */
                              FREERTOS_SOCK_DGRAM, /*FREERTOS_SOCK_DGRAM for UDP.*/
                              FREERTOS_IPPROTO_UDP);
...

But when I try to compile this I get the following error:

sin_addr doesn’t seem to exist either. I’ve attached the Makefile I’m using for reference as well. Any idea what might be the cause of this?

Thanks!

CC = arm-none-eabi-gcc
BIN := freertos_tcp_mps2_demo.axf

BUILD_DIR := build

FREERTOS_DIR_REL := FreeRTOS/FreeRTOS
FREERTOS_DIR := $(abspath $(FREERTOS_DIR_REL))
KERNEL_DIR := $(FREERTOS_DIR)/Source

FREERTOS_PLUS_DIR_REL := FreeRTOS/FreeRTOS-Plus
FREERTOS_PLUS_DIR := $(abspath $(FREERTOS_PLUS_DIR_REL))

INCLUDE_DIRS += -I.

FREERTOS_TCP = ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP

# Demo Source Files
SOURCE_FILES += startup.c
SOURCE_FILES += syscalls.c
SOURCE_FILES += main.c
SOURCE_FILES += main_networking.c
SOURCE_FILES += TCPEchoClient_SingleTasks.c
SOURCE_FILES += UDPEchoClientDemo.c

INCLUDE_DIRS += -ICMSIS

# FreeRTOS Kernel
INCLUDE_DIRS += -I$(KERNEL_DIR)/include

SOURCE_FILES += $(KERNEL_DIR)/tasks.c
SOURCE_FILES += $(KERNEL_DIR)/list.c
SOURCE_FILES += $(KERNEL_DIR)/queue.c
SOURCE_FILES += $(KERNEL_DIR)/timers.c
SOURCE_FILES += $(KERNEL_DIR)/event_groups.c

# FreeRTOS Kernel ARM Cortex-M3 Port
INCLUDE_DIRS += -I$(KERNEL_DIR)/portable/GCC/ARM_CM3

SOURCE_FILES += $(KERNEL_DIR)/portable/GCC/ARM_CM3/port.c
SOURCE_FILES += ${KERNEL_DIR}/portable/MemMang/heap_3.c

# FreeRTOS+TCP
INCLUDE_DIRS += -I${FREERTOS_TCP}/source/include/

SOURCE_FILES += $(wildcard ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/source/*.c )

# FreeRTOS+TCP Port for ARM MPS2 SoC
INCLUDE_DIRS += -I${FREERTOS_TCP}/source/portable/NetworkInterface/MPS2_AN385/ether_lan9118
INCLUDE_DIRS += -I${FREERTOS_TCP}/source/portable/Compiler/GCC

SOURCE_FILES += ${FREERTOS_TCP}/source/portable/BufferManagement/BufferAllocation_2.c
SOURCE_FILES += ${FREERTOS_TCP}/source/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c
SOURCE_FILES += ${FREERTOS_TCP}/source/portable/NetworkInterface/MPS2_AN385/ether_lan9118/smsc9220_eth_drv.c

DEFINES := -DQEMU_SOC_MPS2 -DHEAP3

LDFLAGS = -T mps2_m3.ld -specs=nano.specs --specs=rdimon.specs -lc -lrdimon
LDFLAGS += -Xlinker -Map=${BUILD_DIR}/output.map

CFLAGS += -nostartfiles -mthumb -mcpu=cortex-m3 -Wno-error=implicit-function-declaration
CFLAGS += -Wno-builtin-declaration-mismatch -Werror

ifeq ($(DEBUG), 1)
    CFLAGS += -ggdb3 -Og
else
    CFLAGS += -O3
endif
    CFLAGS += -fstrict-aliasing -Wstrict-aliasing -Wno-error=address-of-packed-member

OBJ_FILES := $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.o)

CPPFLAGS += $(DEFINES)
CFLAGS += $(INCLUDE_DIRS)

.PHONY: clean

$(BUILD_DIR)/$(BIN) : $(OBJ_FILES)
	$(CC) -ffunction-sections -fdata-sections $(CFLAGS) $(LDFLAGS) $+ -o $(@)

%.d: %.c
	@set -e; rm -f $@; \
	$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

INCLUDES := $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.d)
-include $(INCLUDES)

${BUILD_DIR}/%.o : %.c Makefile
	-mkdir -p $(@D)
	$(CC)  $(CPPFLAGS) $(CFLAGS) -MMD -c $< -o $@

clean:
	-rm -rf build

Hi @vilhelm,

Welcome to the FreeRTOS community!

Upon an initial review of your code, it appears to be well-structured. However, I have a minor concern regarding the include paths specified in your Makefile.

When comparing your Makefile with the FreeRTOS_Plus_TCP_Echo_Qemu_mps2 example, I noticed that the paths for FREERTOS_DIR_REL and FREERTOS_PLUS_DIR_REL seem to be different. Could you double-check if the include paths in your Makefile are correct? And sharing your complete project would be helpful for further analysis.

In FreeRTOS_Plus_TCP_Echo_Qemu_mps2:

FREERTOS_DIR_REL := ../../../FreeRTOS
FREERTOS_PLUS_DIR_REL := ../../../FreeRTOS-Plus

In your Makefile:

FREERTOS_DIR_REL := FreeRTOS/FreeRTOS
FREERTOS_PLUS_DIR_REL := FreeRTOS/FreeRTOS-Plus

Thank you for your understanding and cooperation.

Great observation! In the project, all source code is in a directory named src. In this directory, I have all the .c and .h files for the project and the Makefile. I also have the whole FreeRTOS project as a submodule inside this src directory, meaning the paths relative to the Makefile should be okay.

# git submodule config
$ cat .gitmodules
[submodule "src/FreeRTOS"]
	path = src/FreeRTOS
	url = https://github.com/FreeRTOS/FreeRTOS.git
# what I run to get all submodules
$ git submodule update --init --recursive

I’ve would gladly submit the whole source code but I’m not able to upload any files, the forum says “Sorry, new users can not upload attachments.”.

Thanks for the help!

You should be able to upload files now.

HI @vilhelm

Can you also let us know which version of FreeRTOS are you using?
sin_addr was updated to sin_address, so the FreeRTOS version will help us check if demos and FreeRTOS-Plus-TCP are following the same format.

@moninom1: It’s the this version of the source code: GitHub - FreeRTOS/FreeRTOS at 5fc7a750a0d603c1c68d554226d91d44ba922173

I’ve attached the project as .zip. Please note that src/FreeRTOS will be empty since the git stuff isn’t included in the .zip.

source-code.zip (81.1 KB)

Hi @vilhelm,
Thanks for uploading project!

After reviewing the details, it appears that the include file name is incorrect, which is causing an issue with properly including the API. To resolve this, we kindly request your assistance in applying the following changes:

diff --git a/src/UDPEchoClientDemo.c b/src/UDPEchoClientDemo.c
index 2fc4b1a..d474486 100644
--- a/src/UDPEchoClientDemo.c
+++ b/src/UDPEchoClientDemo.c
@@ -1,5 +1,5 @@
 #include "FreeRTOS_IP.h"
-#include "FreeRTOS_sockets.h"
+#include "FreeRTOS_Sockets.h"
 
 static void vUDPSendUsingStandardInterface(void *pvParameters);
 
@@ -27,7 +27,7 @@ static void vUDPSendUsingStandardInterface(void *pvParameters)
     const TickType_t x1000ms = 1000UL / portTICK_PERIOD_MS;
 
     /* Send strings to port 10000 on IP address 192.168.0.50. */
-    xDestinationAddress.sin_address = FreeRTOS_inet_addr("192.168.0.50");
+    xDestinationAddress.sin_address.ulIP_IPv4 = FreeRTOS_inet_addr("192.168.0.50");
     xDestinationAddress.sin_port = FreeRTOS_htons(10000);
 
     /* Create the socket. */
diff --git a/src/main_networking.c b/src/main_networking.c
index 5c52905..9c322ff 100644
--- a/src/main_networking.c
+++ b/src/main_networking.c
@@ -232,8 +232,8 @@ void vApplicationIPNetworkEventHook(eIPCallbackEvent_t eNetworkEvent)
 
 #if (mainCREATE_TCP_ECHO_TASKS_SINGLE == 1)
             {
-                vStartTCPEchoClientTasks_SingleTasks(mainECHO_CLIENT_TASK_STACK_SIZE,
-                                                     mainECHO_CLIENT_TASK_PRIORITY);
+                // vStartTCPEchoClientTasks_SingleTasks(mainECHO_CLIENT_TASK_STACK_SIZE,
+                //                                      mainECHO_CLIENT_TASK_PRIORITY);
                 vStartUDPEchoClientTasks_SingleTasks(mainECHO_CLIENT_TASK_STACK_SIZE,
                                                      mainECHO_CLIENT_TASK_PRIORITY);
             }

Thank you.

1 Like

Sorry for the delay. Thank you very much @ActoryOu! It seems to compile now :slight_smile:

Now I get this error repeated over and over:

0x20015c18->FreeRTOS_sendto 1625: FreeRTOS_sendto: Undefined sin_family 

does FreeRTOS_sendto work with the xDestinationAddress I’ve set-up?

Hi @vilhelm,
Could you try set sin_family in xDestinationAddress before calling FreeRTOS_sendto()?

Like this:

xDestinationAddress.sin_family = FREERTOS_AF_INET4; //or FREERTOS_AF_INET6 if the destination's IP is IPv6.
xDestinationAddress.sin_address.ulIP_IPv4 = FreeRTOS_inet_addr("192.168.0.50");
xDestinationAddress.sin_port = FreeRTOS_htons(10000);

Thank you.

1 Like

Currently, FreeRTOS+TCP ignores the value of sin_len. Other OS’s might check it, so it’s a good habit to set it anyway.

memset( &xAddress, 0, sizeof( xAddress ) );
xAddress.sin_family = FREERTOS_AF_INET4;
xAddress.sin_address.ulIP_IPv4 = FreeRTOS_inet_addr("192.168.0.50");
xAddress.sin_port = FreeRTOS_htons(10000U);
xAddress.sin_len = ( uint8_t ) sizeof( xAddress );

Or when the target is an IPv6 address:

memset( &xAddress, 0, sizeof( xAddress ) );
xAddress.sin_family = FREERTOS_AF_INET6;
FreeRTOS_inet_pton( FREERTOS_AF_INET6,       /* xAddressFamily */
                    "2600:70ff:c066::2001",  /* pcSource */
                    xAddress.sin_address.xIP_IPv6.ucBytes ); /* pucTarget */
xAddress.sin_port = FreeRTOS_htons(10000U);
xAddress.sin_len = ( uint8_t ) sizeof( xAddress );
2 Likes

Thank you @ActoryOu and @htibosch for the suggestioned.

I changed it to this:

    memset( &xDestinationAddress, 0, sizeof( xDestinationAddress ) );
    xDestinationAddress.sin_family = FREERTOS_AF_INET4; //or FREERTOS_AF_INET6 if the destination's IP is IPv6.
    xDestinationAddress.sin_address.ulIP_IPv4 = FreeRTOS_inet_addr("192.168.0.50");
    xDestinationAddress.sin_port = FreeRTOS_htons(10000);
    xDestinationAddress.sin_len = ( uint8_t ) sizeof( xDestinationAddress );

and now I get various other messages:

0x2000beb8->eARPGetCacheEntryGateWay 1089: ARP c0a80032ip miss using ac150001ip
0x20011d38->FreeRTOS_MatchingEndpoint 987: pxEasyFit: ARP ac150003ip -> ac150001ip
0x2000beb8->eARPProcessPacket 265: ipARP_REPLY from ac150001ip to ac150003ip end-point ac150003ip
0x2000beb8->FreeRTOS_InterfaceEndPointOnNetMask 597: FreeRTOS_FindEndPointOnNetMask[4]: No match for c0a80032ip
0x2000beb8->eARPGetCacheEntryGateWay 1089: ARP c0a80032ip hit using ac150001ip
0x2000beb8->FreeRTOS_InterfaceEndPointOnNetMask 597: FreeRTOS_FindEndPointOnNetMask[4]: No match for c0a80032ip
0x2000beb8->eARPGetCacheEntryGateWay 1089: ARP c0a80032ip hit using ac150001ip

I haven’t configured a dummy server on the destination IP yet, but I believe that it’s not what’s causing the issue currently.

What issue are you facing? Are you not able to reach out to the server you are trying to reach?

As @aggarg mentioned if you are trying to have a client server communication, you can take reference from IPv6 demo , more detail here.
Let us know if you are facing some other issue.

Thanks for the suggestion! Sorry for being unclear last time.

I’ve setup the UDP echo server using FreeRTOS-Libraries-Integration-Tests/tools/echo_server at main · FreeRTOS/FreeRTOS-Libraries-Integration-Tests · GitHub

… but the client seems to just seem to repeat these messages over and over:

0x2000beb8->eARPGetCacheEntryGateWay 1089: ARP c0a80032ip miss using ac150001ip
0x20011d38->FreeRTOS_MatchingEndpoint 987: pxEasyFit: ARP ac150003ip -> ac150001ip
0x2000beb8->eARPProcessPacket 265: ipARP_REPLY from ac150001ip to ac150003ip end-point ac150003ip
0x2000beb8->FreeRTOS_InterfaceEndPointOnNetMask 597: FreeRTOS_FindEndPointOnNetMask[4]: No match for c0a80032ip
0x2000beb8->eARPGetCacheEntryGateWay 1089: ARP c0a80032ip hit using ac150001ip
0x2000beb8->FreeRTOS_InterfaceEndPointOnNetMask 597: FreeRTOS_FindEndPointOnNetMask[4]: No match for c0a80032ip
0x2000beb8->eARPGetCacheEntryGateWay 1089: ARP c0a80032ip hit using ac150001ip

… and the UDP server is not getting any packets. The code I have is a lot more lightweight than the IPv6 demo you mentioned @moninom1, but I believe the code I have should be sufficient to send some packets over UDP?

Hi @vilhelm,

The log above means your device received some ARP packets from network. It looks like somebody is sending something to IP 192.168.0.50 (0xc0a80032). That might not relate to the problem you’re facing directly. Could you help share the network environment you’re using? BTW, could you help check if firewall in your network path blocks the packets?

Thank you.

Sorry for the confusion. As you suggested, it was a firewall issue (not on the client, but on the UDP echo server)!

The network setup is rather complicated (and probably not how you’re supposed to do this for FreeRTOS). I’ve attached a figure summarizing how I compile and run FreeRTOS with my code.

So basically there is a TUN/TAP tunnel between the QEMU Arm Emulator and the Docker container, allowing the QEMU VM to access the network via Docker and via the host OS.

Thanks a lot for the help with everything, really appreciated it!

2 Likes

Thanks for feedback!