个人计算机用作客户机,使用RAW lwIP作为TCP客户端,无法connect到PC机

int main(void)

{struct netif *pGB_netif, GB_netif;structip_addr IPaddr, NetMask, GateWay;

u8 MacAddr[]= {0x00, 0x0a, 0x35, 0x00, 0x01, 0x02};

pGB_netif= &GB_netif;

Debugout("\r\n\r\n");

Debugout("------------- Main vernsion 1.8-------------\r\n");

Debugout("-----lwIP RAW Mode Demo Application ------\r\n");/*1. Initialize the platform.*/

if (init_platform() < 0)

{

ErrorInfo("Platform initailize fail!\n");return -1;

}/*2. Set the IP*/IP4_ADDR(&IPaddr, 10, 10, 22, 10);

IP4_ADDR(&NetMask, 255, 255, 255, 0);

IP4_ADDR(&GateWay, 10, 10, 22, 1);

print_ip_settings(&IPaddr, &NetMask, &GateWay);/*3. Initialize the lwIP stack.*/lwip_init();/*4. Add IP to network interface.*/

if (!xemac_add(pGB_netif, &IPaddr, &NetMask, &GateWay, MacAddr, PLATFORM_EMAC_BASEADDR))

{

ErrorInfo("Not able to add IP to the network interface!\n");return -1;

}

netif_set_default(pGB_netif);/*5. Enable the interrupts.*/platform_enable_interrupts();/*6. Set up the network interface.*/netif_set_up(pGB_netif);/*7. Create the TCP server.*/

//GB_InitTCPSrv();

GB_InitTcpClnt();/*8. Dead cycle to receive data.*/

while (1)

{

xemacif_input(pGB_netif);//GB_send();

}return 0;

}

err_t GB_CBF_sent(void *arg, struct tcp_pcb *tpcb, u16_t len)

{

Debugout("Inside CBF_sent\n");returnERR_OK;

}

err_t GB_CBF_connect(void *arg, struct tcp_pcb *pTCPpcb, err_t errNum)

{//err_t errNum = 0;

Debugout("Inside CBF for connect!\n");//g_pClntPCB = pTCPpcb;

tcp_arg(pTCPpcb, NULL);

tcp_sent(pTCPpcb, GB_CBF_sent);returnERR_OK;

}static int GB_InitTcpClnt(void)

{struct tcp_pcb *pClntPcb =NULL;

err_t errNum= 0;char cRet = 0;structip_addr RemoteIP;

pClntPcb=tcp_new();if (NULL ==pClntPcb)

{

ErrorInfo("Create client PCB error!\n");returnRET_FAIL;

}

cRet=tcp_bind(pClntPcb, IPADDR_ANY, CONTROL_CHANNEL_PORT);if (ERR_OK !=cRet)

{

ErrorInfo("Bind Error!\n");returnRET_FAIL;

}//tcp_arg(pClntPcb, NULL);//tcp_setprio(pClntPcb, TCP_PRIO_NORMAL+1);

IP4_ADDR(&RemoteIP, 10,10,22,100);

errNum= tcp_connect(pClntPcb, &RemoteIP, (u16_t)8960, GB_CBF_connect);if (ERR_OK !=errNum)

{

ErrorInfo("Client Connect Error![%d]\n", errNum);returnRET_FAIL;

}

g_pClntPCB=pClntPcb;//tcp_output(pClntPcb);//tcp_sent(pClntPcb, );//Debugout("Client TCP Created succussfully\n");

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值