FX30s - Having problem resolving DNS address

#1

Hi all,

I’m writing an app to connect to a telnet server. When I use the IP address I connect with no problem, but if I use the DNS address, the “connect” command returns a negative value:

if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0)
{

}

I’m sure I’m missing some configuration somewhere, but I have’t been able to find any reference to it. Any help is appreciated. Thanks!

Regards,

Eddie

#2

Hi Eddie,
If you run ‘telnet’ at the command line, does it work?

If you ping using a DNS name, does that work?

The DNS port should already be open in the firewall. Can you also post the output of /etc/resolv.conf please?

BR,
Chris

#3

Chris,

The telnet and ping command both work from a ssh usb session and connect using the DNS address, as long as I have run “CM DATA CONNECT &”

root@fx30s:~# cat /etc/resolv.conf
nameserver 10.177.0.34
nameserver 10.177.0.210

In my app, I’m using the serial port uart1 as “Customer Linux application”
I type telnet, DNS address and port which gives me an error. If I type the same thing only I use the IP address instead of DNS, it connects just fine.

Eddie

#4

I added code to my app to list the network info and this is what I got:

| Net-Info buffer:
| IPV4 GW: 22.101.215.1, DNS1: 10.177.0.34, DNS2: 10.177.0.210 on rmnet0

#5

Hi Eddie

Is your app “sandboxed” ? - if so this could this be an issue of the /etc/resolv.conf being different (an older copy from earlier in the start up process) in your app to the one in the main OS ?

Cheers

John

#6

John,

How do I test if it’s sandboxed or not? Thanks.

Eddie

#7

John,

I figured it out about “sandboxed”, but that didn’t resolve the DNS name.

I found that the socket connect() function does not accept host names, only IP addresses.

I had to use the function getaddrinfo() to resolved the DNS host name and it returned the IP
address. Working great now. Thanks for your help!

Regards,

Eddie

1 Like
#8

Hi Eddie

I had some issues using getaddrinfo() inside a sandbox. As a workaround I created the following - which probably isn’t the best way to do this or that maintainable. I’d be very happy if someone could provide a better way of fixing the problem :slight_smile:

Cheers

John

#9

John,

You’re correct, if I sandboxed my project, the getaddrinfo() function can’t resolve the DNS host name. When I set sandboxed: false, it worked correctly.

Thanks for the help!

Regards,

Eddie