完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我的板子是作为服务器的程序,移植的lwip 我想能够在程序运行过程中重新修改服务器自身的ip地址,可是试了几次还是不行,首先我直接把程序中的 IP4_ADDR(&ipaddr, 192, 168, 1, 18); //设置网络接口的ip地址 IP4_ADDR(&netmask, 255, 255, 255, 0);//子网掩码 IP4_ADDR(&gw, 192, 168, 1, 1);//网关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} |
|
相关推荐
2个回答
|
|
|
你好,我现在也在做这方便的内容,不知道你的功能实现了没?你是通过什么机制修改IP的呢?是外部有个命令触发吗?
|
|
|
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
929 浏览 0 评论
如何使用STM32+nrf24l01架构把有线USB设备无线化?
3089 浏览 7 评论
请问能利用51单片机和nRF24L01模块实现实时语音无线传输吗?
2989 浏览 5 评论
3851 浏览 3 评论
3313 浏览 8 评论
请教各位大咖:有没有接收频率32M左右的芯片推荐的?先感谢啦!
1271浏览 1评论
1215浏览 0评论
887浏览 0评论
975浏览 0评论
930浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-3 19:13 , Processed in 0.518127 second(s), Total 46, Slave 38 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
625