diff --git a/common.h b/common.h index 1480f0b..1d71a0c 100644 --- a/common.h +++ b/common.h @@ -8,7 +8,7 @@ Common #ifndef COMMON_H #define COMMON_H -#include "Net.h" // for User +#include "net.h" // for User #include "macros.h" #include diff --git a/con/console.c b/con/console.c index b64315a..486d5e4 100644 --- a/con/console.c +++ b/con/console.c @@ -174,9 +174,9 @@ void showUsers() { printf("--users--"); clearAttributes(); int i; + int j; for (i=0;isin_addr; int offset = 0; @@ -81,6 +83,11 @@ Message buildMessage(const char *data_buffer, struct sockaddr_in *socket) { return message; } +int freeMessage(Message *message) { + free(message->nick); + return 0; +} + int openListenSocket() { int ip_hash = generateHash("ip", CONFIG_HASH_SIZE); int port_hash = generateHash("port", CONFIG_HASH_SIZE); @@ -454,5 +461,8 @@ void freeInterfaces() { if (ip_list[i]) { free(ip_list[i]); } + if (dev_list[i]) { + free(dev_list[i]); + } } } diff --git a/net.h b/net.h index f1ebf60..685c2c8 100644 --- a/net.h +++ b/net.h @@ -122,6 +122,8 @@ typedef struct { } Message; Message buildMessage(const char *data_buffer, struct sockaddr_in *socket); +/* frees the malloc'd nick */ +int freeMessage(Message *message); Message current_message; // global message struct, contains last packet diff --git a/users.c b/users.c index a4abbf5..87b1923 100644 --- a/users.c +++ b/users.c @@ -12,14 +12,17 @@ int checkUser(UserList *user_list, const char nick[], struct in_addr address) { int addUser(UserList *user_list, const char nick[], struct in_addr address) { user_list->length++; + //printf("Adding!\n"); user_list->users = realloc(user_list->users, (user_list->length)*sizeof(User)); User new_user; new_user.last_address = address; - //new_user.nick = realloc(new_user.nick, strlen(nick)+1); - new_user.nick = malloc(strlen(nick)); + new_user.nick = realloc(new_user.nick, strlen(nick)+1); +// new_user.nick = malloc(strlen(nick)); new_user.addresses = malloc(1); + new_user.address_count = 0; //strcpy(new_user.nick, nick); - memcpy(new_user.nick, nick, strlen(nick)+1); + //memcpy(new_user.nick, nick, strlen(nick)+1); + memcpy(new_user.nick, nick, strlen(nick)); // new_user.last_address = malloc(sizeof(struct in_addr)); // memcpy(new_user.last_address, &address, sizeof(struct in_addr)); //new_user.last_address = malloc(new_user.last_address, sizeof(struct in_addr));