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.

DNSGetHostByName failed to resolve host

MCU: TM4C1294NCPDT

TI-RTOS: v2.01.00.03

NDK: v2.23.01.01

CCS: v6.0.1.0040

-

Hi,

Following the post , I am using the following code in a task to get the IP address of "www.google.com" but the function "DNSGetHostByName()" returns 19 (NO DNS REPLY). Is there any solution to the issue?

-

System_printf("CfgGetImmediate(DNS) = %d\r\n", CfgGetImmediate( 0, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER, 1, 4, (UINT8 *)&IPTmp ));
System_printf("DNS IP = %d.%d.%d.%d\r\n", (UINT8)(IPTmp)&0xFF, (UINT8)(IPTmp>>8)&0xFF, (UINT8)(IPTmp>>16)&0xFF, (UINT8)(IPTmp>>24)&0xFF);
Task_sleep(5000);
System_printf("DNSGetHostByName = %d\r\n", DNSGetHostByName("www.google.com", &host, sizeof(host)));

-

The code above shows the DNS set to "208.67.222.222", but still the function "DNSGetHostByName()" fails to resolve the host.

-

Thanks

-

Regards

Soumyajit

  • Hi Soumyajit,

    Is your board connected directly to the Internet or through proxy/firewall? Host resolution is blocked through proxies/firewall.

    Vikram
  • Hi Vikram,

    Thanks for your reply. Yes, we do have a firewall but as per the words I had with my network administrator, the firewall is NOT set to block DNS requests. To confirm this, I tried to open 8.8.8.8 (Google Primary DNS Server) & also 208.67.222.222 (OpenDNS Server IP) at port 53 (DNS Port) using UDP Datagram packet mode; I tried this from a PC connected to the same network. I found that I could open the socket & push data to the server. I even got reply from the server containing the IP address of the url I have asked the DNS server to resolve. Now, I tried the same thing from NDK too (by opening a socket connection to the DNS server at port 53 in UDP mode) & I got reply from the server. In the query to the DNS server, I sent the URL www.google.com & the reply I received contained the IP address of Google. I tried opening this IP address from a browser & it took me to google search engine.

    What I mean to say is that the DNS requests are properly going through in the LAN network but due to some reason, NDK's DNS stack isn't working. Can you please check what might be going wrong?

    -

    Thanks

    -

    Regards

    Soumyajit

  • Hi 

    i think you can answer my questions about NDK hostname resolver :

    can you get local IP address (IP address of your board) by DNSGetHostByName ?

    thanks

    Ebi

  • Hi Soumyajit,

    Have you read the NDK Users Guide and NDK Programmers Guide and searched other forum posts for this issue?

    Vikram
  • Yes. I did. And that's how I came to know about the DNSgethostbyname() function. I even found the function getaddrinfo() but I couldn't make this function work.
    -
    I tried the DNS Resolving using UDP socket by forming the request, whereas the NDK's inbuilt function for DNS resolve isn't working as expected. During the development of DNS resolve function using UDP socket, I also came across "NO DNS REPLY". This situation happened when the DNS query packet was not formed properly. Eventually I could form the DNS query packet correctly & hence got a reply from the server. But here NDK's stack is unable to fetch the same reply from the server. I would like to have a look at the DNS query data that the NDK's stack is sending to the server. May be after looking at it, I will be able to conclude what might be going wrong with the DNS stack. Can you help me in pointing out the particular section of the code to look for to check the DNS query formation string?
    -
    Thanks
    -
    Regards
    Soumyajit
  • Hi Soumyajit,

    Here is a snippet from the telnet console code (ti/ndk/tools/console/condns.c) for the DNSGetHostByName usage:

            /* All the DNS functions need a scrap buffer */
            buffer = mmAlloc( 512 );
    
            if( buffer )
            {
                /* We can treat buffer as a HOSTENT structure after */
                /* DNSGetHostByXxx calls */
                HOSTENT *phe = (HOSTENT *)buffer;
    
                /* See if tok1 is an IP address */
                if( inet_aton( tok1, &in1 ) )
                    retcode = DNSGetHostByAddr( in1.s_addr, buffer, 512 );
                else
                    retcode = DNSGetHostByName( tok1, buffer, 512 );
    

    I will check with our NDK expert regarding the DNS query formation string question and also if there is a known issue with the DNSGetHostByName() for this NDK version.

    Vikram

  • Hi Soumyajit,

    DNS Host resolution code can be found in ti/ndk/nettools/dns/dnsclnt.c. I believe DNSResolve() is what you are looking for.

    Vikram
  • Hi Vikram,

    Since, I have implemented custom DNS resolution function using UDP socket, I am not going into details of NDK's DNS implementation. I tried to look into the DNSGetHostByName() function but somewhere got lost while trying to figure out the DNS query string.

    I would like to request you to check with the NDK Development Team for any known issues on this function or any specific configuration requirement that needs to be done to make this function work.

    -

    Thanks

    -

    Regards

    Soumyajit

  • Hi Soumyajit,

    I even found the function getaddrinfo() but I couldn't make this function work.

    Are you still using NDK 2.23x?  I think you must have moved to a newer version of the NDK because getaddrinfo was not supported in NDK 2.23.  If you have moved NDK versions, which version are you using now?

    Regarding the failure of DNSGetHostByName(), can you check a few things in your application?


    1. Could you please tell me which NDK libraries are being linked into your app?  I'm interested in the "nettool" and "stk" libraries, whose actual filenames depend on the settings you've configured in your app:

        You can find this info in a linker command file that's generated in your application.  It will have the form "*.xdl" and will look similar to the following:

    2. Can you check the value of "Global.IPv6" in your *cfg file?

        You can edit the app's *.cfg file and add the following at the end of the file:

        print("Global IPv6 = " + Global.IPv6);

    3. Is your app defining the following symbol in the compiler options?  You can see this in the build output, in particular of the build output of the file that you are calling DNSGetHostByName() from:

    -D_INCLUDE_IPv6_CODE

    If the results you see in 1, 2, 3 above are "IPv6 answers", then it could be that you need to instead call the following API:

    DNSGetHostByName2()


    Note that when IPv6 is enabled, you must call DNSGetHostByName2() even for IPv4 host name resolutions.

    Steve

  • Hi Steve,

    Glad to see your comments. Yes, I am still using 2.23.X NDK.

    (01) I found these two lines in the *.xdl file: "-l"C:\ti\tirtos_tivac_2_01_00_03\products\ndk_2_23_01_01\packages\ti\ndk\nettools\lib\nettool_ipv4.aem4f"" & "-l"C:\ti\tirtos_tivac_2_01_00_03\products\ndk_2_23_01_01\packages\ti\ndk\stack\lib\stk_nat_ppp_pppoe.aem4f"".

    (02) The .cfg file contains "Global.IPv6 = false;".

    (03) The build output do not have any occurrance of "-D_INCLUDE_IPv6_CODE" or "IPv6".

    -

    Thanks

    -

    Regards

    Soumyajit

  • Hi Steve and Soumyajit,

    I am using the same CPU as you guys and getting the same error. I have been trying to plug the board into different network/router, the dns server IP retrieve from CfgGet is correct, but the DNSDNSGetHostByName() only reply Error 19

    CCS Version: 6.2.0.00050

    xdctools 3.30.45.2
    bios_6_40_03_39
    ndk_2_23_01_01

    /* ================ NDK configuration ================ */
    var Ndk = xdc.loadPackage('ti.ndk.config');
    var Global = xdc.useModule('ti.ndk.config.Global');
    var Ip = xdc.useModule('ti.ndk.config.Ip');
    var Udp = xdc.useModule('ti.ndk.config.Udp');
    var Tcp = xdc.useModule('ti.ndk.config.Tcp');

    Global.IPv6 = false;
    Global.stackLibType = Global.MIN;

    //Global.pktNumFrameBufs = 10;
    Global.pktNumFrameBufs = 15;
    Global.memRawPageCount = 6;
    Global.ndkThreadStackSize = 1536;
    Global.lowTaskStackSize = 1024;
    Global.normTaskStackSize = 1024;
    Global.highTaskStackSize = 1024;
    Tcp.transmitBufSize = 1024;
    Tcp.receiveBufSize = 1024;
    Ip.dhcpClientMode = 1;
  • Hi Leo,
    We generally discourage posting a new question to an old closed thread because the person who answered before may no longer be available, and also it will allow whomever is currently assigned to monitor the forum to respond to you more quickly. For these reasons, I suggest you start a new thread with your question and reference this thread.

    Thank you