日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

include详解 shell_socket实现基于tcp/ip的网络远程shell命令解析器(完善中...)

發(fā)布時間:2023/12/15 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 include详解 shell_socket实现基于tcp/ip的网络远程shell命令解析器(完善中...) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

//==========================================================================

//模塊名稱: shell命令模塊

//功能描述:判斷輸入的命令信息

//

//==========================================================================

#include "command.h"

#include "strsplit.h"

char cd_path_his[50];

char outbuf[2048];

//========================================================================================================

//function name : getcmd_info

//description: split input command and get it's info

//parameter:

//return value: int,the command's type

//========================================================================================================

int get_cmd_type(char *inputbuf,char *cmd_option[])

{

int cmd_type;

if(inputbuf==NULL)

{

perror("in function get_cmd_tpye() error!\n");

exit(-1);

}

if((strstr(inputbuf,"cd")!=NULL) || (strstr(inputbuf,"exit")!=NULL)||(strstr(inputbuf,"jobs")!=NULL)||(strstr(inputbuf,"bg")!=NULL)||(strstr(inputbuf,"fg")!=NULL))

{

cmd_type=0; //內(nèi)部命令

strsplit(inputbuf," ",cmd_option);

return cmd_type;

}

else if( strstr(inputbuf,">") )//rewrite方式重定向

{

cmd_type=1;

strsplit(inputbuf,">",cmd_option);

return cmd_type;

}

else if( strstr(inputbuf,">>"))//append方式重定向

{

cmd_type=2;

strsplit(inputbuf,">>",cmd_option);

return cmd_type;

}

else if( strstr(inputbuf,"|") )//pipe 管道命令

{

cmd_type=3;

strsplit(inputbuf,"|",cmd_option);

return cmd_type;

}

else //普通命令

{

cmd_type=4;

strsplit(inputbuf," ",cmd_option);

return cmd_type;

}

return -1;

}

//==============================================================================================================

//function name: iner_cmd_addr

//description: execute iner command address

//parameter:

//return value: null

//==============================================================================================================

void iner_cmd_addr(char *cmd_option[])

{

char temp[50];

char path[50];

char cmdbin[20];

int fd[2];

int i=0;

pid_t pid;

printf("in 66 line");

strcpy(cmdbin,cmd_option[0]);

printf("in 68 line");

if(pipe(fd)<0)

{

perror("pipe error!\n");

exit(1);

}

if((pid=fork())<0)

{

perror("fork error in comm_cmd addr\n");

exit(-1);

}

if(pid==0)

{

close(fd[0]);

dup2(fd[1],1);

if(strcmp(cmdbin,"cd")==0)

{

memset(temp,0,50);

memset(path,0,50);

if(cmd_option[1]!=NULL)

strcpy(path,cmd_option[1]);

//????strcpy(cd_cmd_his,cd_cur_path);

getcwd(temp,sizeof(temp));

if(strcmp(path,"~")==0)

{

strcpy(path,"/home");

}

else if(strcmp(path,"-")==0)

{

strcpy(path,cd_path_his);

}

//printf("path=%s",path);

chdir(path);

strcpy(cd_path_his,temp);

}

else if(strcmp(cmdbin,"jobs")==0)

{

;

}

else if(strcmp(cmdbin,"bg")==0)

{

;

}

else if(strcmp(cmdbin,"fg")==0)

{

;

}

else if(strcmp(cmdbin,"exit")==0)

{

printf("Bye bye!\n");

exit(1);

}

}

else

{

close(fd[1]);

waitpid(pid,NULL,0);

while(read(fd[0],outbuf+i,1)!=0)

{

if(outbuf[i]=='\n')

{

outbuf[i]='\r';

i++;

outbuf[i]='\n';

}

i++;

}

}

}

//==============================================================================================================

//function name: comm_cmd_addr

//description:

//parameter:

//return value:

//=========================================================================================================

void comm_cmd_addr(char *cmd_option[])

{

pid_t pid;

char cmdbin[20];

int fd[2];

int i=0;

strcpy(cmdbin,cmd_option[0]);

if(pipe(fd)<0)

{

perror("pipe error!\n");

exit(1);

}

if((pid=fork())<0)

{

perror("fork error in comm_cmd addr\n");

exit(-1);

}

if(0==pid)

{

close(fd[0]);

dup2(fd[1],1);

execvp(cmdbin,cmd_option);

}

else

{

close(fd[1]);

//dup2(fd[0],0);

waitpid(pid,NULL,0);

while(read(fd[0],outbuf+i,1)!=0)

{

if(outbuf[i]=='\n')

{

outbuf[i]='\r';

i++;

outbuf[i]='\n';

}

i++;

}

}

}

總結(jié)

以上是生活随笔為你收集整理的include详解 shell_socket实现基于tcp/ip的网络远程shell命令解析器(完善中...)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。