-
Notifications
You must be signed in to change notification settings - Fork 31
/
dev-proxy-connect.cpp
58 lines (50 loc) · 1.23 KB
/
dev-proxy-connect.cpp
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
#include"Net/DirectConnector.hpp"
#include"Net/ProxyConnector.hpp"
#include"Net/SocketFd.hpp"
#include"Util/make_unique.hpp"
#include<errno.h>
#include<iostream>
#include<sstream>
#include<string.h>
namespace {
int parse_int(std::string s) {
auto is = std::istringstream(std::move(s));
auto rv = int();
is >> rv;
return rv;
}
}
int main(int argc, char** argv) {
if (argc != 3 && argc != 5) {
std::cerr << "Usage: dev-proxy-connect host port" << std::endl
<< " OR:" << std::endl
<< "Usage: dev-proxy-connect proxy proxyport host port" << std::endl
;
return 0;
}
auto conn = std::unique_ptr<Net::Connector>(
Util::make_unique<Net::DirectConnector>()
);
auto host = std::string();
auto port = int();
if (argc == 3) {
host = std::string(argv[1]);
port = parse_int(argv[2]);
} else if (argc == 5) {
conn = Util::make_unique<Net::ProxyConnector>(
std::move(conn),
std::string(argv[1]),
parse_int(argv[2])
);
host = std::string(argv[3]);
port = parse_int(argv[4]);
}
auto fd = conn->connect(host, port);
if (!fd) {
auto err = std::string(strerror(errno));
std::cout << "Not connected: " << err << " (" << errno << ")" << std::endl;
return 1;
}
std::cout << "Connected." << std::endl;
return 0;
}