summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-12-31 18:24:39 +0000
committerChristian Pointner <equinox@anytun.org>2008-12-31 18:24:39 +0000
commit6ab8b360a505c90f14057260433ee4e86cf0d962 (patch)
tree1dcf7865d660234435680f4c89b1fc426618ac1c
parentremoved useless malloc for cipher_t (diff)
removed useless malloc for seq_window_t
-rw-r--r--src/seq_window.c21
-rw-r--r--src/seq_window.h4
-rw-r--r--src/uanytun.c10
3 files changed, 15 insertions, 20 deletions
diff --git a/src/seq_window.c b/src/seq_window.c
index f5c0bf8..df5f9d9 100644
--- a/src/seq_window.c
+++ b/src/seq_window.c
@@ -41,25 +41,23 @@
#include <stdio.h>
-void seq_win_init(seq_win_t** win, window_size_t size)
+int seq_win_init(seq_win_t* win, window_size_t size)
{
if(!win)
- return;
+ return -1;
- *win = malloc(sizeof(seq_win_t));
- if(!*win)
- return;
+ win->size_ = size;
+ win->first_ = NULL;
- (*win)->size_ = size;
- (*win)->first_ = NULL;
+ return 0;
}
-void seq_win_clear(seq_win_t** win)
+void seq_win_clear(seq_win_t* win)
{
- if(!win || !(*win))
+ if(!win)
return;
- seq_win_element_t* ptr = (*win)->first_;
+ seq_win_element_t* ptr = win->first_;
while(ptr) {
seq_win_element_t* to_free = ptr;
ptr = ptr->next_;
@@ -68,9 +66,6 @@ void seq_win_clear(seq_win_t** win)
free(to_free);
}
-
- free(*win);
- *win = NULL;
}
seq_win_element_t* seq_win_new_element(sender_id_t sender_id, seq_nr_t max, window_size_t size)
diff --git a/src/seq_window.h b/src/seq_window.h
index 9832372..7855594 100644
--- a/src/seq_window.h
+++ b/src/seq_window.h
@@ -50,8 +50,8 @@ struct seq_win_struct {
};
typedef struct seq_win_struct seq_win_t;
-void seq_win_init(seq_win_t** win, window_size_t size);
-void seq_win_clear(seq_win_t** win);
+int seq_win_init(seq_win_t* win, window_size_t size);
+void seq_win_clear(seq_win_t* win);
seq_win_element_t* seq_win_new_element(sender_id_t sender_id, seq_nr_t max, window_size_t size);
int seq_win_check_and_add(seq_win_t* win, sender_id_t sender_id, seq_nr_t seq_nr);
diff --git a/src/uanytun.c b/src/uanytun.c
index c2f5585..26f4bea 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -76,11 +76,11 @@ int main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt)
return_value = ret;
}
- seq_win_t* seq_win;
- seq_win_init(&seq_win, opt->seq_window_size_);
- if(!seq_win) {
+ seq_win_t seq_win;
+ ret = seq_win_init(&seq_win, opt->seq_window_size_);
+ if(ret) {
printf("could not initialize sequence window");
- return_value = -1;
+ return_value = ret;
}
while(!return_value) {
@@ -146,7 +146,7 @@ int main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt)
if(encrypted_packet_get_mux(&encrypted_packet) != opt->mux_)
continue;
- int result = seq_win_check_and_add(seq_win, encrypted_packet_get_sender_id(&encrypted_packet), encrypted_packet_get_seq_nr(&encrypted_packet));
+ int result = seq_win_check_and_add(&seq_win, encrypted_packet_get_sender_id(&encrypted_packet), encrypted_packet_get_seq_nr(&encrypted_packet));
if(result > 0) {
log_printf(WARNING, "detected replay attack, discarding packet");
continue;