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.

How to resolve hostname of local system

Other Parts Discussed in Thread: SYSBIOS

Hi to all

i am using NDK (2_24_03_35) and sysbios (6_45_01_29) on C6678 EVM and i try to get my hostname (added by CfgAddEntry) using DNSgethostname API (i think must work easily !!! )

but DNSGetHostname() return 19 (NODNSREPLY 19 No DNS server response)

adding DNS server is necessary for getting my hostname ?

anybody can suggest me sample code for this API  or alternative API?

(i hope my question is not very basic)

i attach simple project (modified version of NIMU_emacExample_EVMC6678C66BiosExampleProject ) for reproduct problem.

NIMU_Rebiuld_1.rar

thanks for reading

Ebi

  • Monday's a holiday in US. We'll get to your thread on Tues.

    Todd
  • Hi Ebi,

    As you pointed out, NODNSREPLY means "No DNS server response". The NDK documentation states:

    "When the configuration contains client
    machine records (i.e., controls local domain names), these entries are checked when the matching
    domain is encountered. Otherwise (and for all other queries), the query is resolved via external DNS
    servers."

    If you do not have a DNS server service setup, DNSGetHostname() would try to reach out to external DNS servers. Are you connected to the internet or an internal network where your IP address could be resolved to a hostname by an existing DNS server?

    Best regards,
    Vincent
  • hi 

    thanks for reply and sorry for replying late (i was out of office)

    Vincent W. said:
    If you do not have a DNS server service setup, DNSGetHostname() would try to reach out to external DNS servers. Are you connected to the internet or an internal network where your IP address could be resolved to a hostname by an existing DNS server?

    logically when i try to get my board's hostname , DNSGetHostname() don't need to internet or an internal network (plaese confirm if it's correct) 

    but problem remained  when i connect board to internal network with DNS server and set gateway,DNS server IP.

    NDK document said :

    6.6.1 Operation
    The NDK contains a small DNS resolver that can resolve hostnames and addresses that are local to the
    system via the configuration, or those outside the system by using an external DNS server.

    i think "small DNS resolver" is sufficient for my project

    thanks for support

    Ebi 

  • Hi Ebi,

    Did you enable the DNS Server Service in your BIOS configuration (.cfg) file? It is disabled by default. As per section 6.6,

    "If you are using XGCONF to configure your application, you can configure the DNS server to be enabled
    in the application by checking the box in the property sheet to add the module to your configuration. See
    the SPRU523 (TI Network Developer's Kit (NDK) User's Guide.) and the context-sensitive help for details."

    Best regards,
    Vincent
  • Hi

    thanks for your reply !

    yes i enable DNS Server Service using XGCONF :

    what parameter need to add in  DNS Server Service ?

    (you can re product problem by simple project in my first post )

    thanks 

    Ebi

  • Hi Ebi,

    To give you an update, I was able to reproduce your issue on my end using a different board I have. I'll let you know once I have identified the root cause.

    Best regards,
    Vincent
  • Vincent,

    Thank you very much for your help !

    Ebi

  • Hi Ebi,

    I have analyzed this with our NDK expert, and we think that there could be something wrong with the implementation of DNSGetHostname(). You can workaround the issue for now using this approach:

    char *HostName = "tidsp";
    char hostname_1[128];

    HANDLE hCfg, cfgHandle;
    int rc;
    int cnt;

    /* Add an entry for the hostname */

    CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0, strlen(HostName), (UINT8 *)HostName, 0 );

    /* Get the hostname by retrieving the last entry under CFGITEM_DHCP_HOSTNAME */
    cnt = CfgGetEntryCnt(0, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME);
    if(cnt <= 0)
    {
         printf ("Error: Unable to retrieve entry count.\n");
         return;
    }
    rc = CfgGetEntry(0, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, cnt, &cfgHandle);
    if(rc <= 0)
    {
         printf ("Error: Unable to retrieve CFGTAG_SYSINFO configuration.\n");
         return;
    }
    rc = CfgEntryGetData(cfgHandle, sizeof(hostname_1), hostname_1);
    if (rc <= 0)
    {
         printf("Error in CfgEntryGetData\n");
         return;
    }

    Please let us know if this works for you.

    Thanks,
    Vincent

  • Hi 

    thank you for your time !

    i can get hostname correctly using your suggest code (but with small changes)

    // Add our global hostname to hCfg (to be claimed in all connected domains)
    CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,
    strlen(HostName), (UINT8 *)HostName, 0 );

    //EA: add for get hostname
    /* Get the hostname by retrieving the last entry under CFGITEM_DHCP_HOSTNAME */
    cnt = CfgGetEntryCnt(hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME);
    if(cnt <= 0)
    {
    printf ("Error: Unable to retrieve entry count.\n");
    return;
    }
    rc = CfgGetEntry(hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, cnt, &cfgHandle);
    if(rc <= 0)
    {
    printf ("Error: Unable to retrieve CFGTAG_SYSINFO configuration.\n");
    return;
    }
    hns=sizeof(hostname_1);
    rc = CfgEntryGetData(cfgHandle, &hns, hostname_1);
    if (rc <= 0)
    {
    printf("Error in CfgEntryGetData\n");
    return;
    }

    //

    I try to use BSD code to my NDK project . in BSD code, need hostname for GetHostByName() but DNSGetHostByName API return 19 (NODNSREPLY 19 No DNS server response). 

    i have problem with DNSGetHostxxx API please update this post if you can resolve problem or alternative approach

    (attached file demonstrate the problem)

    7750.helloWorld.c

    thanks a lot !

    Ebi

  • Hi Ebi,

    Could you try to modify your code like this:

    #define SCRAPBUF_SIZE   512

    char *HostName    = "tidsp";
    char hostname_1[128];

    ...

        HANDLE          hCfg;
        HANDLE          cfgEntryHandle;

        int rc;
        int cnt;
        int hns = sizeof(hostname_1);
        char    ScrapBuf_1[SCRAPBUF_SIZE];
        void * pScrapBuf_1 = ScrapBuf_1;

        hCfg = CfgGetDefault();
        if( !hCfg )
        {
            System_printf("Unable to get configuration\n");
        }
        else {
            // Add our global hostname to hCfg (to be claimed in all connected domains)
            CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,
                     strlen(HostName), (UINT8 *)HostName, 0 );

            cnt = CfgGetEntryCnt(hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME);
            if(cnt <= 0)
            {
                printf ("Error: Unable to retrieve entry count.\n");
                return;
            }

            rc = CfgGetEntry(hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, cnt, &cfgEntryHandle);
            if(rc <= 0)
            {
                printf ("Error: Unable to retrieve CFGTAG_SYSINFO configuration.\n");
                return;
            }

            rc = CfgEntryGetData(cfgEntryHandle, &hns, (UINT8 *)hostname_1);
            if (rc <= 0)
            {
                printf("Error in CfgEntryGetData\n");
                return;
            }

            //rc=DNSGetHostname(hostname_1, sizeof(hostname_1));
            printf("DNSGetHostname return = %d host=%s\n",rc, hostname_1);

            rc=DNSGetHostByName(hostname_1, pScrapBuf_1, SCRAPBUF_SIZE);
            printf("DNSGetHostByName return = %d \n",rc);
        }


    DNSGetHostByName() successfully returns 0 for me in this case. The key here is what is in bold. Make sure you are using a scrap buffer that is large enough, and calling cfgGetDefault() to use the default configuration as opposed to creating a brand new one via cfgNew().

    Let us know how it goes.

    Best regards,

    Vincent

  • Hi

    thanks for following and sorry for replying late (i was out of office)

    i correct ScrapBuf_1's type and size !

    when i try to using cfgGetDefault() for system configuration cfgGetDefault() return null :

        rc = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT );
        if( rc )
        {
            platform_write("NC_SystemOpen Failed (%d)\n",rc);
            for(;;);
        }
    
    
        //
        // Create and build the system configuration from scratch.
        //
    
        // Create a new configuration
        hCfg = CfgNew();
        if( !hCfg )
        {
            platform_write("Unable to create configuration\n");
            goto main_exit;
        }
    
        //
        // THIS MUST BE THE ABSOLUTE FIRST THING DONE IN AN APPLICATION!!
        //
        rc = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT );
        if( rc )
        {
            platform_write("NC_SystemOpen Failed (%d)\n",rc);
            for(;;);
        }
    
        // Print out our banner
        platform_write(VerStr);
    
        //
        // Create and build the system configuration from scratch.
        //
    
        // Create a new configuration
        hCfg = CfgGetDefault();//EA: CfgNew();
        if( !hCfg )
        {
            platform_write("Unable to create configuration\n");//EA: <= return Null at this line
            goto main_exit;
        }
    
        // We better validate the length of the supplied names
        if( strlen( DomainName ) >= CFG_DOMAIN_MAX ||
            strlen( HostName ) >= CFG_HOSTNAME_MAX )
        {
            platform_write("Names too long\n");
            goto main_exit;
        }
    
        // Add our global hostname to hCfg (to be claimed in all connected domains)
        CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,
                     strlen(HostName), (UINT8 *)HostName, 0 );
    
    
        /* Get the hostname by retrieving the last entry under CFGITEM_DHCP_HOSTNAME */
        //EA: add for get hostname
    
        cnt = CfgGetEntryCnt(hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME);
        if(cnt <= 0)
        {
             printf ("Error: Unable to retrieve entry count.\n");
             return;
        }
        rc = CfgGetEntry(hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, cnt, &cfgHandle);
        if(rc <= 0)
        {
             printf ("Error: Unable to retrieve CFGTAG_SYSINFO configuration.\n");
             return;
        }
        hns=sizeof(hostname_1);
        rc = CfgEntryGetData(cfgHandle, &hns, hostname_1);
        if (rc <= 0)
        {
             printf("Error in CfgEntryGetData\n");
             return;
        }

    and i using cfgGetDefault() in my task , for getting hostname only

    but problem not resolved and DNSGetHostByName() return 19

    i check stack size and it seem ok !

    i think somethings wrong in DNS config , can you please look at my cfg file and c file?

    thanks

    Ebi

    0677.cfg_file.txt

    8130.helloWorld.c 

  • Hi Ebi,


    In your .cfg file, I see this line:

    Global.enableCodeGeneration = false;


    Did you add this line intentionally to prevent the stack thread from automatically being created? Just wondering if this is a necessary part to your application.

    Best regards,

    Vincent

  • Hi Vincent

    i don't change this line, in NIMU_emacExample_EVMC6678C66BiosExampleProject (from processor_sdk_rtos_c667x_2_00_01_07 ) Global.enableCodeGeneration is false and StackTest() created manually in helloworld.c !

    thanks

    Ebi

  • Hi Ebi,


    By setting Global.enableCodeGeneration to false, you are telling the NDK to avoid auto-generating C code based on the configuration in your .cfg file, which includes the code for a stack thread and for your DNS configuration. I am assuming your application has been providing its own stack thread, which is why it has been able to run.

    Given you want DNS support, you need to set Global.enableCodeGeneration = true. What this means is the stack thread would be automatically created for you in a file under Debug/configPkg/package/cfg/<app_name>_pe66.c. If you open up that file after rebuilding with Global.enableCodeGeneration = true (I'd suggest you save a copy of the file somewhere else for reference later), you'll see a function named "ti_ndk_config_Global_stackThread()". Compare this with your existing stack thread and see if you are missing anything by using the auto-generated one. If not, you are good to go by simply commenting out your own stack thread.


    However, if there are things in your stack thread function that are critical and do not show up in the generated one, you would have to additionally set

        Global.stackThreadUser = <name of your StackTest() function>;

    in your .cfg file to override the generated one. This allows you to keep your existing stack thread function while having *some* code generation at the same time. In this case, you would have to manually call the NDK generated functions as a result of Global.enableCodeGeneration=true in your stack thread function.

    For example, if you have configured DNS settings in your *.cfg, then this results in a generated function call in ti_ndk_config_Global_stackThread() of <app_name>_pe66.c:

        /* add the Dns module configuration settings. */
        ti_ndk_config_dns_init(hCfg);

    You would need to add a call to that function within your own StackTest().  This needs to be repeated for all other NDK modules you may have configured.

    Hope this helps,

    Vincent

  • Hi

    thanks a lot for very useful information ,  I try to modify code according to your suggestion and update this post !

    Best Regards

    Ebi 

  • Hi Vincent 

    i work on problem according to your suggestion and some change in my BSD code.

    now i success to solve problem ( but not completely ) and think can close this post (i don't know why "verify answer" disable for this post !!! ).

    thank you for your support !

    Ebi