summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/encrypted_packet.c26
-rw-r--r--src/encrypted_packet.h2
-rw-r--r--src/uanytun.c109
3 files changed, 46 insertions, 91 deletions
diff --git a/src/encrypted_packet.c b/src/encrypted_packet.c
index 7be3cd5..fdbc288 100644
--- a/src/encrypted_packet.c
+++ b/src/encrypted_packet.c
@@ -63,6 +63,21 @@ u_int32_t encrypted_packet_get_length(encrypted_packet_t* packet)
return (packet->payload_length_ + sizeof(encrypted_packet_header_t));
}
+void encrypted_packet_set_length(encrypted_packet_t* packet, u_int32_t len)
+{
+ if(!packet)
+ return;
+
+ if(len > ENCRYPTED_PACKET_SIZE_MAX)
+ len = ENCRYPTED_PACKET_SIZE_MAX - sizeof(encrypted_packet_header_t);
+ else if(len < sizeof(encrypted_packet_header_t))
+ len = 0;
+ else
+ len -= sizeof(encrypted_packet_header_t);
+
+ packet->payload_length_ = len;
+}
+
u_int8_t* encrypted_packet_get_payload(encrypted_packet_t* packet)
{
if(!packet)
@@ -79,17 +94,6 @@ u_int32_t encrypted_packet_get_payload_length(encrypted_packet_t* packet)
return packet->payload_length_;
}
-void encrypted_packet_set_payload_length(encrypted_packet_t* packet, u_int32_t len)
-{
- if(!packet)
- return;
-
- if(len > ENCRYPTED_PACKET_SIZE_MAX || (len + sizeof(encrypted_packet_header_t)) > ENCRYPTED_PACKET_SIZE_MAX)
- len = ENCRYPTED_PACKET_SIZE_MAX - sizeof(encrypted_packet_header_t);
-
- packet->payload_length_ = len;
-}
-
seq_nr_t encrypted_packet_get_seq_nr(encrypted_packet_t* packet)
{
if(!packet)
diff --git a/src/encrypted_packet.h b/src/encrypted_packet.h
index f2011a0..025d32b 100644
--- a/src/encrypted_packet.h
+++ b/src/encrypted_packet.h
@@ -62,10 +62,10 @@ void encrypted_packet_init(encrypted_packet_t* packet);
u_int8_t* encrypted_packet_get_packet(encrypted_packet_t* packet);
u_int32_t encrypted_packet_get_length(encrypted_packet_t* packet);
+void encrypted_packet_set_length(encrypted_packet_t* packet, u_int32_t len);
u_int8_t* encrypted_packet_get_payload(encrypted_packet_t* packet);
u_int32_t encrypted_packet_get_payload_length(encrypted_packet_t* packet);
-void encrypted_packet_set_payload_length(encrypted_packet_t* packet, u_int32_t len);
seq_nr_t encrypted_packet_get_seq_nr(encrypted_packet_t* packet);
void encrypted_packet_set_seq_nr(encrypted_packet_t* packet, seq_nr_t seq_nr);
diff --git a/src/uanytun.c b/src/uanytun.c
index a80dfe2..c302764 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -53,25 +53,41 @@ void main_loop(tun_device_t* dev, udp_socket_t* sock)
{
log_printf(INFO, "entering main loop");
- u_int8_t buf[1600];
- int len = 0;
+ plain_packet_t plain_packet;
+ plain_packet_init(&plain_packet);
+ encrypted_packet_t encrypted_packet;
+ encrypted_packet_init(&encrypted_packet);
+ u_int32_t len = 0;
udp_endpoint_t remote;
- unsigned int cnt = 0;
- while(cnt < 5) {
- len = udp_read(sock, buf, 1600, &remote);
+ while(1) {
+ plain_packet_set_payload_length(&plain_packet, -1);
+ encrypted_packet_set_length(&encrypted_packet, -1);
- if(memcmp(&remote, &(sock->remote_end_), sizeof(remote))) {
- memcpy(&(sock->remote_end_), &remote, sizeof(remote));
- char* addrstring = udp_endpoint_to_string(remote);
- log_printf(NOTICE, "autodetected remote host changed %s", addrstring);
- free(addrstring);
- }
+
+
+
+/* len = tun_read(dev, plain_packet_get_payload(&plain_packet), plain_packet_get_payload_length(&plain_packet)); */
+/* plain_packet_set_payload_length(&plain_packet, len); */
+
+/* udp_write(sock, encrypted_packet_get_packet(&encrypted_packet), encrypted_packet_get_length(&encrypted_packet)); */
+
+
+
+
+/* len = udp_read(sock, encrypted_packet_get_packet(&encrypted_packet), encrypted_packet_get_length(&encrypted_packet), &remote); */
+/* encrypted_packet_set_length(&encrypted_packet, len); */
+
+/* if(memcmp(&remote, &(sock->remote_end_), sizeof(remote))) { */
+/* memcpy(&(sock->remote_end_), &remote, sizeof(remote)); */
+/* char* addrstring = udp_endpoint_to_string(remote); */
+/* log_printf(NOTICE, "autodetected remote host changed %s", addrstring); */
+/* free(addrstring); */
+/* } */
+
+/* tun_write(dev, plain_packet_get_payload(&plain_packet), plain_packet_get_payload_length(&plain_packet)); */
- printf("read %d bytes from socket\n", len);
- udp_write(sock, buf, len);
- cnt++;
}
}
@@ -95,71 +111,6 @@ int main(int argc, char* argv[])
log_init("uanytun", DAEMON);
signal_init();
- encrypted_packet_t packet;
- encrypted_packet_init(&packet);
-
- printf("packet length: %d\n", encrypted_packet_get_length(&packet));
- printf("packet: \n");
- print_hex_dump(encrypted_packet_get_packet(&packet), encrypted_packet_get_length(&packet));
- printf("\nseq nr: 0x%08X\n", encrypted_packet_get_seq_nr(&packet));
- printf("sender id: 0x%04X\n", encrypted_packet_get_sender_id(&packet));
- printf("mux: 0x%04X\n", encrypted_packet_get_mux(&packet));
- printf("payload length: %d\n", encrypted_packet_get_payload_length(&packet));
- printf("payload: \n");
- print_hex_dump(encrypted_packet_get_payload(&packet), encrypted_packet_get_payload_length(&packet));
- printf("\n\n");
-
-
- encrypted_packet_set_payload_length(&packet, 20);
-
- printf("packet length: %d\n", encrypted_packet_get_length(&packet));
- printf("packet: \n");
- print_hex_dump(encrypted_packet_get_packet(&packet), encrypted_packet_get_length(&packet));
- printf("\nseq nr: 0x%08X\n", encrypted_packet_get_seq_nr(&packet));
- printf("sender id: 0x%04X\n", encrypted_packet_get_sender_id(&packet));
- printf("mux: 0x%04X\n", encrypted_packet_get_mux(&packet));
- printf("payload length: %d\n", encrypted_packet_get_payload_length(&packet));
- printf("payload: \n");
- print_hex_dump(encrypted_packet_get_payload(&packet), encrypted_packet_get_payload_length(&packet));
- printf("\n\n");
-
-
- u_int32_t i;
-
- for(i=0; i<encrypted_packet_get_payload_length(&packet); i++)
- encrypted_packet_get_payload(&packet)[i] = (u_int8_t)i;
- encrypted_packet_set_seq_nr(&packet, 124);
- encrypted_packet_set_sender_id(&packet, 2);
- encrypted_packet_set_mux(&packet, 234);
-
- printf("packet length: %d\n", encrypted_packet_get_length(&packet));
- printf("packet: \n");
- print_hex_dump(encrypted_packet_get_packet(&packet), encrypted_packet_get_length(&packet));
- printf("\nseq nr: 0x%08X\n", encrypted_packet_get_seq_nr(&packet));
- printf("sender id: 0x%04X\n", encrypted_packet_get_sender_id(&packet));
- printf("mux: 0x%04X\n", encrypted_packet_get_mux(&packet));
- printf("payload length: %d\n", encrypted_packet_get_payload_length(&packet));
- printf("payload: \n");
- print_hex_dump(encrypted_packet_get_payload(&packet), encrypted_packet_get_payload_length(&packet));
- printf("\n\n");
-
- encrypted_packet_set_payload_length(&packet, 18);
- encrypted_packet_set_seq_nr(&packet, 124025310);
- encrypted_packet_set_sender_id(&packet, 0);
- encrypted_packet_set_mux(&packet, 23412);
-
- printf("packet length: %d\n", encrypted_packet_get_length(&packet));
- printf("packet: \n");
- print_hex_dump(encrypted_packet_get_packet(&packet), encrypted_packet_get_length(&packet));
- printf("\nseq nr: 0x%08X\n", encrypted_packet_get_seq_nr(&packet));
- printf("sender id: 0x%04X\n", encrypted_packet_get_sender_id(&packet));
- printf("mux: 0x%04X\n", encrypted_packet_get_mux(&packet));
- printf("payload length: %d\n", encrypted_packet_get_payload_length(&packet));
- printf("payload: \n");
- print_hex_dump(encrypted_packet_get_payload(&packet), encrypted_packet_get_payload_length(&packet));
- printf("\n\n");
-
-
// chrootAndDrop("/var/run/", "nobody");
// daemonize();
// log_printf(INFO, "running in background now");