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.

RTOS: DNS Client example

Other Parts Discussed in Thread: EK-TM4C129EXL

Tool/software: TI-RTOS

Hello,

I would like to resolve hostname to ip using local DNS server. ( Sometimes valid DNS servers are used such as dnsmasq, sometimes a basic router does the job with static dns entries.) My problem is I don't find any out of the box examples nowhere.

My starting application is the tcpEcho example (EK-TM4C129EXL) and I only add the DNS module to the config. After that I can not build the example. Can you tell me how to go on?

Please see the attached image:

Looking forward you kind reply,

  • Daniel,

    You can use DNSGetHostByName() (which is similar to gethostbyname()). What you are did was add a DNS server into the target. I don't think you want to do that. You want to access a local DNS to resolve the name. Note: the DNS servers are specified as part of the DHCP setup or must be explicitly set if you have a static IP address.

    Todd
  • Thank you for your reply. May I ask some support to find the right header file as well as include example to use gethostbyname() ?

    UPDATE: I got this work with the following code:

        struct addrinfo *server_data = NULL;
        int result = 0;
    
    
    
        System_printf("!!!!!!!!!!\n", result);System_flush();
    
        result = getaddrinfo(HOSTNAME, "0", NULL, &server_data);
    
        System_printf("getaddrinfo result: %d\n", result);
    
        if (result == 0 && server_data != NULL)
        {
            struct sockaddr addr = *(server_data->ai_addr);
            inet_ntop(AF_INET, &((struct sockaddr_in *)&addr)->sin_addr, strIp, INET_ADDRSTRLEN);
            System_printf("Resolved address:%s\n", strIp);
    
            freeaddrinfo(server_data);
            server_data = NULL;
        }
    
    
        System_flush();

    However, I can not resolve static hostnames handled by my router. I can resolve hostnames like "www.google.com"

    Any idea how to go on? 

    Shall I create a new thread for this question?

  • This thread is not too long so let's just deal with it here.

    What is Wireshark showing for the "www.google.com" and "myStaticName" (or whatever your static hostname is)? Are you sure the DNS Server knows the static hostnames?
  • I was a bit confused with the hostnames listed on the dhcp client list and the domain names in the router settings. On my Win machine i can ping the "hostname" however the NDK can not resolve the hostname. I had to add the "hostname" to the router domain names list and everything works very well.

    Thank you for your help.
  • Cool! Glad to hear it's all working now.