Commit 617a243f authored by nanamicat's avatar nanamicat

fix

parent b27ecb5c
...@@ -17,10 +17,11 @@ namespace po = boost::program_options; ...@@ -17,10 +17,11 @@ 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.";
auto cipher_length = strlen((char *) cipher);
void encrypt_package(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 % cipher_length];
} }
} }
...@@ -30,7 +31,7 @@ void inbound(int raw, int tun) { ...@@ -30,7 +31,7 @@ void inbound(int raw, int tun) {
sockaddr_in address{.sin_family = AF_INET}; sockaddr_in address{.sin_family = AF_INET};
socklen_t address_length; socklen_t address_length;
size_t packet_length; size_t packet_length;
while ((packet_length = recvfrom(raw, buffer, sizeof(buffer), 0, (sockaddr * ) & address, &address_length)) >= 0) { while ((packet_length = recvfrom(raw, buffer, sizeof(buffer), 0, (sockaddr *) &address, &address_length)) >= 0) {
auto *packet = (iphdr *) buffer; auto *packet = (iphdr *) buffer;
auto overhead = packet->ihl * 4; auto overhead = packet->ihl * 4;
auto payload = buffer + overhead; auto payload = buffer + overhead;
...@@ -56,7 +57,7 @@ void outbound(int raw, int tun) { ...@@ -56,7 +57,7 @@ void outbound(int raw, int tun) {
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_package(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");
} }
} }
......
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