IP改了,然后 执行tcp_close(iris_pcb);
然后再执行LwIP_Init();
CMD_init();
结果作为client的PC根本就没办法再连上作为服务器的板子了(不管是新设的ip还是以前老的IP)。请各位大虾指点迷津 O(∩_∩)O谢谢
下面是两个函数的具体代码:
void LwIP_Init( void )
{
struct ip_addr ipaddr;
struct ip_addr netmask;
struct ip_addr gw;
/*调用LWIP初始化函数,
初始化网络接口结构体链表、内存池、pbuf结构体*/
lwip_init();
#if LWIP_DHCP //若使用DHCP协议
ipaddr.addr = 0;
netmask.addr = 0;
gw.addr = 0;
#else //
/* //by iris 2013.6.6 //
IP4_ADDR(&ipaddr, 192, 168, 0, 18); //设置网络接口的ip地址
IP4_ADDR(&netmask, 255, 255, 255, 0); //子网掩码
IP4_ADDR(&gw, 192, 168, 0, 1); //网关
*/ //by iris 2013.6.6 //
IP4_ADDR(&ipaddr, 192, 168, 1, 18); //设置网络接口的ip地址
IP4_ADDR(&netmask, 255, 255, 255, 0); //子网掩码
IP4_ADDR(&gw, 192, 168, 1, 1); //网关
#endif
/*初始化enc28j60与LWIP的接口,参数为网络接口结构体、ip地址、
子网掩码、网关、网卡信息指针、初始化函数、输入函数*/
netif_add(&enc28j60, &ipaddr, &netmask, &gw, NULL, ðernetif_init, ðernet_input);
/*把enc28j60设置为默认网卡 .*/
netif_set_default(&enc28j60);
#if LWIP_DHCP //若使用了DHCP
/* Creates a new DHCP client for this interface on the first call.
Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at
the predefined regular intervals after starting the client.
You can peek in the netif->dhcp struct for the actual DHCP status.*/
dhcp_start(&enc28j60); //启动DHCP
#endif
/* When the netif is fully configured this function must be called.*/
netif_set_up(&enc28j60); //使能enc28j60接口
}
struct tcp_pcb *pcb; //定义一个tcp控制块
/* Create a new TCP control block */
pcb = tcp_new(); //给tcp控制块分配内存空间
/* Assign to the new pcb a local IP address and a port number */
/* Using IP_ADDR_ANY allow the pcb to be used by any local interface */
tcp_bind(pcb, IP_ADDR_ANY, 23); //把PCB控制块绑定到本机的所有IP地址,端口为23
/* Set the connection to the LISTEN state */
pcb = tcp_listen(pcb); //监听该端口
/* Specify the function to be called when a connection is established */
tcp_accept(pcb, CMD_accept); //监听的端口接通后调用的函数HelloWorld_accept
iris_pcb=pcb; //the mathod is wrong //by iris 2013.6.3
}