【 以下文字转载自 Unix 讨论区 】
【 原文由 rainwoodman 所发表 】
可以从keyfile里面读取按键记录。
如果把#define STDIN_FILENO s
去掉可以用来记录按键。
根据记录的数据,
稍加几个回车键,
切分一下,
就可以用来自动转发文章,
可以在转信坏掉的时候用。
test
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <errno.h>
#include <curses.h>
#define SIZE sizeof(struct sockaddr_in)
#define BUFSIZE 1024
char* buf="\nguest\n\n\n\n\n";
char bufout[BUFSIZE+1];
void main(){
int in;
int sockfd;
int log;
int ch;
int r;
int s;
char* p;
fd_set readfds;
struct sockaddr_in bbs={SIZE,AF_INET,htons(23),inet_addr("162.105.204.150")};
sockfd=socket(AF_INET,SOCK_STREAM,0);
log=open("logfile",O_CREAT|O_RDWR|O_TRUNC,0777);
s=open("keyfile",O_RDONLY);
#define STDIN_FILENO s
printf("%d,file%d\n",sockfd,log);
printf("%s\n",inet_ntoa(bbs.sin_addr));
//initscr();
//cbreak();
//noecho();
r=connect(sockfd,(struct sockaddr*) &bbs,SIZE);
printf("%d\n",r);
ch=0;
while(ch!=EOF){
FD_ZERO(&readfds);
FD_SET(sockfd,&readfds);
FD_SET(STDIN_FILENO,&readfds);
if(select(FD_SETSIZE,&readfds,NULL,NULL,NULL)>0){
if(FD_ISSET(sockfd,&readfds)){
//printf("sockfd");
bzero(bufout,BUFSIZE+1);
r=read(sockfd,bufout,BUFSIZE);
printf("%s",bufout);
if(r<0) break;
}
if(FD_ISSET(STDIN_FILENO,&readfds)){
//printf("stdin");
if(read(STDIN_FILENO,&ch,1)<0) break;
if(ch=='\n')usleep(4000);else usleep(500);
r=write(sockfd,&ch,1);
r=write(log,&ch,1);
}
// printf("go");
}
//printf("%d\n",r);
//printf("%d\n",errno);
}
close(sockfd);
close(log);
//noraw();
}
--
修改:rainwoodman FROM 162.105.173.82
FROM 162.105.173.82