Commit f65c6593 authored by Manni's avatar Manni

fix

parent 057e78a1
# Project exclude paths # Project exclude paths
cmake-build-debug cmake-build-debug
.idea .idea
\ No newline at end of file .DS_Store
...@@ -11,22 +11,19 @@ ...@@ -11,22 +11,19 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#define decrypt_package encrypt_package
namespace po = boost::program_options; namespace po = boost::program_options;
in_addr_t remote; in_addr_t remote;
auto cipher = (unsigned char *) "Mathematics is the art of giving the same name to different things"; auto cipher = (unsigned char *) "Mathematics is the art of giving the same name to different things.";
void encrypt(unsigned char *buffer, size_t length) { void encrypt_package(unsigned char *buffer, size_t length) {
for (auto i = 0; i < length; i++) { for (auto i = 0; i < length; i++) {
buffer[i] ^= cipher[i]; buffer[i] ^= cipher[i];
} }
} }
void decrypt(unsigned char *buffer, size_t length) {
// xor decrypt is same as encrypt
encrypt(buffer, length);
}
// internet -> tun // internet -> tun
void inbound(int raw, int tun) { void inbound(int raw, int tun) {
unsigned char buffer[ETH_DATA_LEN]; unsigned char buffer[ETH_DATA_LEN];
...@@ -39,7 +36,7 @@ void inbound(int raw, int tun) { ...@@ -39,7 +36,7 @@ void inbound(int raw, int tun) {
auto overhead = packet->ihl * 4; auto overhead = packet->ihl * 4;
auto payload = buffer + overhead; auto payload = buffer + overhead;
auto payload_length = packet_length - overhead; auto payload_length = packet_length - overhead;
decrypt(payload, payload_length); decrypt_package(payload, payload_length);
if (write(tun, payload, payload_length) < 0) { if (write(tun, payload, payload_length) < 0) {
perror("inbound write"); perror("inbound write");
} }
...@@ -54,7 +51,7 @@ void outbound(int raw, int tun) { ...@@ -54,7 +51,7 @@ void outbound(int raw, int tun) {
address.sin_addr.s_addr = remote; address.sin_addr.s_addr = remote;
size_t packet_length; size_t packet_length;
while ((packet_length = read(tun, buffer, sizeof(buffer))) >= 0) { while ((packet_length = read(tun, buffer, sizeof(buffer))) >= 0) {
encrypt(buffer, packet_length); encrypt_package(buffer, packet_length);
if (sendto(raw, buffer, packet_length, 0, (sockaddr *) &address, sizeof(address)) < 0) { if (sendto(raw, buffer, packet_length, 0, (sockaddr *) &address, sizeof(address)) < 0) {
perror("outbound write"); perror("outbound write");
} }
...@@ -66,9 +63,9 @@ int main(int argc, char *argv[]) { ...@@ -66,9 +63,9 @@ int main(int argc, char *argv[]) {
po::options_description desc("Allowed options"); po::options_description desc("Allowed options");
desc.add_options() desc.add_options()
("help", "produce help message") ("help,h", "see how to use me elegantly")
("IP,i", po::value<std::string>(), "IP to connect") ("IP,i", po::value<std::string>(), "IP to connect")
("dev,d", po::value<std::string>(), "tun device name") ("dev,d", po::value<std::string>(), "tunnel device's name")
("postup,p", po::value<std::string>(), "post up script"); ("postup,p", po::value<std::string>(), "post up script");
po::variables_map args; po::variables_map args;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment