Quality RTOS & Embedded Software

NOTE:This is a read only archive of threads posted to the FreeRTOS support forum. Use these archive pages to search previous posts. New forum support threads can be started at the FreeRTOS forums.

FreeRTOS Support Archive

The FreeRTOS support forum can be used for active support both from Amazon Web Services and the community. In return for using our software for free, we request you play fair and do your bit to help others! Sign up for an account and receive notifications of new support topics then help where you can.

This is a read only archive of threads posted to the FreeRTOS support forum. Use these archive pages to search previous posts. New forum support threads can be started at the FreeRTOS forums.

printf(“%lxip”) in FreeRTOS+TCP

Hi!
I just saw that FreeRTOS+TCP uses a custom “%lxip” format specifier to print IP adresses.
This format is not supported by newlib, and I can’t use the recommended printf-stdarg.c from the FreeRTOS demos either (LGPL license :/ ).
So I would like to change that to a more portable “%d.%d.%d.%d”.
Has anyone done this already?
Would you accept a patch?
best regards,
Thomas

printf(“%lxip”) in FreeRTOS+TCP

Hi Thomas,
The format “%lxip” is supported by the module “printf-stdarg.c”, which was included in the original FreeRTOS+TCP distribution on freertos.org/tcp
If that module is not included, the statement will print as e.g. “C0A80101ip”, instead of “192.168.1.1”.

This format is not supported by newlib, and I can’t use the recommended
printf-stdarg.c from the FreeRTOS demos either (LGPL license :/ ).

I am not an expert on licensing, but I think that “printf-stdarg.c” has the same MIT-type licence as the FreeRTOS+TCP library.

define FreeRTOSntohliptoprintf_args(IP)

~~~
and substitute:
~~~
FreeRTOSdebugprintf( ( “vDHCPProcess: acked %lxipn”, FreeRTOS_ntohl( xDHCPData.ulOfferedIPAddress ) ) );
~~~
with:
~~~
FreeRTOSprintf( ( “vDHCPProcess: acked %d.%d.%d.%dn”, FreeRTOSntohliptoprintfargs( xDHCPData.ulOfferedIPAddress ) ) );
~~~
I noticed that there are a lot of places, where ntohl() is missing, and sometimes it’s even mixed in the same printf() (see FreeRTOSTCPIP.c, line 1028):
~~~
FreeRTOSdebugprintf( ( “ARP for %lxip (using %lxip): rc=%d %02X:%02X:%02X %02X:%02X:%02Xn”,
pxSocket->u.xTCP.ulRemoteIP,
FreeRTOS_ntohl( ulRemoteIP ),
~~~
Is this by purpose? I would have expected that +TCP uses a consistent format internally, or at least uses different variable names to identify host and network order.
I think I will use two different macros then. I’m also not so clear what names to use.
Perhaps
FreeRTOSnetiptoprintfargs () for network order and a plain
FreeRTOSiptoprintf_args () for native order IPs?