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.

Problem on using DNSGetHostname()

Other Parts Discussed in Thread: TMS320C6678

Hi to all

i try to test  DNSGetHostname() in NIMU_emacExample from PDK_c667x_2.0.0 (my device and packages: TMS320c6678  ccs 6.1.2 bios_6_45_01_29 ndk_2_24_03_35)

NDK document said : "This function is quite similar to BSD's gethostname()" and i add DNSGetHostname() before NC_NetStart() :

    char hostname_1[128];
    hostname_1[127] = '\0';
    int rc_3;
...

    //EA: test gethostname
    rc_3=DNSGetHostname(hostname_1, sizeof(hostname_1));
    //
    //
    // Boot the system using this configuration
    //
    // We keep booting until the function returns 0. This allows
    // us to have a "reboot" command.
    //
    do
    {
        rc = NC_NetStart( hCfg, NetworkOpen, NetworkClose, NetworkIPAddr );
    } while( rc > 0 );

i expect see "tidsp" in hostname_1 ,but buffer is empty and  return value is 0 !

i can't find any example or E2E post about DNSGetHostname . anybody can help me how to use this function?

thanks

Ebi

  • Dear Ebi,
    Let me try this at my end and update you!
  • Titus,

    thank you very much for your support !

    some more info:

    this is body of function :

    /*-------------------------------------------------------------------- */
    /* DNSGetHostname */
    
    /* Requests the hostname which matches the IPHost supplied to SetConfig, */
    /* or uses the first IP address found in the system if SetConfig was */
    /* not supplied with a host address. The hostname is copied into the */
    /* buffer pointed to by 'pNameBuf' with a max size of 'size'. */
    /* NULL terminates the name when space allows. */
    
    /* Returns 0 if OK, or error code */
    /*-------------------------------------------------------------------- */
    int DNSGetHostname( char *pNameBuf, int size )
    {
        IPN    IPAddr = 0;
        char   *tmpbuf;
        int    errcode;
    
        /* This call is just about the same as DNSGetHostByAddr, only */
        /* with our IP address. */
    
        /* Get the best IP address for this system */
        /* If we don't have an IP address, then don't copy a name */
        if( !NtGetPublicHost( &IPAddr, 0, 0 ) )
        {
            if( size > 0 )
                *pNameBuf = 0;
            return(0);
        }
    
        /* Allocate a scrap buffer for the resolver */
        tmpbuf = mmAlloc( 1024 );
        if( !tmpbuf )
            return( MEMERROR );
    
        /* Now we can call DNSGetHostByAddr */
        errcode = DNSGetHostByAddr( IPAddr, tmpbuf, 1024 );
    
        /* If there's no error, copy the name (if we have one) */
        if( !errcode )
        {
            HOSTENT *ph = (HOSTENT *)tmpbuf;
    
            if( strlen( ph->h_name ) < (uint)size )
                strcpy( pNameBuf, ph->h_name );
            else
                strncpy( pNameBuf, ph->h_name, size-1 );
        }
    
        /* Free the temp buffer */
        mmFree( tmpbuf );
    
        return( errcode );
    }

    and i think value return from this part:

        if( !NtGetPublicHost( &IPAddr, 0, 0 ) )
        {
            if( size > 0 )
                *pNameBuf = 0;
            return(0);
        }

    i check this function separately and see IPAddr is empty although in run time , i can ping EVM ip without problem  ! 

    thanks

    Ebi

  • Hi  and others

    by create a thread and call NtGetPublicHost() after NC_netStart() , i can get IP correctly but DNSGetHostname() return 19 (NODNSREPLY 19 No DNS server response) .

    i work on this problem and glad to hear your suggestions...

    thanks

    Ebi

  • Hi

    after some effort , i stop work on problem because i think hostname not necessary for my project !

    but i need DNSGetHostname() now.

    any update for this problem?

  • update:

    more info : i using static ip 

    char *HostName    = "tidsp";
    char *LocalIPAddr = "170.170.170.35";//EA: 192.168.1.4 -> 192.168.5.8
    char *LocalIPMask = "255.255.255.0";    // Not used when using DHCP
    char *GatewayIP   = "170.170.170.1";    // Not used when using DHCP EA: 192.168.1.1 -> 192.168.5.1
    char *DomainName  = "demo.net";         // Not used when using DHCP
    char *DNSServer   = "0.0.0.0";          // Used when set to anything but zero
    char *PC_IPAddr = "170.170.170.17";

    i try to add external DNS server to my project by setting the "External DNS server address" in XGConf's "TI-RTOS->Products->NDK->Application Layer->DNS-Module Settings" page .related line in .cfg :

    //Dns.externDnsServIp = "8.8.8.8";
    Dns.externDnsServIp = "170.170.170.1";
    var dns0Params = new Dns.Params();
    dns0Params.IfIdXValid = true;
    dns0Params.mode = 15;
    dns0Params.ResolveIP = true;
    dns0Params.CallByIP = true;
    dns0Params.RestartIPTerm = true;
    var dns0 = Dns.create(dns0Params);

    but DNSGetHostname() return 19 . i attach simple project (modified version of NIMU_emacExample_EVMC6678C66BiosExampleProject ) for reproduct problem.

    NIMU_Rebiuld_1.rar

    thanks

    Ebi

  • Hi again

    some more info:

    i think after change from dhcp to static IP i forget some config

    in G.3.7 section of NDK spru524i.pdf said :

    "First, when the standard DHCP client is executing, it will take full control over the first 256 Item values. It

    fills in the entries when it obtains its address lease, and purges them when the lease expires. There is a
    set of default entries that the DHCP client will always request. Additional information requests can be
    made by configuring the DHCP client, and the resulting replies will be added to the configuration.
    Second, when there is no DHCP client service, the network application must manually write values to the
    configuration for the Item values it views as important. A minimum configuration would include hostname,
    domain name, and a list of domain name servers. Note that multiple IP addresses should be stored as
    multiple instances of the same Item, not concatenated together with a longer byte length."

    any body can suggest me example for add manually config host name?

    in this E2E post problem solved by increase stack size but my stack size seem OK

    thanks

    Ebi

  • Hi to all

    i continue working on problem at this post:

    Best Regards

    Ebi

     

  • Ebi,

    Thank you so much for the link & update. This will definitely help other community members too.