TI E2E Community
Changing IP address after connection has made
I have c6678, NDK 2.20.04.26, SYS/BIOS 6.32.05.54,
I am trying to change IP address in client example after connection has made. (in dtask_tcp_echo function):
That doesn't work, how can I do it?
You would need to add the new IP address you want to the NDK's configuration database, save the configuration, reboot the stack and then load the saved configuration.
For example, to add a static IP to the NDK configuration, the code would look something like the following:
// Setup manual IP address bzero( &NA, sizeof(NA) ); NA.IPAddr = IpAddr; NA.IPMask = IpMask; strcpy( NA.Domain, Domainname ); NA.NetType = 0; // Add the address to interface 1 CfgAddEntry( hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (UINT8 *)&NA, 0 );
Have you seen the NDK example "cfgdemo"?
That example shows how to change the IP address of a running application via a web browser interface. Do you have that example sitting next to your "client" example?
If not, you can get the cfgdemo application from the evmOMAPL138 NSP. This is for a different platform, but you can still view the example code or even port it to the 6678 if you like.
You can find the NSP download here:
The file you will be interested in is "webpage.c" and the function that handles the new IP address received from the web page is cgiCfgDone().
I did My project based on client example, in dtask_tcp_echo I created a task (with lower priority than the current task priority) that calls BuildConfig() as in webpage.c in cfgdemo,
and then in dtask_tcp_echo function i wrote the following code:
fdClose( ) // Close the socket
NC_NetStop(1) // Request stack reboot
TaskDestroy() //Destroy the current task
that doesn't work.
Can you please zip up and attach your (entire) modified project (preferably built) to this thread so I can see your changes?
Hi, We need some advice on the same topic about dynamic IP Address change i.e Changing IP address while running.(Device used DM6435 + NDK 2.0)
We would like to know whether the below procedure to change the IP address is proper or not.
bzero(&NA, sizeof(NA)); NA.IPAddr = inet_addr(defaultIPAddr); // IP Address NA.IPMask = inet_addr(subNetMask); // Subnet Mask strcpy(NA.Domain, " "); // full domain name NA.NetType = 0;
int ret = CfgAddEntry(configHandle, CFGTAG_IPNET, 1, 0,sizeof(CI_IPNET),(Uchar *)&NA, &ipEntry);}
This setting seems to be working for us but, sometimes we get communication problem after changing the IP address so we would like to make sure if the above settings is proper to change the IP Addressand if there is anything else to be considered.
What communications problems are you seeing? Is it due to sockets that were opened on the old IP address still being open and used for communication?
Have you analyzed the communication problems in Wireshark?
Thank you so much for the response.
Actually the communication itself is stopped after changing the IP address.There are times when the communication is proper and times when communication is stopped.
We are confused whether it is necessary to reboot the stack after changing the IP address.In our case we didn't reboot the stack in order to save the time.
According to your comment above it seems there is a need to reboot the stack."You would need to add the new IP address you want to the NDK's configuration database, save the configuration, reboot the stack and then load the saved configuration."
And you have mentioned about NDK example "cfgdemo" above,should we change our code according to this example code?
It's actually not necessary to reboot the stack in order to add a new IP address. I may have been referring to the functionality of the cfgdemo example itself in that post (or just had it wrong :)
There is actually an example of removing and adding an IP address - it's part of the NDK's Telnet console. If you are able to run the client example (or have the Telnet console linked into your application) you can do this using the 'ipaddr' command.
Here's the Telnet console output I got when running that (the original address was 10.90.90.3):
TCP/IP Stack Example ClientWelcome connection : 10.90.90.5:57878Welcome to the console program.Enter '?' or 'help' for a list of commands.>ipaddr 1 10.90.90.4 255.0.0.0Connection to host lost.C:\Users\a0323418>ping 10.90.90.3Pinging 10.90.90.3 with 32 bytes of data:Reply from 10.90.90.5: Destination host unreachable.Ping statistics for 10.90.90.3: Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),Control-C^CC:\Users\a0323418>C:\Users\a0323418>ping 10.90.90.4Pinging 10.90.90.4 with 32 bytes of data:Reply from 10.90.90.4: bytes=32 time=1ms TTL=255Reply from 10.90.90.4: bytes=32 time=7ms TTL=255Reply from 10.90.90.4: bytes=32 time<1ms TTL=255Reply from 10.90.90.4: bytes=32 time<1ms TTL=255Ping statistics for 10.90.90.4: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 7ms, Average = 2msC:\Users\a0323418>
And here's the application output. Notice the 10.90.90.3 address was removed, and the ".4" address was added.
[ARM9_0] Using default MAC addressUsing MAC Address: 00-12-ab-21-04-7900000.000 MAC Address = 00-12-ab-21-04-7900000.000 EMAC should be up and running00000.000 EMAC has been started successfully00000.000 Registeration of the EMAC SuccessfulNetwork Added: If-1:10.90.90.3 If-1:10.90.90.3Service Status: Telnet : Enabled : : 000Service Status: Telnet : Enabled : : 000Service Status: HTTP : Enabled : : 000IPv6 stack has been initialized on 1Address: fe80::212:abff:fe21:479 on device 1 is UNIQUELink Status: 100Mb/s Full Duplex on PHY 7Network Removed: If-1:10.90.90.3 If-1:10.90.90.3Network Added: If-1:10.90.90.4 If-1:10.90.90.4
At this point, I was able to ping and telnet back into the NDK host using the newly added ".4" address.
You can see the code for the ipaddr command in the NDK under ti/ndk/tools/console/conipaddr.c
Thank you very much.Your support is greatly appreciated.
We shall modify the code according to the ndk->example->network->client example.
Just as an information we would like to know what could be the consequences if there are sockets that were opened on the old IP address.As you mentioned a above "Is it due to sockets that were opened on the old IP address still being open and used for communication?"Please let us know if there is any information about what happens in this case.
While I don't know of any exact symptoms in particular, I was imagining that if you had an app that was sending and receiving data to/from the NDK, say in a Task, and that Task failed to close the socket and then there was an IP address change, then I would expect to see communication problems with such a transfer.
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.