Forum Discussion
Altera_Forum
Honored Contributor
15 years ago@ Jakobjones
I have created this following function to change the ethernet's IP address during the TCP/IP connectionint change_ip (int dhcp_actv, NetInfo new_ip)
{
NET p_net;
ip_addr ipaddr, netmask, gw;
p_net = nets; // for multi network interface, check file alt_iniche_dev.c
// Get the new ip address
printf(" Get the new ip address\n");
if(dhcp_actv) p_net -> n_flags |= NF_DHCPC;
else
{
IP4_ADDR( ipaddr, new_ip.ipaddr_in, new_ip.ipaddr_in, new_ip.ipaddr_in, new_ip.ipaddr_in );
IP4_ADDR( netmask, new_ip.netmask_in, new_ip.netmask_in, new_ip.netmask_in, new_ip.netmask_in );
IP4_ADDR( gw, new_ip.gw_in, new_ip.gw_in, new_ip.gw_in, new_ip.gw_in );
p_net -> n_ipaddr = ipaddr;
p_net -> snmask = netmask;
p_net -> n_defgw = gw;
}
netmain_init();
iniche_net_ready = TRUE;
return 0;
}Then after executing the above code, I re-initialize the TCP/IP connection (socket creation, bind, listen, select). The above code could work correctly. However, it only could change the IP address for two times in sequence. In the third times, it would be error. The error message said that the program couldn't find any ethernet card anymore. From debugging my code, I noticed that whenever I assigned a new IP address to my ethernet, the Nios-II thought that as IP address for another ethernet card. Since in the default niche configuration Nios-II only supports for two ethernet cards, in the third times of new IP address assignment, Nios-II will generate error notification. Do you know how to solve this problem? Is there any function to flush the ethernet configuration, such that whenever I assign a new ip address, the Nios will notice it as for the same ethernet card? :( And another question is about the DHCP connection. Since in this current project I want to provide on-fly DHCP / manual IP address assignment, I disable the 'dhcp client' option in the altera niche. For re-initialize DHCP function do you think it is enough by assigning this single code : p_net -> n_flags |= NF_DHCPCOr are there anything else that I need to configure? :confused: Thank you. I'm looking forward any help from you or anyone