dev-proxy-connect.cpp: Dev tool to check connections via proxy.

This commit is contained in:
ZmnSCPxj jxPCSnmZ 2020-11-13 10:30:17 +08:00
parent 6c714cb36b
commit 974dfb7953
3 changed files with 61 additions and 1 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
clboss
dev-boltz-api
dev-boltz
dev-proxy-connect
data.dev-boltz
*.o
*.la

View file

@ -3,7 +3,8 @@ clboss_SOURCES = \
main.cpp
noinst_PROGRAMS = \
dev-boltz \
dev-boltz-api
dev-boltz-api \
dev-proxy-connect
# These are the actual source files of clboss.
# We separate them here so that we can test parts of

58
dev-proxy-connect.cpp Normal file
View file

@ -0,0 +1,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;
}