Home/Support/Support Forum/migrating from 9.62 to 10.72 cannot find sethostid()
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

migrating from 9.62 to 10.72 cannot find sethostid()

0 votes
asked Nov 12, 2015 in Rabbit by rzanotta New to the Community (1 point)

Please log in or register to answer this question.

1 Answer

+1 vote
 
Best answer
The function sethostid(), was removed from DC10.72 if you are trying to change the address at runtime you can do this with ifconfig(), see sample below:


This is an easy way to set the Network settings of a device using the
ifconfig() function and shows how to bounce the connection.

*******************************************************************************/

/*
* The following macros define the network setup of the physical Ethernet
* interface.
*/

#define LOCAL_IP1 "192.168.1.197"
#define LOCAL_NETMASK "255.255.255.0"
#define LOCAL_GATEWAY "192.168.1.1"

#define LOCAL_IP2 "192.168.1.198"

/*
* USE_ETHERNET must be defined. This definition simply means that we are
* using the first (and probably only) physical Ethernet interface.
*/
#define USE_ETHERNET 0x01

/*
* NOTE: Since we are setting up the network manually, we are
* intentionally NOT using the TCP_CONFIG.LIB setup.
*/
#define TCPCONFIG 0

#memmap xmem
#use "dcrtcp.lib"


void display_config(void)
{
auto longword ipaddr;
auto longword netmask;
auto longword gateway;
auto char addr_buffer[16];

ifconfig(IF_DEFAULT,
IFG_IPADDR, &ipaddr,
IFG_NETMASK, &netmask,
IFG_ROUTER_DEFAULT, &gateway,
IFS_END);
printf("Your current configuration is:\n");
printf("IP Address: %s\n", inet_ntoa(addr_buffer, ipaddr));
printf("Netmask : %s\n", inet_ntoa(addr_buffer, netmask));
printf("Gateway : %s\n", inet_ntoa(addr_buffer, gateway));
}


void main(void)
{
char Network_Up_Flag; //Flag used to reset the network
char IP_buffer[16];

strcpy(IP_buffer, LOCAL_IP1);

//Initialize the TCP/IP stack
sock_init();

//This primary loop handles setting and bouncing the network settings
while(1)
{
//Perform network configuration with second configuration
printf("Bringing up Main Interface \n");
ifconfig(IF_ETH0,
IFS_IPADDR, aton(IP_buffer),
IFS_NETMASK, aton(LOCAL_NETMASK),
IFS_ROUTER_SET,aton(LOCAL_GATEWAY),
IFS_UP,
IFS_END);

// Wait for the interface to come up
while (ifpending(IF_ETH0) == IF_COMING_UP) {
tcp_tick(NULL);
}
printf("Interface is up!!\n\n");
Network_Up_Flag = 1;

display_config();

//This secondary loop is used to drive the stack and monitor the
//network status. It provides an easy mechanism for bouncing the
//connection.
while (Network_Up_Flag)
{
costate //Drive the TCP stack
{
tcp_tick(NULL);
}

costate //This could be a test that determines the status of the network
{
waitfor(DelayMs((1000)*10)); //bounce network after 10 sec delay
Network_Up_Flag = 0;
if (strcmp(LOCAL_IP1, IP_buffer) == 0)
strcpy(IP_buffer, LOCAL_IP2);
else
strcpy(IP_buffer, LOCAL_IP1);
}
}

// Bring down the main Ethernet interface
printf("Bringing down Main Interface!!\n");
ifconfig(IF_ETH0,
IFS_DOWN,
IFS_END);

// Wait for the interface to come down
while (ifpending(IF_ETH0) != IF_DOWN) {
tcp_tick(NULL);
}
printf("Interface is down!!\n\n");
}
}
answered Nov 12, 2015 by Campbell Veteran of the Digi Community (552 points)
selected Nov 13, 2015 by rzanotta
...