# Getaddrinfo failing after closing socket

**URL:** <https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443>\
**Category:** Uncategorized\
**Created:** [February 27, 2023, 3:31pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443 "2023-02-27T15:31:21Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![karlkuhn](https://avatars.discourse-cdn.com/v4/letter/k/977dab/32.png) [@karlkuhn](https://forum.legato.io/u/karlkuhn)\
**Post date:** [February 27, 2023, 3:31pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/1 "2023-02-27T15:31:21Z")

</div>

Hi, I am running on a FX30S LTE-M WP77 with legato 19.11.5…

I can successufly create a data connection, resolve hostname using getaddrinfo.  
I then close the socket.

I use le\_data\_Request and socket / close…

However any subsequent attempts to resolve a hostname then fail with **"Temporary failure in name resolution "**

cm data, shows there is a connection with DNS and gateway IP addresses.

root@fx30s:~# cm data  
Index: 1  
APN: \*\*\*\*\*  
PDP Type: IPV4  
Connected: yes  
Interface: rmnet\_data0  
Family[IPv4]: inet  
IP[IPv4]: \*\*\*\*\*\*\*\*  
Gateway[IPv4]: \*\*\*\*\*\*\*\*\*  
Dns1[IPv4]: 8.8.8.8  
Dns2[IPv4]: 212.9.0.136

ping my.host.name  
nslookup my.host.name 8.8.8.8  
ping 8.8.8.8

all fails. They where fine before the initial connection in the legato app.  
resolv.conf is correctly populated.

Any thoughts?

Thanks,Karl

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 27, 2023, 3:36pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/2 "2023-02-27T15:36:12Z")

</div>

If you disconnect data connection by “cm data connnect -1”, and thr restart data channel by “cm data”, can it be resolved?

---

<div class="post-metadata">

**Author:** ![karlkuhn](https://avatars.discourse-cdn.com/v4/letter/k/977dab/32.png) [@karlkuhn](https://forum.legato.io/u/karlkuhn)\
**Post date:** [February 27, 2023, 3:37pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/3 "2023-02-27T15:37:27Z")

</div>

Just tries that… it did not work.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 27, 2023, 3:39pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/4 "2023-02-27T15:39:04Z")

</div>

Then is this network problem?

---

<div class="post-metadata">

**Author:** ![karlkuhn](https://avatars.discourse-cdn.com/v4/letter/k/977dab/32.png) [@karlkuhn](https://forum.legato.io/u/karlkuhn)\
**Post date:** [February 27, 2023, 3:41pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/5 "2023-02-27T15:41:29Z")

</div>

No I don’t think so… after reboot it work every time… the problem is repeatable…

Device reboots  
connected to bearer  
created data connection  
getaddrinfo and open socket  
send /rec data  
close socket

ping, nslookup etc don’t work anymore

Thanks,

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 27, 2023, 4:04pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/6 "2023-02-27T16:04:23Z")

</div>

then how about you do radio on off?  
cm radio off  
cm radio on

you might also need to capture wireshark log on rmnet interface to see what happens inside

---

<div class="post-metadata">

**Author:** ![karlkuhn](https://avatars.discourse-cdn.com/v4/letter/k/977dab/32.png) [@karlkuhn](https://forum.legato.io/u/karlkuhn)\
**Post date:** [February 27, 2023, 4:06pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/7 "2023-02-27T16:06:23Z")

</div>

busy setting up tcpdump so I can do just that… will try radio on off… but that would not be a solution…

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 27, 2023, 4:07pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/8 "2023-02-27T16:07:59Z")

</div>

you can see here for wireshark log capturing:

> [@View pings sent from an external device to mangoh red](https://forum.legato.io/t/view-pings-sent-from-an-external-device-to-mangoh-red/5378/3):
>
> @jyijyi Is there a step by step process you can provide?

---

<div class="post-metadata">

**Author:** ![karlkuhn](https://avatars.discourse-cdn.com/v4/letter/k/977dab/32.png) [@karlkuhn](https://forum.legato.io/u/karlkuhn)\
**Post date:** [February 27, 2023, 4:20pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/9 "2023-02-27T16:20:04Z")

</div>

I just get no reply… when “ping 8.8.8.8”

 ![image](https://us1.discourse-cdn.com/flex019/uploads/legato1/original/2X/1/10d7971306a82490b537afe0d71f2518fbf1b56a.png)

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 27, 2023, 4:24pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/10 "2023-02-27T16:24:35Z")

</div>

even after re-estabishment of data channel?  
even after restart of radio by “cm radio”?

How do you reproduce the issue?

1. cm data connect
2. ping 8.8.8.8
3. wait for some time
4. ping does not work

---

<div class="post-metadata">

**Author:** ![karlkuhn](https://avatars.discourse-cdn.com/v4/letter/k/977dab/32.png) [@karlkuhn](https://forum.legato.io/u/karlkuhn)\
**Post date:** [February 27, 2023, 4:40pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/11 "2023-02-27T16:40:04Z")

</div>

it seems turning radio off then on resolves the issue.

To recreate… I start my app which  
a) turns the radio on (if off) with le\_mrc\_SetRadioPower(LE\_ON)  
b) wait for network registration (in the le\_mrc\_AddNetRegStateEventHandler)  
c) request data connection with le\_data\_Request()  
d) wait for connection in le\_data\_AddConnectionStateHandler

At this point I can ping successfully to 8.8.8.8

then in my app it  
e) get IP address for hostname using getaddrinfo and getnameinfo  
f) create a non blocking socket using “connect”  
g) send/receive data over socket  
h) close the socket once done.

At this point I cannot ping to 8.8.8.8 anymore… I get no response as per tcpdump…

cm radio and cm data suggest I still have a connection… however I can’t successfully send/rec anything over rmnet…

cm data connect -1 followed by cm data connect does not seem to solve it… I need to cm radio off and then cm radio on…

However that is a problem as I cannot turn the radio off and on for each socket connection…

I assume I am doing something wrong… but can’t work out what…

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 27, 2023, 4:50pm UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/12 "2023-02-27T16:50:01Z")

</div>

can you reproduce the issue with cm tool only?

1. cm data connect
2. ping 8.8.8.8
3. wait for some time

---

<div class="post-metadata">

**Author:** ![karlkuhn](https://avatars.discourse-cdn.com/v4/letter/k/977dab/32.png) [@karlkuhn](https://forum.legato.io/u/karlkuhn)\
**Post date:** [February 28, 2023, 7:16am UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/13 "2023-02-28T07:16:33Z")

</div>

If I turn my app off and do the above… it does not fail… so something in the app is causing this… but what?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 28, 2023, 7:29am UTC](https://forum.legato.io/t/getaddrinfo-failing-after-closing-socket/6443/14 "2023-02-28T07:29:56Z")

</div>

one idea is to try the modemdemo application, if it works, and then you can port the code there to your application  
In this way, you don’t need to debug your current code
