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.

Unable to Set DNS IP

Other Parts Discussed in Thread: EK-TM4C1294XL

MCU: TM4C1294NCPDT

TI-RTOS: v2.01.00.03

NDK: v2.23.01.01

CCS: v6.0.1.0040

-

Hi,

I have the following code setup, still I am unable to set the DNS IP to be used by NDK. In the task "someTaskFxn()", the console is printing "CfgGetImmediate(DNS) = 0" & "DNS IP = 255.255.255.255" & "DNSGetHostByName = 19".

SECTION OF THE .cfg FILE:

EMAC.libType = EMAC.LibType_NonInstrumented;
Global.IPv6 = false;
Ip.autoIp = true;
Ip.address = "";
Ip.mask = "255.255.255.0";
Ip.gatewayIpAddr = "192.168.1.2";
Ip.domainName = "domain.com";
var http0Params = new Http.Params();
var http0 = Http.create(http0Params);
Global.lowTaskPriLevel = 3;
Global.stackInitHook = "&AddWebFiles";
Global.stackDeleteHook = "&RemoveWebFiles";
Global.networkIPAddrHook = "&mynetworkIPAddrHook";
Global.networkOpenHook = "&functionNetworkOpenHook";

SECTION of the .c FILE:


Void functionNetworkOpenHook(Void)
{
char *HostName = "_csl_";
IPN IPTmp;

if(usr_s.eth_dhcp_enabled == true)
{
System_printf("NetworkOpenHook: DHCP EN\n");
}

else
{
System_printf("NetworkOpenHook: DHCP DIS, (%s,%s,%s)\n", usr_s.eth_static_ip, usr_s.eth_subnet_mask, usr_s.eth_gateway);

CI_IPNET NA;
CI_ROUTE RT;

HANDLE hCfgIpAddr, hCfg;

/* Setup manual IP address */
bzero(&NA, sizeof(NA));
NA.IPAddr = inet_addr(usr_s.eth_static_ip);
NA.IPMask = inet_addr(usr_s.eth_subnet_mask);
strcpy(NA.Domain, "demo.net");
NA.NetType = 0;

/* get the current static IP entry */
CfgGetEntry(0, CFGTAG_IPNET, 1, 1, &hCfgIpAddr);

/* remove the current static IP entry */
CfgRemoveEntry(0, hCfgIpAddr);

/* add a new static IP entry */
CfgAddEntry(0, CFGTAG_IPNET, 1, 0,
sizeof(CI_IPNET), (UINT8 *)&NA, 0);

// Add the default gateway.

bzero( &RT, sizeof(RT) );
RT.IPDestAddr = 0;
RT.IPDestMask = 0;
RT.IPGateAddr = inet_addr(usr_s.eth_gateway);

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

// Add the route
CfgAddEntry( hCfg, CFGTAG_ROUTE, 0, 0, sizeof(CI_ROUTE), (UINT8 *)&RT, 0 );

// Manually add the DNS server when specified
IPTmp = inet_addr("192.168.1.5");
if(IPTmp)
{
CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER,
0, sizeof(IPTmp), (UINT8 *)&IPTmp, 0 );
}

}

}


void mynetworkIPAddrHook(IPN IPAddr, uint IfIdx, uint fAdd)
{
IPN IPTmp;int rc = 0;

CI_IPNET NA;
char IPString[16];

/* Initialize the IP Address block. */
bzero (&NA, sizeof(CI_IPNET));

if(fAdd)

{
System_printf("networkIPAddrHook: Network Added");
}
else
{
System_printf("networkIPAddrHook: Network Removed");
}

IPTmp = ntohl(IPAddr);
System_printf("networkIPAddrHook:\tIf-%d:%d.%d.%d.%d\n", IfIdx,
(UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF,
(UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF);

sprintf(current_ip, "%d.%d.%d.%d", (UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF, (UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF);

/* Print the IP address information only if one is present. */
if (CfgGetImmediate( 0, CFGTAG_IPNET, 1, 1, sizeof(NA), (UINT8 *)&NA) == sizeof(NA))
{
/* Yes the device was configured and we got the IP address/Mask */
NtIPN2Str (NA.IPAddr, IPString);
System_printf("IP Address: %s\n", IPString);
NtIPN2Str (NA.IPMask, IPString);
System_printf("IP Subnet Mask: %s\n", IPString);
}
else
{
System_printf("IP Address & SUBNET MASK NOT AVAILABLE\n");
}

if(1)

{
rc = CfgGetImmediate( 0, CFGTAG_SYSINFO,
CFGITEM_DHCP_DOMAINNAMESERVER,
1, 4, (UINT8 *)&IPTmp );
if(rc == 4)
{
System_printf("networkIPAddrHook:\tIf-%d: DNS = %d.%d.%d.%d\n", IfIdx,
(UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF,
(UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF);
}
else
{
System_printf("networkIPAddrHook: DNS IP Fetch Failed!!\n");
}
}

}

Void someTaskFxn(UArg arg0, UArg arg1)
{

HOSTENT host;
IPN IPTmp;

while(1)

{

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\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)));

}

}

Regards

Soumyajit

  • Soumyajit,

    This looks similar to e2e.ti.com/.../1903623 question of yours.

    I am working on it with our NDK expert. I will get to this question as soon as I finish the other thread of yours.

    Vikram
  • Ok. Thanks.
    -
    Regards
    Soumyajit
  • I have answered your DNS questions in your other post. e2e.ti.com/.../1905854

    Please mark this thread answered if you have all the information you need.

    Vikram
  • Hi Vikram,

    With reference to the code posted at the beginning of this thread, can you please check and inform me how I can add the DNS server IP in the configuration so that the NDK can use the DNS. (Note: DHCP is disabled for this mode)

    -

    Thanks

    -

    Regards

    Soumyajit

  • Hi Soumyajit,

    Have you tried calling CfgAddEntry() to set the DNS IP (for no DHCP case) and then calling CfgGetImmediate() to get the entry?

    Please look at the other thread for code snippets for these functions. Also, I would recommend using the telnet console code as a reference for configuring NDK at runtime which has code that you can reuse. You can also refer to NDK Programmer's Guide for detailed description about these functions.

    Vikram
  • Hi Vikram,

    Thanks for your reply. Yes, I have called CfgAddEntry() to set the DNS IP (DHCP disabled mode) & then called CfgGetimmediate() [please see the post at the beginning of this thread]. But, I don't know why "CfgGetImmediate( 0, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER, 1, 4, (UINT8 *)&IPTmp )" is returning 0.

    Can you please tell me any diagnostic procedure or where to or what to look for ahead?

    I even tried putting "Dns.externDnsServIp = "192.168.1.5";" in the .cfg file (after rebuilding the NDK) & removing "CfgAddEntry()" in code, but still "CfgGetimmediate()" is returning zero.

    -

    Thanks

    -

    Regards

    Soumyajit

  • Hi Soumyajit,

    I talked to our NDK expert who says the telnet code uses the same API to get the DNS IP. Can you share a test code that can recreate the issue? We can try running it on our set-up.

    Vikram
  • Hi Vikram,

    Ok. I'll guide you in setting up the issue for analysis.

    1. Open a project in TI RTOS on Tiva C for EK-TM4C1294XL

    2. Implement the HTTP Web Server Example following this link 

    3. In the .cfg file, make sure Ip.autoIp is set to true. (System will change the DHCP to disabled via function "functionNetworkOpenHook", explained later)

    4. Add these two lines in the .cfg file: "Global.networkIPAddrHook = "&mynetworkIPAddrHook";" & "Global.networkOpenHook = "&functionNetworkOpenHook";"

    5. For the functions "mynetworkIPAddrHook" & "functionNetworkOpenHook", see the attached .c file

    6. Declare a new task named "testTaskFxn()" & enable it from the .cfg file. See the attached .c file for the function "testTaskFxn()"

    7. Observe whether the system can get the IP of google.com or not (in my observation, "DNSGetHostByName()" was returning 19)

    8. After all looks fine, you can declare another task named "tcpOutgoingTaskFxn()" & see whether this task is able to connect to some external IP. This task function is also provided in the attached .c file

    9. Also you can observe the console/debug printout of function "DumpRouteTable()".

    Regards

    Soumyajit

    ------

    Attached ndk.c

    2364.ndk.c

  • HI Soumyajit,

    It would have been faster if I had an example that I could build easily. Anyways, I will set-up the code as detailed in your steps and get back to you with my findings.

    Vikram
  • Thanks Vikram. Am waiting to hear from you soon.
    -
    Regards
    Soumyajit
  • Soumyajit,

    I looked at your code and found the issue. If you would like to read your set DNS IP address in networkIPAddr hook function, set the DNS IP address before setting the static IP address. This is because setting IP address would immediately call the networkIPAddr hook to inform addition of an IP. 

    Here is a snippet of the code:

    void netOpenHook()
    {
    	IPN IPTmp;
    	CI_IPNET NA;
    	HANDLE hCfgIpAddr;
    	HANDLE hCfg;
        int ret;
    
    	hCfg = CfgGetDefault();
    	if (!hCfg) {
    		System_abort("Couldn't fetch handle\n");
    	}
    
    	ret = CfgGetEntryCnt(hCfg, CFGTAG_IPNET, 1);
    	System_printf("Static IP count: %d\n", ret);
    
    	/* get the current static IP entry */
    	if (CfgGetEntry(hCfg, CFGTAG_IPNET, 1, 1, &hCfgIpAddr)) {
     		/* remove the current static IP entry */
    		if (CfgRemoveEntry(hCfg, hCfgIpAddr) < 0) {
    			System_abort("Couldn't remove static IP entry\n");
    		}
    	}
    	else {
    		System_printf("Couldn't get static IP entry\n");
    	}
    
        // Manually add the DNS server when specified
    	IPTmp = inet_addr("192.168.1.5");
    	if(IPTmp)
    	{
    		if(CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER,
    				0, sizeof(IPTmp), (UINT8 *)&IPTmp, 0 ) < 0) {
    			System_abort("Couldn't add static IP entry\n");
         	}
    
    	}
    	else {
    		System_printf("Couldn't add DNS IP\n");
    	}
    
    	/* Setup manual IP address */
    	bzero(&NA, sizeof(NA));
    	NA.IPAddr  = inet_addr("192.168.1.180");
    	NA.IPMask  = inet_addr("255.255.255.0");
    	strcpy(NA.Domain, "demo.net");
    	NA.NetType = 0;
    
    	/* add a new static IP entry */
    	if (CfgAddEntry(hCfg, CFGTAG_IPNET, 1, 0,
    				sizeof(CI_IPNET), (UINT8 *)&NA, 0) < 0) {
    		System_abort("Couldn't add static IP entry\n");
    	}
    
    }
    
    void mynetworkIPAddrHook(IPN IPAddr, uint IfIdx, uint fAdd)
    {
        IPN IPTmp;
        CI_IPNET    NA;
        HANDLE hCfg;
    	int rc = 0;
        char IPString[16];
    
    	hCfg = CfgGetDefault();
    
        /* Initialize the IP Address block. */
        bzero (&NA, sizeof(CI_IPNET));
    
    	if(fAdd) {
    	    System_printf("networkIPAddrHook: Network Added\n");
    	}
    	else {
    	    System_printf("networkIPAddrHook: Network Removed\n");
    	}
    
        IPTmp = ntohl(IPAddr);
        System_printf("networkIPAddrHook:\tIf-%d:%d.%d.%d.%d\n", IfIdx,
                (UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF,
                (UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF);
    
        /* Print the IP address information only if one is present. */
        if (CfgGetImmediate(hCfg, CFGTAG_IPNET, 1, 1, sizeof(NA), (UINT8 *)&NA) == sizeof(NA))  {
            /* Yes the device was configured and we got the IP address/Mask */
            NtIPN2Str (NA.IPAddr, IPString);
            System_printf("IP Address: %s\n", IPString);
            NtIPN2Str (NA.IPMask, IPString);
            System_printf("IP Subnet Mask: %s\n", IPString);
        }
        else {
            System_printf("IP Address & SUBNET MASK NOT AVAILABLE\n");
        }
    
         rc = CfgGetImmediate(hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER,
        		 1, 4, (UINT8 *)&IPTmp );
         if (rc == 4) {
            IPTmp = ntohl(IPTmp);
    		System_printf("networkIPAddrHook:\tIf-%d: DNS = %d.%d.%d.%d\n", IfIdx,
    				(UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF,
    				(UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF);
    	}
    	else {
    	    System_printf("networkIPAddrHook: DNS IP Fetch Failed!!\n");
    	}
    
        System_flush();
    }
    

    And here is the output that see:

    Service Status: DHCPC : Enabled : : 000
    Static IP count: 0
    Couldn't get static IP entry
    Network Added: If-1:192.168.1.180
    networkIPAddrHook: Network Added
    networkIPAddrHook: If-1:192.168.1.180
    IP Address: 192.168.1.180
    IP Subnet Mask: 255.255.255.0
    networkIPAddrHook: If-1: DNS = 192.168.1.5
    Service Status: DHCPC : Enabled : Running : 000

    I hope this answers your question.

    Vikram

  • Thanks Vikram, this answers my question.
    -
    Regards
    Soumyajit