A simple proxy proxy source source code!

zhaozj2021-02-08  274

#include #include

#define proxy_ip "xxx.xxx.xxx.xxx" #define proxy_port 1080

#define dest_ip "xxx.xxx.xxx.xxx" #define dest_port 8888

#define local_ip "xxx.xxx.xxx.xxx" #define local_port 6666

INT main () {Int fd, fd_udp; struct sockaddr_in name; wsadata wsadata; char buf [100]; int Len; INT i; if (WsaStartup (MakeWord (2, 2), & WSADATA) RETURN 1; IF ((fd_udp) = Socket (AF_INET, SOCK_DGRAM, 0) == -1) Return 1; IF ((fd = socket, sock_stream, 0) == -1) Return 1; MEMSET (& Name, 0, Sizeof (Name) ); Name.sin_family = af_inet; name.sin_addr.s_addr = inet_addr (proxy_ip); name.sin_port = htons (proxy_port); if (Connect (FD, Struct SockAddr *) & name, sizeof (name))! = 0) RETURN 1; BUF [0] = 5; BUF [1] = 1; BUF [2] = 0; Send (FD, BUF, 3, 0); RECV (FD, BUF, 2, 0); IF (BUF [ 0]! = 5 || BUF [1]! = 0) Return 1; BUF [0] = 5; / * protocol version * / buf [1] = 3; / * Command udp associate * / buf [2] = 0; / * reserved * / buf [3] = 1; / * address type ip v4 * / len = sizeof (name); MEMSET (&) name, 0, sizeof (name)); name.sin_family = AF_INET; name.sin_addr.s_addr = inet_addr (LOCAL_IP); name.sin_port = htons (LOCAL_PORT); bind (fd_udp, (struct sockaddr *) & name, len); * (unsigned int *) & buf [4] = inet_addr (local_ip); // name.sin_addr.s_addr; * (unsigned short *) & buf [8] = htons (local_port); send (fd, buf, 10, 0) Recv (FD, BUF, 10, 0); IF (BUF [0]! = 5) RETURN 11; MEMSET (& Name, 0, SizeOf (Name)); Name.sin_Family = AF_INET; Name.SIN_ADDR.S_ADDR = * (int *) & buf [4]; name.sin_port = (* (short *) & buf [8]);

转载请注明原文地址:https://www.9cbs.com/read-819.html

New Post(0)