#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
//Windows和LINUX系?所提供的Socket API不一??需要分?e?明
#ifdef _WIN32
#include <winsock2.h>
#include <wininet.h>
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#endif
//定?一段???^
#define BUFSZ 65535
char buf[ BUFSZ ];
int main(int argc, char** argv)
{
//?是Server的?料,包括IP地址以及用作TCP和UDP?接的埠?
short tcp_proxy_port=8888, udp_proxy_port=8811;
char udp_proxy_ip[]="127.0.0.1";
short clt_udp_port;
//在Windows系?下,使用??前要先用WSAStartup()?磉M行初始化,
//WSA是Windows Socket API的意思,本文使用WinSock 2.0版本
//在VC中可以用WINSOCK_VERSION?碇付ò奼?不?GCC FOR WIN32?]有定????宏
//我??需要自己指定
#ifdef _WIN32
WSADATA WSAData;
if( WSAStartup(0x0110, &WSAData) ) {
//if( WSAStartup(WINSOCK_VERSION, &WSAData) ) {
p_error("WSA error");
exit(-1);
}
#endif
//??右??TCP SOCKET,用?硨?Q?行握手,?K??QQ用?硨臀???賢ǖ?DP埠?(clt_udp_port)
Launch_TCP( tcp_proxy_port, udp_proxy_ip, udp_proxy_port, &clt_udp_port );
//握手成功後,??右??UDP SOCKET,用作???鬏?,是真正起PROXY作用的部份
Launch_UDP( udp_proxy_port, udp_proxy_ip, clt_udp_port );
return 0;
}
void p_error( const char *err_msg )
{
printf( "ERR=>%s\n", err_msg );
}
void debug_showbin( const char *dbuf, int n, const char *name, const char *end )
{
int i;
printf( "%s ==> %d bytes: ", name, n );
for( i=0; i<n; i++ )
printf( "(0x%x)", (unsigned char)dbuf[i] );
printf( "%s", end );
}
void debug_showip( const struct sockaddr_in *dbuf, const char *name, const char *end )
{
printf("[ %s ==> %s:%u ]%s", name, inet_ntoa(dbuf->sin_addr), ntohs(dbuf->sin_port), end
);
}
[火星人 ] ?檳愕?Q造一??SOCK5 PROXY(Gcc篇)之一已經有348次圍觀