diff --git a/Lcx.cpp b/Lcx.cpp index b886c28..010f9d8 100644 --- a/Lcx.cpp +++ b/Lcx.cpp @@ -8,28 +8,28 @@ #include #pragma comment(lib, "ws2_32.lib") -//궨 +//宏定义 typedef struct{ SOCKET s1; SOCKET s2; }Stu_sock; -// +//函数声明 void version(); -int param(int argc,char **argv); //в -void Funlisten(int port1, int port2); //ܺ -bool bindAndFunlisten(SOCKET s,int port);//socketĵַṹ -void datatrans(LPVOID data); //ת -void slave(char* hostIp,char * slaveIp,int destionPort,int slavePort);//slave +int param(int argc,char **argv); //对命令行参数 +void Funlisten(int port1, int port2); //监听功能函数 +bool bindAndFunlisten(SOCKET s,int port);//绑定socket的地址结构 +void datatrans(LPVOID data); //数据转发函数 +void slave(char* hostIp,char * slaveIp,int destionPort,int slavePort);//slave函数 bool checkIP(char * str); -int client_connect(int sockfd,char* server,int port);//ӷ +int client_connect(int sockfd,char* server,int port);//连接服务端 void main(int argc,char **argv) { version(); - //ж + //参数判断 WSADATA wsadata; WSAStartup(MAKEWORD(1, 1), &wsadata); char hostIp[20]={0}; @@ -50,7 +50,7 @@ void main(int argc,char **argv) int param(int argc,char **argv) { - //stricmp==strcmp ignore caseԴСд + //stricmp==strcmp ignore case忽略大小写 if (argc==4&&stricmp(argv[1],"-listen")==0) { // cout<<"Funlisten"<s1; //ܵslave - SOCKET s2=stuSock->s2; //ͳȥsocket + SOCKET s1=stuSock->s1; //接受的是slave的数据 + SOCKET s2=stuSock->s2; //发送出去的socket int sentacount1=0; // cout<s1<s2<0))///////////////////////////////////2 + if (FD_ISSET(s2,&writefd)&&flag&&(readsize>0))///////////////////////////////////2 { - int sendsize=send(s2,SendBuffer,readsize,0);//slave + int sendsize=send(s2,SendBuffer,readsize,0);//发给slave if (sendsize==0) { break; @@ -275,7 +275,7 @@ void datatrans(LPVOID data) if (FD_ISSET(s2,&readfd)&&(!flag))///////////////////////////////////3 { { - readsize=recv(s2, RecvBuffer, 20480, 0);//slave + readsize=recv(s2, RecvBuffer, 20480, 0);//接受slave返回数据 memcpy(SendBuffer,RecvBuffer,readsize); cout<<" [+] Recv "<0))///////////////////////////////////4 { - readsize=send(s1,SendBuffer,readsize,0);//host + readsize=send(s1,SendBuffer,readsize,0);//发给host if (readsize==0) { break; @@ -313,7 +313,7 @@ void datatrans(LPVOID data) /************************************************************************/ /* */ -/* slave ģ */ +/* slave 功能模块 */ /************************************************************************/ void slave(char* hostIp,char * slaveIp,int destionPort,int slavePort) { @@ -325,7 +325,7 @@ void slave(char* hostIp,char * slaveIp,int destionPort,int slavePort) int l; while(TRUE) { - //׽ + //创建套接字 SOCKET sock1=socket(AF_INET,SOCK_STREAM,0); SOCKET sock2=socket(AF_INET,SOCK_STREAM,0); @@ -341,24 +341,24 @@ void slave(char* hostIp,char * slaveIp,int destionPort,int slavePort) { closesocket(sock1); closesocket(sock2); - continue;/*ѭ*/ + continue;/*跳过这次循环*/ } memset(buffer,0,20480); while(1) { - //sock,set + //把sock清零,加入set集 FD_ZERO(&fd); FD_SET(sock1, &fd); - //select¼ д 쳣 + //select事件 读 写 异常 if (select(sock1+1, &fd, NULL, NULL, NULL) == SOCKET_ERROR) { - // + //不懂 if (errno == WSAEINTR) continue; break; } - //FD_ISSETֵ>0 ʾSETĿɶд + //FD_ISSET返回值>0 表示SET里的可读写 if (FD_ISSET(sock1, &fd)) { l=recv(sock1, buffer, 20480, 0); @@ -410,7 +410,7 @@ void slave(char* hostIp,char * slaveIp,int destionPort,int slavePort) } } -//IPַʽǷȷ +//检查IP地址格式是否正确 bool checkIP(char * str) { if(INADDR_NONE == inet_addr(str)) @@ -419,24 +419,24 @@ bool checkIP(char * str) } int client_connect(int sockfd,char* server,int port) -{ /*sock*/ /*ԶIP*/ /*Զ̶˿*/ +{ /*sock*/ /*远程IP*/ /*远程端口*/ - // + //声明 struct sockaddr_in cliaddr; struct hostent *host; - if(!(host=gethostbyname(server))) //ԶIP + if(!(host=gethostbyname(server))) //获得远程主机的IP { // printf("[-] Gethostbyname(%s) error:%s\n",server,strerror(errno)); return(0); } - //ַṹֵ + //给地址结构赋值 memset(&cliaddr, 0, sizeof(struct sockaddr)); cliaddr.sin_family=AF_INET; - cliaddr.sin_port=htons(port);/*Զ̶˿*/ + cliaddr.sin_port=htons(port);/*远程端口*/ cliaddr.sin_addr=*((struct in_addr *)host->h_addr);//host ip - //ȥԶlisten + //去连接远程正在listen的主机 if(connect(sockfd,(struct sockaddr *)&cliaddr,sizeof(struct sockaddr))<0) { // printf("[-] Connect error.\r\n");