Download FreeRTOS

Quality RTOS & Embedded Software

Simplifying Authenticated Cloud Connectivity for Any Device.
Designing an energy efficient and cloud-connected IoT solution with CoAP.
Introducing FreeRTOS Kernel version 11.0.0:
FreeRTOS Roadmap and Code Contribution process.
OPC-UA over TSN with FreeRTOS.

[FreeRTOS-Plus-TCP API Reference]

BaseType_t FreeRTOS_getaddrinfo_a( const char * pcName,
                                   const char * pcService,
                                   const struct freertos_addrinfo * pxHints,
                                   struct freertos_addrinfo ** ppxResult,
                                   FOnDNSEvent pCallback,
                                   void * pvSearchID,
                                   TickType_t uxTimeout );

The suffix "_a" stands for asynchronous, and the function is a non-blocking function. The API functionality is the same as FreeRTOS_getaddrinfo, along with the capability to perform multiple IP lookups asynchronously. Which means the call returns immediately whereas the lookup happens in the background. Once the lookup is completed or a timeout occurs, a user defined function pCallback will be called to send the updated results back.


The name of the node or device.
Ignored for now.
If not NULL then can be used to indicate the preferred type of IP ( v4 or v6 ).
An allocated struct, containing the results.
The callback function to be called when the address has been found or when a timeout has been reached.
Search ID for the callback function.
Timeout for the callback function.

The callback function should be of the following type:

void (* FOnDNSEvent ) ( const char * /* pcName */,
void * /* pvSearchID */,
struct freertos_addrinfo * /* pxAddressInfo */ );
where the pcName is the name of the node or device that's looked up, pvSearchID is the ID that was passed when the call to FreeRTOS_getaddrinfo_a was made for that query, and pxAddressInfo contains the result.

Example usage:

/* FreeRTOS-Plus-TCP DNS include. */
#include "FreeRTOS_DNS.h"

static BaseType_t xDNSResult = -2;

static void vDNSEvent( const char * pcName,
void * pvSearchID,
struct freertos_addrinfo * pxAddrInfo )
( void ) pcName;
( void ) pvSearchID;

FreeRTOS_printf( ( "vDNSEvent: called with %p\n", pxAddrInfo ) );
showAddressInfo( pxAddrInfo );

if( pxAddrInfo != NULL )
xDNSResult = 0;

static void dnsTest( const char * pcHostName )
uint32_t ulID;
BaseType_t rc;

if( xApplicationGetRandomNumber( &( ulID ) ) != pdFALSE )

xDNSResult = -2;
rc = FreeRTOS_getaddrinfo_a( pcHostName,
&pxResult, /* An allocated struct, containing the results. */
( void * ) ulID,
pdMS_TO_TICKS( 1000U ) );
vTaskDelay( pdMS_TO_TICKS( 1000U ) );
rc = xDNSResult;
FreeRTOS_printf( ( "Lookup '%s': %d\n", pcHostName, rc ) );
FreeRTOS_printf( ( "dns_test: Failed to generate a random SearchID\n" ) );

Example use of the FreeRTOS_getaddrinfo_a() API function

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.