# FreeRTOS DNS issue (first request does not send)

**URL:** <https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896>\
**Category:** Libraries\
**Created:** [July 5, 2024, 10:07am UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896 "2024-07-05T10:07:46Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![pistoletov1974](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/pistoletov1974/32/4554_2.png) [@pistoletov1974](https://forums.freertos.org/u/pistoletov1974)\
**Post date:** [July 5, 2024, 10:07am UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/1 "2024-07-05T10:07:47Z")

</div>

Hi!  
Every first DNS request after system start does not send . The situation is 100% repeated at the first request after launching the application  
I attach log and screenshot from wireshark  
This is part of the log of the first failed request:

```auto
 [12:51:41:077] > dnscheck google.com
 [12:51:41:083] < 
 [12:51:41:083] < FreeRTOS_FindEndPointOnNetMask[4]: No match for 5fae6002ip
 [12:51:41:083] < ARP 5fae6002ip miss using c0a85801ip
 [12:51:41:083] < FreeRTOS_FindEndPointOnNetMask[11]: No match for 5fae6002ip
 [12:51:46:094] < DNS_ReadReply returns -11
 [12:51:46:094] < prvIncreaseDNS4Index: from 0 to 1
 [12:51:46:094] < FreeRTOS_FindEndPointOnNetMask[4]: No match for 8080808ip
 [12:51:46:094] < ARP 8080808ip miss using c0a85801ip
 [12:51:50:877] < Network buffers: 56 lowest 54
 [12:51:50:877] < pxEasyFit: ARP c0a8586dip -> c0a85801ip
 [12:51:50:877] < ipARP_REPLY from c0a85801ip to c0a8586dip end-point c0a8586dip
 [12:51:51:093] < DNS_ReadReply returns -11
 [12:51:51:093] < prvIncreaseDNS4Index: from 1 to 0
 [12:51:51:093] < REsolved addr:0.0.0.0

```

 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/e/e65f3cf2ac31d287cec6188765fc25d9fce2580c.png)  
[log\_dns.c](https://forums.freertos.org/uploads/short-url/uKlFbNs7WbSJSmiuVvrYgSG23wQ.c) (5.4 KB)

---

<div class="post-metadata">

**Author:** ![archigup](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/archigup/32/1418_2.png) [@archigup](https://forums.freertos.org/u/archigup)\
**Post date:** [July 5, 2024, 6:25pm UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/2 "2024-07-05T18:25:53Z")

</div>

Hi, which version of FreeRTOS+TCP and which port are you using?

---

<div class="post-metadata">

**Author:** ![pistoletov1974](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/pistoletov1974/32/4554_2.png) [@pistoletov1974](https://forums.freertos.org/u/pistoletov1974)\
**Post date:** [July 5, 2024, 6:47pm UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/3 "2024-07-05T18:47:42Z")

</div>

FreeRTOS TCP version 4.1.0 and custom port for Cortex M4 with zerocopy driver based on STM32F4 port. If you need more debug information (breakpoints, data etc…) dont hesitate to ask-)

---

<div class="post-metadata">

**Author:** ![NikhilKamath](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/nikhilkamath/32/2934_2.png) [@NikhilKamath](https://forums.freertos.org/u/NikhilKamath)\
**Post date:** [July 6, 2024, 5:57am UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/4 "2024-07-06T05:57:43Z")

</div>

It looks like it took some time for the ARP resolution for the default gateway 192.168.88.1? From the logs below, once the ARP resolution for default gateway succeeds, the DNS resolves, which is expected.

```auto
[12:51:41:083] < FreeRTOS_FindEndPointOnNetMask[4]: No match for 5fae6002ip
 [12:51:41:083] < ARP 5fae6002ip miss using c0a85801ip
 [12:51:41:083] < FreeRTOS_FindEndPointOnNetMask[11]: No match for 5fae6002ip
 [12:51:46:094] < DNS_ReadReply returns -11
 [12:51:46:094] < prvIncreaseDNS4Index: from 0 to 1
 [12:51:46:094] < FreeRTOS_FindEndPointOnNetMask[4]: No match for 8080808ip
 [12:51:46:094] < ARP 8080808ip miss using c0a85801ip
 [12:51:50:877] < Network buffers: 56 lowest 54
 [12:51:50:877] < pxEasyFit: ARP c0a8586dip -> c0a85801ip
 [12:51:50:877] < ipARP_REPLY from c0a85801ip to c0a8586dip end-point c0a8586dip
 [12:51:51:093] < DNS_ReadReply returns -11
 [12:51:51:093] < prvIncreaseDNS4Index: from 1 to 0
 [12:51:51:093] < REsolved addr:0.0.0.0
 [12:52:08:073] > dnscheck amazon.com
 [12:52:08:088] < 
 [12:52:08:088] < FreeRTOS_FindEndPointOnNetMask[4]: No match for 5fae6002ip
 [12:52:08:088] < ARP 5fae6002ip hit using c0a85801ip
 [12:52:08:104] < FreeRTOS_ProcessDNSCache: add: amazon.com @ 205.251.242.103 (TTL 723)
 [12:52:08:104] < DNS[0xEAE1]: The answer to amazon.com (205.251.242.103) will be stored
 [12:52:08:104] < REsolved addr:205.251.242.103

```

Can you share the wireshark capture for ARP as well along with DNS? Overall the behavior looks as expected, but might be interesting to see why it took so long for ARP to resolve.  
@ActoryOu@moninom1

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [July 6, 2024, 8:45am UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/5 "2024-07-06T08:45:59Z")

</div>

When FreeRTOS sends a packet to an unresolved IP-address, it will change the UDP packet into an ARP request. This was created in a time that RAM was very expensive 🙂

The UDP packet will not be sent, that is why you must do it a second time.

You can force an ARP lookup of the gateway with this function:

```auto
    /* xARPWaitResolution checks if an IPv4 address is already known. If not
     * it may send an ARP request and wait for a reply. This function will
     * only be called from an application. */
    BaseType_t xARPWaitResolution( uint32_t ulIPAddress,
                                   TickType_t uxTicksToWait );

```

You can call it like this, as soon as the network is up:

```auto
    BaseType_t doARPLookup = pdFALSE;

    void vApplicationIPNetworkEventHook_Multi( eIPCallbackEvent_t eNetworkEvent,
                                               NetworkEndPoint_t *pxEndPoint )
    {
        /* If the network has just come up...*/
        if( eNetworkEvent == eNetworkUp )
        {
            doARPLookup = pdTRUE;
        }
    }
    void main_loop()
    {
        if( doARPLookup == pdTRUE )
        {
            doARPLookup = pdFALSE;
            xARPWaitResolution( pxEndPoint->ipv4_settings.ulGatewayAddress,
                                pdMS_TO_TICKS( 500U ) );
        }

```

Note that `vApplicationIPNetworkEventHook_Multi()` is called by the IP-task, and therefore it is **not allowed** to call `xARPWaitResolution()` immediately.

Please report back how it goes.

---

<div class="post-metadata">

**Author:** ![pistoletov1974](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/pistoletov1974/32/4554_2.png) [@pistoletov1974](https://forums.freertos.org/u/pistoletov1974)\
**Post date:** [July 8, 2024, 1:02pm UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/6 "2024-07-08T13:02:28Z")

</div>

hi! I attach the wireshark capture screen and log. As we can see ARP reply appeared only after 10sec,

 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/9/9fef4a3d7462d6b77a41a37074529123c98bf41c.png)

[dnc+arp.c](https://forums.freertos.org/uploads/short-url/j1bn44Qs96C1KeTZTV7PV6W2FX0.c) (6.5 KB)

---

<div class="post-metadata">

**Author:** ![pistoletov1974](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/pistoletov1974/32/4554_2.png) [@pistoletov1974](https://forums.freertos.org/u/pistoletov1974)\
**Post date:** [July 8, 2024, 1:28pm UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/7 "2024-07-08T13:28:05Z")

</div>

> [@htibosch](#):
>
> Please report back how it goes.

at first glance it works well  
I add this code in the begining of sntp\_task (which use dns requests)

```auto
            if( doARPLookup == pdTRUE )
            {
            doARPLookup = pdFALSE;
            LogDebug( ( "Waiting for arp gateway..." ) );    
            xARPWaitResolution( endpoint.ipv4_settings.ulGatewayAddress,
                                pdMS_TO_TICKS( 20000U ) );
            } 

```

and this code from you post in vApplicationIPNetworkEventHook\_Multi:

> [@htibosch](#):
>
> ```auto
> /* If the network has just come up...*/
> if( eNetworkEvent == eNetworkUp )
> {
> doARPLookup = pdTRUE;
> }
> 
> ```

I will add a similar code to the tasks who uses dns (mqtt agent) or can create a high-priority task that will be created in vApplicationIPNetworkEventHook\_Multi and executed once and then deleted? What is your opinion?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [July 9, 2024, 5:06am UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/8 "2024-07-09T05:06:19Z")

</div>

> [@pistoletov1974](#):
>
> I will add a similar code to the tasks who uses dns (mqtt agent) or can create a high-priority task that will be created in vApplicationIPNetworkEventHook\_Multi and executed once and then deleted? What is your opinion?

You need to do gateway resolution once only, so the second option seems better. Have you also thought about adding retries in case of error? This way you won’t have to add extra code for triggering ARP resolution and the normal error handling code would take care of sending the DNS query. Adding retries would also have the benefit of making your application robust in case of unpredictable network errors.

---

<div class="post-metadata">

**Author:** ![newbie](https://avatars.discourse-cdn.com/v4/letter/n/dc4da7/32.png) [@newbie](https://forums.freertos.org/u/newbie)\
**Post date:** [October 30, 2024, 6:34am UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/9 "2024-10-30T06:34:05Z")

</div>

> [@pistoletov1974](#):
>
> `FreeRTOS_FindEndPointOnNetMask[4]: No match for`

May I ask a question?  
"FreeRTOS\_FindEndPointOnNetMask[4]: No match for " is a bug?

---

<div class="post-metadata">

**Author:** ![ActoryOu](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/actoryou/32/2880_2.png) [@ActoryOu](https://forums.freertos.org/u/ActoryOu)\
**Post date:** [October 30, 2024, 9:23am UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/10 "2024-10-30T09:23:03Z")

</div>

Hi @newbie,  
I’d like to clarify that what you’re experiencing is not actually a bug, but rather an expected behavior in certain network configurations.

The message you’re seeing indicates that FreeRTOS-Plus-TCP is unable to locate the corresponding endpoint for the specific IP address. This situation typically occurs when the remote IP address is not within the same subnet as your device.

Thank you.

---

<div class="post-metadata">

**Author:** ![newbie](https://avatars.discourse-cdn.com/v4/letter/n/dc4da7/32.png) [@newbie](https://forums.freertos.org/u/newbie)\
**Post date:** [October 30, 2024, 9:41am UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/11 "2024-10-30T09:41:20Z")

</div>

Hi. Thanks for your response.  
Yes, actually I tried to connect my device (local IP) to AWS endpoint. As your mention, it’s not same subnet.

 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/b/b459501e0dda95436b143343fdfe977399f82d58.png)  
I would like to not show “FreeRTOS\_FindEndPointOnNetMask[4]: No match for”, but when I check code, it seems I can not.  
I hope in next version, this FreeRTOS\_debug\_printf will be configurated by user that we can show log or not.

---

<div class="post-metadata">

**Author:** ![ActoryOu](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/actoryou/32/2880_2.png) [@ActoryOu](https://forums.freertos.org/u/ActoryOu)\
**Post date:** [October 30, 2024, 9:53am UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/12 "2024-10-30T09:53:42Z")

</div>

Yes, we support configuration to disable FreeRTOS\_debug\_printf. Please refer to [FreeRTOS-Plus-TCP Configuration - FreeRTOS™](https://www.freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/06-Configuration#ipconfighas_debug_printf-and-freertos_debug_printf) for more detail. Hopefully this is good enough for you.

Thank you.

---

<div class="post-metadata">

**Author:** ![newbie](https://avatars.discourse-cdn.com/v4/letter/n/dc4da7/32.png) [@newbie](https://forums.freertos.org/u/newbie)\
**Post date:** [October 30, 2024, 10:08am UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/13 "2024-10-30T10:08:09Z")

</div>

@ActoryOu . Thanks. I will try later.  
This FreeRTOS-Plus-TCP version is different from previous on showing the log. May I know the purpose of the adding FreeRTOS\_InterfaceEndPointOnNetMask?

---

<div class="post-metadata">

**Author:** ![ActoryOu](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/actoryou/32/2880_2.png) [@ActoryOu](https://forums.freertos.org/u/ActoryOu)\
**Post date:** [October 30, 2024, 10:21am UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/14 "2024-10-30T10:21:07Z")

</div>

`FreeRTOS_InterfaceEndPointOnNetMask` was introduced as part of our efforts to enhance FreeRTOS-Plus-TCP’s capabilities. When we updated to version 4.0.0, we not only implemented IPv6 support but also added functionality for managing multiple network interfaces. The `FreeRTOS_InterfaceEndPointOnNetMask` is one of the key function in supporting these multiple interfaces.

For more comprehensive information on this feature and its implementation, I would encourage you to refer to our official documentation: [FreeRTOS-Plus-TCP Multiple Interfaces - FreeRTOS™](https://www.freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/03-Multiple-interface/01-Multiple-interfaces)

Thank you.

---

<div class="post-metadata">

**Author:** ![newbie](https://avatars.discourse-cdn.com/v4/letter/n/dc4da7/32.png) [@newbie](https://forums.freertos.org/u/newbie)\
**Post date:** [October 31, 2024, 2:57am UTC](https://forums.freertos.org/t/freertos-dns-issue-first-request-does-not-send/20896/15 "2024-10-31T02:57:16Z")

</div>

@ActoryOu  
Thank you.
