;p 一个增加系统负担的程序, 不过比cterm客气多了, 若干分钟才发一个ctrl+l
把下面这段代码存下来, 并编译之, 产生可执行文件, 比如 gcc fadai.c
在当前目录产生 a.out ,运行命令, 比如 "./a.out | telnet bbs.tsinghua.edu.cn"
就可以了. 有一部分代码是不必要的, 先放着吧 ;p 其中倒数第十行中的
timeout.tv_sec=600
是指当你不击键达600秒时程序就替你向bbs就送出一个ctrl+l, 可以改
成自己想要的时间长度.
这个程序中的两个子函数是从<<Linux 从入门到精通, A-Z>>上抄下来
的. 是本不错的书.
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/time.h>
#include <sys/types.h>
struct termios tsave;
void scan_mode(void)
{ struct termios tbuf;
if(!isatty(0)) exit(1);
if(tcgetattr(0,&tbuf)==-1) exit(1);
tsave=tbuf;
tbuf.c_lflag&=~(ECHO|ICANON|ISIG);
tbuf.c_cc[VMIN]=tbuf.c_cc[VTIME]=0;
if(tcsetattr(0,TCSANOW,&tbuf)==-1) exit(1);
}
void restore_mode(int i)
{ tcsetattr(0,TCSANOW,&tsave);
exit(1);
}
main()
{ int i;
char bufer[1024], s=12;
fd_set rdfds;
struct timeval timeout;
fcntl(0,F_SETFL,O_NONBLOCK);
scan_mode();
(void)signal(SIGPIPE, restore_mode);
while(1)
{ timeout.tv_sec=600;
timeout.tv_usec=0;
FD_ZERO(&rdfds);
FD_SET(0,&rdfds);
if(select(1,&rdfds,NULL,NULL,&timeout))
{ i=read(0,bufer,1024);
if(i>0) write(1,bufer,i);
}else
{ write(1,&s,1);
}
}
}
--
修改:ylsdd FROM 162.105.21.92
FROM 162.105.21.92