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