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.

change static IP address in NDK 2.24.02.31

Hello

I am using TIRTOS 2_12_01_33 with NDK 2_24_02_31 and wish to be able to change the static IP of my Ethernet port on the fly.

I have been able to set the static IP on start up by

bzero(&NetAddr, sizeof(NetAddr));

NetAddr.IPAddr = htonl(IpLocalConfig.IPaddress);

NetAddr.IPMask = htonl(IpLocalConfig.IPnetmask);

strcpy(NetAddr.Domain, (char *)IpLocalConfig.domain);

NetAddr.NetType = 0;

// Add the new static IP entry
CfgAddEntry(hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (UINT8 *)&NetAddr, 0);


However when I try to change the static IP using

					hCfg = 0;

					binding = BindGetFirst();
					if (binding)
					{
						// get the current static IP entry
						CfgGetEntry(hCfg, CFGTAG_IPNET, 1, 1, &hCfgIpAddr);

						if (hCfgIpAddr)
						{
							if (SystemStatus.DiagState & DIAG_ETHERNET)
								LogDiagMessage("ETH  Change IP Address");
							// Remove the current static IP entry
							CfgRemoveEntry(hCfg, hCfgIpAddr);

							// Add the new static IP entry
							CfgAddEntry(hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (UINT8 *)&NetAddr, 0);
                                                }
}

I find this works sometimes and not others.

Also I have a PPP session up at the same time and I don't know if this is correctly taking that into account?

How do I correctly determine the existing static route config and replace with a new one?

Thanks in advance for any assistance.




  • Worked it out (At least this works for me)

    Here is how I did it in case anyone else wants to know

    .

      CI_IPNET 		NetAddr;
      CI_IPNET 		CurrentAddr;
      int	rc;
      int	size;
      HANDLE      hCfgIpAddr;
      HANDLE 			hCfg;
    
    
    					//  hCfg = CfgGetDefault();
    					//  CfgExecute(hCfg, 0);
    					hCfg = 0;
    
    					// get the current static IP entry
    					rc = CfgGetEntry(hCfg, CFGTAG_IPNET, 1, 1, &hCfgIpAddr);
    
    					// If we already have a route for Ethernet
    					if (rc > 0)
    					{
    						while (rc > 0)
    						{
    							size = sizeof(CurrentAddr);
    							rc = CfgEntryGetData(hCfgIpAddr, &size, (uint8_t *)&CurrentAddr);
    
    							// this was our existing static IP
    							if (CurrentAddr.IPAddr == NetAddr.IPAddr)
    							{
    								// Setup Static IP address
    								bzero(&NetAddr, sizeof(NetAddr));
    								NetAddr.IPAddr  = htonl(IpLocalConfig.IPaddress);
    								NetAddr.IPMask  = htonl(IpLocalConfig.IPnetmask);
    								strcpy(NetAddr.Domain, (char *)IpLocalConfig.domain);
    								NetAddr.NetType = 0;
    
    								if (SystemStatus.DiagState & DIAG_ETHERNET)
    									LogDiagMessage("ETH  Change IP Address");
    
    								// Remove the current static IP entry
    								CfgRemoveEntry(hCfg, hCfgIpAddr);
    
    								// Add the new static IP entry
    								CfgAddEntry(hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (UINT8 *)&NetAddr, 0);
    								break;
    							}
    							else
    								rc = CfgGetNextEntry(0, hCfgIpAddr, &hCfgIpAddr);
    						}
    					}
    				}
    
    				// We didn't have a static IP
    				if (rc <= 0)
    				{
    					if (SystemStatus.DiagState & DIAG_ETHERNET)
    						LogDiagMessage("ETH  Add Static IP Address");
    					// Add the new static IP entry
    					CfgAddEntry(hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (UINT8 *)&NetAddr, 0);
    				}
    

    This adds my initial static IP on start up and if I change the IP address it removes the old one and replaces with the new value.

  • Glad to see this was resolved.