分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

uip移植telnetd并加入自己定义命令

发布时间:2023-09-16 23:49责任编辑:赖小花关键词:暂无标签
?????????????????版权声明:https://blog.csdn.net/cp1300/article/details/30541507
???????????
???????????????

刚刚移植了一下uip的telnetd,还是比較简单方便的.


首先加入文件,注意usershell是自己写的.



在tcp.c中加入tcp端口监听程序

加入#include "telnetd.h"

void tcp_demo_appcall(void){if(uip_conn->lport == HTONS(TCP_ClinetPort)){tcp_client_demo_appcall();}else if(uip_conn->lport == HTONS(80)){httpd_appcall(); }else if(uip_conn->lport == HTONS(23)){telnetd_appcall();}}

在主函数中初始化

telnetd_init();

//自己定义shell

usershell.c

//用户自己定义shell#include "shell.h"#include "usershell.h"#include <string.h>#include "rtc.h"char printfbuff[64];//获取时间void SHELL_GetTime(char *pStr){//RTC_Get();//更新时间sprintf(printfbuff, "%02d:%02d:%02d\r\n",timer.hour, timer.min, timer.sec);shell_output("[获取时间成功]: ", printfbuff);}//获取日期void SHELL_GetDate(char *pStr){//RTC_Get();//更新时间sprintf(printfbuff, "%04d-%02d-%02d\r\n",timer.w_year, timer.w_month, timer.w_date);shell_output("[获取日期成功]: ", printfbuff);}


usershell.h

#ifndef __USER_SHELL_H__#define __USER_SHELL_H__void SHELL_GetTime(char *pStr);//获取时间void SHELL_GetDate(char *pStr);////获取日期#endif /* __USER_SHELL_H__ */


改动telnetd.h

#ifndef __TELNETD_H__#define __TELNETD_H__#include "uipopt.h"void telnetd_init(void);void telnetd_appcall(void);#ifndef TELNETD_CONF_LINELEN#define TELNETD_CONF_LINELEN 40#endif#ifndef TELNETD_CONF_NUMLINES#define TELNETD_CONF_NUMLINES 16#endifstruct telnetd_state { ?char *lines[TELNETD_CONF_NUMLINES]; ?char buf[TELNETD_CONF_LINELEN]; ?char bufptr; ?u8_t numsent; ?u8_t state;};//typedef struct telnetd_state uip_tcp_appstate_t;//#ifndef UIP_APPCALL//#define UIP_APPCALL ????telnetd_appcall//#endif#endif /* __TELNETD_H__ */
加入
void telnetd_init(void);


在shell.c中加入自己定义命令支持
static voidhelp(char *str){ ?shell_output("Available commands:", ""); ?shell_output("stats ??- show network statistics", ""); ?shell_output("conn ???- show TCP connections", ""); ?shell_output("help, ?

- show help", ""); ?shell_output("exit ???- exit shell", "");shell_output("time?

???- 获取当前系统时间", "");shell_output("date?, ??- 获取当前系统日期", "");}/*---------------------------------------------------------------------------*/static voidunknown(char *str){ ?if(strlen(str) > 0) { ???shell_output("Unknown command: ", str); ?}}/*---------------------------------------------------------------------------*/static struct ptentry parsetab[] = ?{{"stats", help}, ??{"conn", help}, ??{"help", help}, ??{"exit", shell_quit}, ??{"?

", help},{"time?", SHELL_GetTime},{"date?

", SHELL_GetDate}, ??/* Default action */ ??{NULL, unknown}};/*---------------------------------------------------------------------------*/

加入命令显示
shell_output("time? ???- 获取当前系统时间", "");shell_output("date?, ??- 获取当前系统日期", "");

命令列表
{"time?", SHELL_GetTime},{"date?", SHELL_GetDate},



运行之后的效果







???????????
?????????????????????

uip移植telnetd并加入自己定义命令

原文地址:https://www.cnblogs.com/xfgnongmin/p/10768127.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved