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.

Changing IP address after connection has made

Hi

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):

  • I shutdown the socket,
  • set the IP maually as in stackTest function,
  • and then call NC_NetStart

That doesn't work, how can I do it?

Thanks

Aviv

 

 

 

  • Hi Aviv,

    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:

        http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/ndk/nsp_1_10_00_03/index_FDS.html

    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().

    Steve

  • Hi Steve,

    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.

    thanks,

    Aviv

  • Aviv,

    Can you please zip up and attach your (entire) modified project (preferably built) to this thread so I can see your changes?

    Steve

  • 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.

    void ChangeIPAddr()
    {

         CfgRemoveEntry(configHandle, ipEntry);

         CI_IPNET NA;

         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 Address
    and if there is anything else to be considered.

    Best Regards.
    Prad

  • Prad,

    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?

    Steve

  • Hi Steve,

    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?

    Best Regards.
    Prad

  • Hi Prad,

    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 Client
    Welcome connection : 10.90.90.5:57878


    Welcome to the console program.
    Enter '?' or 'help' for a list of commands.

    >ipaddr 1 10.90.90.4 255.0.0.0

    Connection to host lost.

    C:\Users\a0323418>ping 10.90.90.3

    Pinging 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
    ^C
    C:\Users\a0323418>
    C:\Users\a0323418>ping 10.90.90.4

    Pinging 10.90.90.4 with 32 bytes of data:
    Reply from 10.90.90.4: bytes=32 time=1ms TTL=255
    Reply from 10.90.90.4: bytes=32 time=7ms TTL=255
    Reply from 10.90.90.4: bytes=32 time<1ms TTL=255
    Reply from 10.90.90.4: bytes=32 time<1ms TTL=255

    Ping 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 = 2ms

    C:\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 address
    Using MAC Address: 00-12-ab-21-04-79
    00000.000 MAC Address = 00-12-ab-21-04-79

    00000.000 EMAC should be up and running

    00000.000 EMAC has been started successfully

    00000.000 Registeration of the EMAC Successful

    Network Added: If-1:10.90.90.3
        If-1:10.90.90.3
    Service Status: Telnet   : Enabled  :          : 000
    Service Status: Telnet   : Enabled  :          : 000
    Service Status: HTTP     : Enabled  :          : 000
    IPv6 stack has been initialized on 1
    Address: fe80::212:abff:fe21:479 on device 1 is UNIQUE
    Link Status: 100Mb/s Full Duplex on PHY 7
    Network Removed: If-1:10.90.90.3
        If-1:10.90.90.3
    Network 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

    Steve

  • Hi Steve,

    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.

    Best Regards
    Prad.

  • Hi Prad,

    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.

    Steve

  • Aviv,

    Can I see your code to change the IP Address after boot up?

    I need to do the same thing.   

    Any help would be great.

    -Craig

  • Craig,

    You may have missed it, but in the post I made above, I mentioned that the code to do that can be found in the code for the telnet console, that's part of the command for adding/removing an IP address.  Please have a look at that code to see how you can do the same.


    Steve