- static err_t telnet_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
- {
- // char *rq;
- /* We perform here any necessary processing on the pbuf */
- if (p != NULL)
- {
- u16_t len;
- u8_t *datab;
- u16_t strlen;
- /* We call this function to tell the LwIp that we have processed the data */
- /* This lets the stack advertise a larger window, so more data can be received*/
- tcp_recved(pcb, p->tot_len);
- //do
- {
- //data=p->payload;
- len=p->len;
- datab = (unsigned char *)p->payload;
- if((len == 2) && (*datab == 0x0d) && (*(datab+1) == 0x0a))
- {
- if(cmd_flag > 0)
- {
- cmdbuf[cmd_flag] = 0x00;
- if(strcmp(cmdbuf,"date")==0)
- {
- strlen = sprintf(sndbuf, "Now, It is 2011-xx-xx!\r\n");
- tcp_write(pcb,sndbuf,strlen, 1);
- }
- else if(strcmp(cmdbuf, "hello")==0)
- {
- strlen = sprintf(sndbuf, "Hello, Nice to see you!\r\n");
- tcp_write(pcb,sndbuf,strlen, 1);
- }
- else if(strcmp(cmdbuf, "more")==0)
- {
- strlen = sprintf(sndbuf, "Add whatever you need in this way!\r\n");
- tcp_write(pcb,sndbuf,strlen, 1);
- }
- else if(strcmp(cmdbuf, "help")==0)
- {
- strlen = sprintf(sndbuf, "Suppprted Command£ºdate hello more help quit\r\n");
- tcp_write(pcb,sndbuf,strlen, 1);
- }
- else if(strcmp(cmdbuf, "quit")==0)
- {
- cmd_flag=0;
- pbuf_free(p);
- return tcp_close(pcb);
- }
- else
- {
- strlen = sprintf(sndbuf, "Unkonwn Command: %s.\r\n", cmdbuf);
- tcp_write(pcb,sndbuf,strlen, 1);
- }
- cmd_flag = 0;
- }
- strlen = sprintf(sndbuf,"\r\nForrest_Shell>>");
- tcp_write(pcb,sndbuf,strlen, 1);
- }
- else if((len == 1) && (*datab >= 0x20) && (*datab <= 0x7e) && (cmd_flag < 19))
- {
- cmdbuf[cmd_flag] = *datab;
- cmd_flag++;
- }
- else if((len == 1) && (*datab == 0x08) && (cmd_flag >0))
- {
- cmd_flag--;
- strlen = sprintf(sndbuf," \b \b");
- tcp_write(pcb,sndbuf,strlen, 1);
- }
- else if((len == 1) && (*datab == 0x08))
- {
- cmd_flag=0;
- strlen = sprintf(sndbuf,">");
- tcp_write(pcb,sndbuf,strlen, 1);
- }
- else
- {
-
- }
- }
- // while(netbuf_next(buf) >= 0);
- pbuf_free(p);
- }
- else if (err == ERR_OK)
- {
- /* When the pbuf is NULL and the err is ERR_OK, the remote end is closing the connection. */
- /* We free the allocated memory and we close the connection */
- return tcp_close(pcb);
- }
- return ERR_OK;
- }
这个是收到数据后的回调函数,你可以看看数据怎么提取以及处理的,这是个talent的例子