Hello ,
I am working on a project using Tiva, TM4C1294NCPDT MCU ON TIRTOS environment and uses NDK module for TCP client application. My application use static ip connection and I am enter this address in to .cfg file. tcp-echo application is works fine with any ip address entered on .cfg files.
But I want to change ip to be enter in run time. I am already done with following which was posted on one of your portal and tried but it is not connected with new ip. .
- use the NDK hook "Network open hook" instead of "Stack begin hook" for 'readIPAddr()'
- find and remove the static IP address that's initially added (unbind it from the interface)
- add the new IP address (bind a new one)
Here's the updated code I used to do this (covers steps 2 + 3 above). You can change it to read and use the IP address in ROM:
CI_IPNET NA;
HANDLE hCfgIpAddr;
/* Setup manual IP address */
bzero(&NA, sizeof(NA));
NA.IPAddr = inet_addr("172.16.10.2");
NA.IPMask = inet_addr("255.255.255.0");
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);
I have added above routine on netOpenHook function(tcp-eco sample code) which is already Network open hook function.
On console following is displayed where 172.16.10.1 is .cfg ip address and 172.16.10.2 is new ip.
Network Added: If-1:172.16.10.1
Network Removed: If-1:172.16.10.1
Network Added: If-1:172.16.10.2
Strange behavior is this new ip is getting ping on cmd prompt but when is connected to hyper terminal is it not connected. The accept function is not return the connection. Why is it so? When this above routin is comment form netOpenHook function , it is connected to .cfg ip address(i.e 172.16.10.1)