Hello,
I am using FreeRTOS v11.1.0 kernel and FreeRTOS+TCP v4.2.2 (both from the FreeRTOSv202406.01-LTS package) and I am trying to get sockets on multiple endpoints to work.
This is how I initialize the two endpoints that should be set to different IP adresses:
// Add the interface
pxZynq_FillInterfaceDescriptor(XPAR_PS7_ETHERNET_0_DEVICE_ID, &networkInterface);
//Add the endpoint for the client address
FreeRTOS_FillEndPoint( &(networkInterface),
&(ipEndpoints[IP_ENDPOINT_CLIENT_ACCESS]),
ipConfig.ipAdr4,
ipConfig.ipSubNetMask4,
ipConfig.ipStdGateway4,
ucDNSServerAddress,
ucMACAddress );
//Add the endpoint for the default IP address
FreeRTOS_FillEndPoint( &(networkInterface),
&(ipEndpoints[IP_ENDPOINT_PRIVATE_ACCESS]),
privateIPAddress,
privateNetMask,
privateGatewayAddress,
ucDNSServerAddress,
ucMACAddress );
When setting up a TCP socket, how do I select which endpoint it should use to bind to?
I cannot find any official documentation on how to do that, specifically mentioning the new concept of multiple endpoints.
Any links to such documentation or some hints on how to do this would be greatly appreciated.
Sockets cannot be bound to endpoints in FreeRTOS+TCP.
While using a socket, for example, sending a UDP packet, the right endpoint is chosen during the ARP lookup. The FreeRTOS_FindEndPointOnNetMask [eARPGetCacheEntryGateWay] is used to find which endpoint has the same network mask as the given IP-address and that endpoint is used.
Okay, I am fine with FreeRTOS choosing the correct endpoint automatically, but how do I select the IP adress to use?
Is this done through the bind address parameter like for the port?
This example from here sets the IP address field to all zeros. Should the desired IP be set here?
/* Set the listening port to 10000. */
memset( &xBindAddress, 0, sizeof(xBindAddress) );
xBindAddress.sin_port = ( uint16_t ) 10000;
xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port );
xBindAddress.sin_family = FREERTOS_AF_INET4;
/* Bind the socket to the port that the client RTOS task will send to. */
FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
During the bind operation, if you have specified the IP address [xBindAddress.sin_address] to be the address of an endpoint, the socket’s pxEndPoint field will be set to that endpoint (using FreeRTOS_FindEndPointOnIP_IPv4).
Which, if not NULL, will be used to send packets; if it’s NULL, it uses ARP or other methods.
Okay thanks. It’s strange, I keep getting error -22 when trying to bind to the IP address of a specific endpoint that I want to use. I need to look into that.
Please be a little bit more careful about your usage of the term “end point.” An end point is not an IP address, but a combination of an IP address and a port (any machine that supports IP netwotking may and often will listen on several ports at any time, so a client must establish a connection to a specific port on the target device).