-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
70 lines (65 loc) · 2.49 KB
/
Copy pathexample.cpp
File metadata and controls
70 lines (65 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <unistd.h>
#include "proxymanager/proxymanager.h"
#define PROXY_IP "127.0.0.1"
#define PROXY_PORT 1080
#define UDP_DST_IP "28.28.28.28"
#define UDP_DST_PORT 2727
#define RCV_TRY_MAX 10
#define TCP_DST_IP "27.27.27.27"
#define TCP_DST_PORT 2828
int main (int argc, char **argv)
{
ProxyManager *proxyManagerUDP = new ProxyManager();
ProxyManager *proxyManagerTCP = new ProxyManager();
std::cout << "Socks5 client was started!" << std::endl;
if (proxyManagerUDP->connectToProxy(PROXY_IP, PROXY_PORT, "", "", Socks5::PROXY_MODE::UDP_ASSOCIATE))
{
const char testPacket[] = "TEST_PACKET\0";
char *testAnswer = new char[572]; // standart MTU
int32_t sentResult = proxyManagerUDP->send(const_cast<char *>(&testPacket[0]), sizeof(testPacket), UDP_DST_IP, UDP_DST_PORT);
if (sentResult > 0)
{
std::cout << "UDP packet was successful sent" << std::endl;
}
uint32_t tryCount = 0;
int32_t messageLength = 0;
while ((messageLength = proxyManagerUDP->read(testAnswer, 572)) < 1)// don`t get src addr
// if this need: read(testAnswer, 572, &binAddr, &port)
{
tryCount++;
if (tryCount >= RCV_TRY_MAX)
{
std::cout << "Don`t get answer..." << std::endl;
break;
}
usleep(100 * 1000); // 10ms
}
// do something with answer
delete[] testAnswer;
}
else
{
std::cout << "Proxy connection error: " << ProxyManager::getErrorString(proxyManagerUDP->lastErrorCode()) << std::endl;
}
if (proxyManagerTCP->connectToProxy(PROXY_IP, PROXY_PORT, "", "", Socks5::PROXY_MODE::CONNECTION, TCP_DST_IP, TCP_DST_PORT))
{
const char testPacket[] = "TEST_PACKET\0";
char *testAnswer = new char[572]; // standart MTU
int32_t sentResult = proxyManagerTCP->send(const_cast<char *>(&testPacket[0]), sizeof(testPacket));
if (sentResult > 0)
{
std::cout << "TCP packet was successful sent" << std::endl;
}
if (proxyManagerTCP->read(testAnswer, 572) > 0) // blocking socket
{
//do something with answer
}
delete[] testAnswer;
}
else
{
std::cout << "Proxy connection error: " << ProxyManager::getErrorString(proxyManagerTCP->lastErrorCode()) << std::endl;
}
return 0;
}