This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

getaddrinfo failing on some networks

Hi,

I am using TI-RTOS 2.14.04.31 with NDK 2.24.03.35 and XDC 3.32.00.06 on a TM4C129NCPDT based custom board. Your forums suggested using getaddrinfo instead of a fullfledged DNS service to acquire the server's IP from a hostname. I have encountered a problem on some routers, where getaddrinfo fails every time while on other routers it works perfectly. Some of the routers tested have been connected to the same network. Using a hostname is the prefered method for connecting to the server in our application.

Can anyone give insight into why this could be? How to resolve the issue?

  • Hi Jaan,

    Unfortunately, our NDK expert is out for the day, so I will ask him about this issue tomorrow.  In the meantime, can you answer the following:

    • What is your network topology?
    • Is the topology the same for passing & failing cases?
    • Can you provide wireshark logs?

    Thanks,

    -- Emmanuel

  • Hello,

    I do not know the full topology of all the networks, I'm sorry. What I do know is that it works perfectly connected to a 4G router that is connected to the phone operator company. It also worked when I connected a wifi router to the same 4G router and the device to the wifi router.

    It also worked perfectly just plugged into a university building's ethernet port, but I do not know their network setup.

    In another setting, getaddrinfo kept returning EAI_NONAME. In this case the device was connected to a home router that then connects to the ISP directly.

    I also tried it at the client's office, where it worked perfectly when connected to one router but not another. Their contact person could not supply me with the details of their network.

    I can not supply you with wireshark logs at the moment, but if they end up being necessary I will figure something out.

    Thank your taking the time for me!

  • Hi Jaan,

    From your post above it seems like it is working when you have direct access to the internet & DNS servers. Are you sure there is a DNS server on the network in failure cases? I spoke with our NDK expert & he believes you would only get the EAI_NONAME return code because a DNS server could not be contacted.

    Also I highly recommend you post Wireshark logs of the network transfers, this will help determine what is going on (it is also a really really helpful tool for any network developer).

    Regards,
    -- Emmanuel
  • I will look into getting a hub to use to capture packets.

    Just to be clear,  in one of the instances described above, where getaddrinfo failed, the device was connected to two different routers, both of which have the same connection going into them. getaddrinfo worked with one of them but not the other. How do other devices function using name servers in a configuration like this?

    In the other instance, the same router was used for the developer's PC and other devices to connect to the internet aswell.

    Just in case, this is how I call getaddrinfo:

    	struct addrinfo hints;
    	struct addrinfo *server_data = NULL;
    	memset(&hints, 0, sizeof(hints));
    
    	hints.ai_family = AF_INET;
    	hints.ai_socktype = SOCK_STREAM;
    	hints.ai_protocol = IPPROTO_IP;
    
    	// Get server IP address once
    	int value = getaddrinfo(HOSTNAME, PORT_STR, &hints, &server_data);
    	if (value != 0) {
    		System_printf("Error getting server IP\n"); System_flush();
    	}
    
    	System_printf("Got address!\n"); System_flush();

    Having getaddrinfo run in a do-while loop with a sleep timer in between still yielded EAI_NONAME in the latter case.

  • Hi Jaan,

    Sorry I lost track of this post.

    I am still unsure if this is a NDK problem or a problem with the router.  Can you write a small program on your host/development PC to execute the code above (using the getaddrinfo API)? These are BSD APIs so you should have little trouble porting it over.  If running the program while on the problem router is successful, it would rule out the router as the problem.  If it fails on the PC, then we would know there is something odd with the router.

    Regards,

    -- Emmanuel

  • Hi Emmanuel,

    I am working together with other Jaan.
    I did test the same code on my Linux PC using the same router. The code was working correctly in my Linux PC. Thus it seems that it is possibly NDK problem.

    Regards,

    Jaan