summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-12-28 17:16:59 +0000
committerChristian Pointner <equinox@anytun.org>2008-12-28 17:16:59 +0000
commitdae86de028e6f07c8c45b51f3386e1242bc9bde5 (patch)
treeca802c307a2d57cef88ac3c9ccdbbf65d8f070e9
parentint main() is pretty finished now (diff)
cleaned up main loop (still some building blocks missing)
-rw-r--r--src/uanytun.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/uanytun.c b/src/uanytun.c
index 5ccab3b..7b207b6 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -61,34 +61,50 @@ void main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt)
encrypted_packet_init(&encrypted_packet);
u_int32_t len = 0;
udp_endpoint_t remote;
+ seq_nr_t seq_nr = 0;
while(1) {
plain_packet_set_payload_length(&plain_packet, -1);
encrypted_packet_set_length(&encrypted_packet, -1);
+// TODO: add select
+
+// if dev->fd_ is ready:
+ 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);
+ // TODO: cipher packet
+ // TODO: add auth-tag
+
+ encrypted_packet_set_seq_nr(&encrypted_packet, seq_nr);
+ encrypted_packet_set_sender_id(&encrypted_packet, opt->sender_id_);
+ encrypted_packet_set_mux(&encrypted_packet, opt->mux_);
+ udp_write(sock, encrypted_packet_get_packet(&encrypted_packet), encrypted_packet_get_length(&encrypted_packet));
+
-/* 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)); */
+// if sock->fd_ is ready:
+ len = udp_read(sock, encrypted_packet_get_packet(&encrypted_packet), encrypted_packet_get_length(&encrypted_packet), &remote);
+ encrypted_packet_set_length(&encrypted_packet, len);
+ // TODO: check auth-tag
+ if(encrypted_packet_get_mux(&encrypted_packet) != opt->mux_)
+ continue;
+ // TODO: check seq nr for sender id
-/* 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);
+ }
-/* 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); */
-/* } */
+ // TODO: decipher packet
-/* tun_write(dev, plain_packet_get_payload(&plain_packet), plain_packet_get_payload_length(&plain_packet)); */
- sleep(1);
+ tun_write(dev, plain_packet_get_payload(&plain_packet), plain_packet_get_payload_length(&plain_packet));
}
}