Fixed some behavioral differences between Darwin and Linux w/ unitialized values (didn't notice due to this), along with an improperly named #include due to differences in case sensitivity. Also fixed memory leaks in the new User/UserList related code.
parent
3f6cfbca8e
commit
6e12546e06
2
common.h
2
common.h
|
@ -8,7 +8,7 @@ Common
|
||||||
#ifndef COMMON_H
|
#ifndef COMMON_H
|
||||||
#define COMMON_H
|
#define COMMON_H
|
||||||
|
|
||||||
#include "Net.h" // for User
|
#include "net.h" // for User
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
|
@ -174,9 +174,9 @@ void showUsers() {
|
||||||
printf("--users--");
|
printf("--users--");
|
||||||
clearAttributes();
|
clearAttributes();
|
||||||
int i;
|
int i;
|
||||||
|
int j;
|
||||||
for (i=0;i<user_list.length;i++) {
|
for (i=0;i<user_list.length;i++) {
|
||||||
printf("\n%s",user_list.users[i].nick);
|
printf("\n%s",user_list.users[i].nick);
|
||||||
int j;
|
|
||||||
for (j=0;j<user_list.users[i].address_count;j++) {
|
for (j=0;j<user_list.users[i].address_count;j++) {
|
||||||
printf("\n %s", inet_ntoa(user_list.users[i].addresses[j]));
|
printf("\n %s", inet_ntoa(user_list.users[i].addresses[j]));
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ void showInterfaces() {
|
||||||
fputs("\033[32m", stdout);
|
fputs("\033[32m", stdout);
|
||||||
for (i = 0; i < interfaces; i++) {
|
for (i = 0; i < interfaces; i++) {
|
||||||
if (ip_list[i]) {
|
if (ip_list[i]) {
|
||||||
printf("%s: %s\n", dev_list[i], ip_list[i]);
|
printf("%i: %i\n", dev_list[i], ip_list[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fputs("\033[0m",stdout);
|
fputs("\033[0m",stdout);
|
||||||
|
|
1
main.c
1
main.c
|
@ -108,6 +108,7 @@ int main() {
|
||||||
}
|
}
|
||||||
closeInterface();
|
closeInterface();
|
||||||
stopSockets(NULL);
|
stopSockets(NULL);
|
||||||
|
freeMessage(¤t_message);
|
||||||
freeInterfaces();
|
freeInterfaces();
|
||||||
freeUserList(&user_list);
|
freeUserList(&user_list);
|
||||||
freeHelp();
|
freeHelp();
|
||||||
|
|
10
net.c
10
net.c
|
@ -59,6 +59,8 @@ void handleNetInput(const char *data_buffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Message buildMessage(const char *data_buffer, struct sockaddr_in *socket) {
|
Message buildMessage(const char *data_buffer, struct sockaddr_in *socket) {
|
||||||
|
// free the old malloc'd ish
|
||||||
|
freeMessage(¤t_message);
|
||||||
Message message;
|
Message message;
|
||||||
message.address = socket->sin_addr;
|
message.address = socket->sin_addr;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
@ -81,6 +83,11 @@ Message buildMessage(const char *data_buffer, struct sockaddr_in *socket) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int freeMessage(Message *message) {
|
||||||
|
free(message->nick);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int openListenSocket() {
|
int openListenSocket() {
|
||||||
int ip_hash = generateHash("ip", CONFIG_HASH_SIZE);
|
int ip_hash = generateHash("ip", CONFIG_HASH_SIZE);
|
||||||
int port_hash = generateHash("port", CONFIG_HASH_SIZE);
|
int port_hash = generateHash("port", CONFIG_HASH_SIZE);
|
||||||
|
@ -454,5 +461,8 @@ void freeInterfaces() {
|
||||||
if (ip_list[i]) {
|
if (ip_list[i]) {
|
||||||
free(ip_list[i]);
|
free(ip_list[i]);
|
||||||
}
|
}
|
||||||
|
if (dev_list[i]) {
|
||||||
|
free(dev_list[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
net.h
2
net.h
|
@ -122,6 +122,8 @@ typedef struct {
|
||||||
} Message;
|
} Message;
|
||||||
|
|
||||||
Message buildMessage(const char *data_buffer, struct sockaddr_in *socket);
|
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
|
Message current_message; // global message struct, contains last packet
|
||||||
|
|
||||||
|
|
9
users.c
9
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) {
|
int addUser(UserList *user_list, const char nick[], struct in_addr address) {
|
||||||
user_list->length++;
|
user_list->length++;
|
||||||
|
//printf("Adding!\n");
|
||||||
user_list->users = realloc(user_list->users, (user_list->length)*sizeof(User));
|
user_list->users = realloc(user_list->users, (user_list->length)*sizeof(User));
|
||||||
User new_user;
|
User new_user;
|
||||||
new_user.last_address = address;
|
new_user.last_address = address;
|
||||||
//new_user.nick = realloc(new_user.nick, strlen(nick)+1);
|
new_user.nick = realloc(new_user.nick, strlen(nick)+1);
|
||||||
new_user.nick = malloc(strlen(nick));
|
// new_user.nick = malloc(strlen(nick));
|
||||||
new_user.addresses = malloc(1);
|
new_user.addresses = malloc(1);
|
||||||
|
new_user.address_count = 0;
|
||||||
//strcpy(new_user.nick, nick);
|
//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));
|
// new_user.last_address = malloc(sizeof(struct in_addr));
|
||||||
// memcpy(new_user.last_address, &address, 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));
|
//new_user.last_address = malloc(new_user.last_address, sizeof(struct in_addr));
|
||||||
|
|
Loading…
Reference in New Issue