Error in FreeRTOS_SendPingRequest function when I compile project

Hi.

I made a TCP/IP server on my microcontroller based on the following link:

Which works properly.

Now what I need is to determine the IP address of the client that connected and then ping that address.

To obtain the client’s address, I do the following:

apptcpipserverData.xConnectedSocket = FreeRTOS_accept(apptcpipserverData.xListeningSocket, &apptcpipserverData.xClient, &xSize );
configASSERT( apptcpipserverData.xConnectedSocket != FREERTOS_INVALID_SOCKET );

/** clientAddress is struct freertos_sockaddr *clientAddress, and clientAddress->sin_addr will be set to the IP address of the remote connected socket**/
if (-pdFREERTOS_ERRNO_EINVAL != FreeRTOS_GetRemoteAddress(apptcpipserverData.xConnectedSocket, clientAddress ))
{
	apptcpipserverData.state = APPTCPIPSERVER_STATE_RECEIVE_DATA_FROM_CLIENT;
}
else
{
	FreeRTOS_shutdown(apptcpipserverData.xConnectedSocket, FREERTOS_SHUT_RDWR );
	apptcpipserverData.state = APPTCPIPSERVER_STATE_TRY_CLOSE_SCOKET
}

To ping the client I do the following:

usRequestSequenceNumber = FreeRTOS_SendPingRequest( clientAddress.sin_addr, 8, 100 / portTICK_PERIOD_MS );
if( usRequestSequenceNumber == pdFAIL )
{
	/* The ping could not be sent because a network buffer could not be
        obtained within 100ms of FreeRTOS_SendPingRequest() being called. */
}
else
{
	if( xQueueReceive( xPingReplyQueue,&usReplySequenceNumber,200 / portTICK_PERIOD_MS ) == pdPASS )
	{
		/* A ping reply was received.  Was it a reply to the ping just sent? */
		if( usRequestSequenceNumber == usReplySequenceNumber )
		{
			/* This was a reply to the request just sent. */
		}
		else
		{
			
		}
	}
}

but when compiling, the compiler tells me the following error:

Any comment or suggestion is welcome

I think you should use an object resp. a struct freertos_sockaddr clientAddress; and provide it’s address to FreeRTOS_GetRemoteAddress( …, &clientAddress );
to get it filled with the peer address.
Also then you can correctly use clientAddress.sin_addr to ping.

Hello, thanks for the suggestions, the first change has been regarding the declaration of clientAddress which is like this:

 struct freertos_sockaddr clientAddress;

Then the change that was made regarding the FreeRTOS_GetRemoteAddress function is now like this:

if (-pdFREERTOS_ERRNO_EINVAL != FreeRTOS_GetRemoteAddress(apptcpipserverData.xConnectedSocket, &clientAddress )) 

With regard to performing the ping I have tried it in two ways, and both give me an error (when compiling), the first way is like this:

usRequestSequenceNumber = FreeRTOS_SendPingRequest( clientAddress.sin_addr, 8, 100 / portTICK_PERIOD_MS );

[quote]build/default/production/_ext/1360937237/apptcpipserver.o: In function APPTCPIPSERVER_Tasks': c:/projects/alexa home 7/firmware/src/apptcpipserver.c:249: undefined reference to FreeRTOS_SendPingRequest’[/quote]

And the other option is like this:

usRequestSequenceNumber = FreeRTOS_SendPingRequest( clientAddress->sin_addr, 8, 100 / portTICK_PERIOD_MS );

[quore]…/src/apptcpipserver.c: In function ‘APPTCPIPSERVER_Tasks’:
…/src/apptcpipserver.c:249:104: error: invalid type argument of ‘->’ (have ‘struct freertos_sockaddr’)
usRequestSequenceNumber = FreeRTOS_SendPingRequest( clientAddress->sin_addr, 8, 100 / portTICK_PERIOD_MS );[/quote]

Hmm … this are completely unrelated issues. With the fix using an object the 2nd error is clear, right ? It’s just syntactically wrong using the-> operator.
Regarding 1st issue is it possible that your project doesn’t contain the respective source file where FreeRTOS_SendPingRequest is defined or that it doesn’t get compiled/linked in properly ?

I think it is defined correctly

image

The TCPIP server works great, the reason I want to ping the client is that a client termination can happen without closing the socket.

The server (the microcontroller) doesn’t detect this event, and when the client wants to reconnect, it is not possible because it only allows a single client to connect and the socket has not been closed.

That is why I want to ping the client and if the MCU detects that after a certain time there is no response, the server would close the socket.

If there is a better idea regarding that problem, I might just drop the idea of pinging.

Being defined as opposed to be declared means that there is a source file with the actual implementation of a function (usually in a c/cpp file, whereas header files usually contain the corresponding declarations).
Looking up https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/305e1f21705aa482464785f2354e8ecd65e2201c/FreeRTOS_IP.c#L1419

did you

ipconfigSUPPORT_OUTGOING_PINGS must be set to 1 in FreeRTOSIPConfig.h for FreeRTOS_SendPingRequest() to be available.

as documented here and is FreeRTOS_IP.c compiled and linked into your application ?

1 Like

I hadn’t noticed, thank you.

I have put 1 ipconfigSUPPORT_OUTGOING_PINGS, and when compiling I get an error regarding axICMPPacket-> xICMPHeader.usIdentifier in FreeRTOS_IP.c:

/* Call back into the application to pass it the result. */
vApplicationPingReplyHook( eStatus, pxICMPPacket->xICMPHeader.usIdentifier ); 

Well, it’s all documented. Follow the link to the API doc and see the example how to deal with that. Good luck !

1 Like

@hs2

Ok, I got it. Thank you. The project has been compiled without errors, now I must check if the ping works.