diff --git a/linkedlist.c b/linkedlist.c index 2a65f41..bd76ae2 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -2,11 +2,13 @@ // Created by jake on 12/17/19. // +#include #include "linkedlist.h" LinkedList *linkedlist_new() { LinkedList *tmp = (LinkedList *) malloc(sizeof(LinkedList)); tmp->data = NULL; + tmp->next = NULL; return tmp; } @@ -15,16 +17,15 @@ LinkedList *linkedlist_new() { * @param head The first node in the list. * @param data Our data to add to the list. */ -void linkedlist_add(LinkedList *head, char *data) { +void linkedlist_add(LinkedList **head, char *data) { // Create a pointer to the head element. - LinkedList *tmp = head; + LinkedList *tmp = *head; - // Head was null? Create a new node. - if (head == NULL) { - head = linkedlist_new(); - head->data = data; + if (tmp->data == NULL) { + tmp->data = data; } else { + fprintf(stderr, "Adding to the body\n"); // Iterate until we don't have a next node. while ((tmp = tmp->next) != NULL) ; @@ -34,6 +35,17 @@ void linkedlist_add(LinkedList *head, char *data) { } } +void linkedlist_print(LinkedList *head) { + fprintf(stderr, "Entering linked list print\n"); + LinkedList *tmp = head; + while (tmp != NULL) { + fprintf(stderr, "Node: %s\n", tmp->data); + tmp = tmp->next; + } +} +void free_list(LinkedList *head) { + +} void free_node(LinkedList *node) { free(node->data); free(node); diff --git a/linkedlist.h b/linkedlist.h index 93a4d2e..ef3a4eb 100644 --- a/linkedlist.h +++ b/linkedlist.h @@ -16,6 +16,6 @@ typedef struct linkedlist { } LinkedList; LinkedList *linkedlist_new(); -void linkedlist_add(LinkedList *head, char *data); -void linkedlist_print(LinkedList *head, char *data); +void linkedlist_add(LinkedList **head, char *data); +void linkedlist_print(LinkedList *head); #endif //HOSTBLOCKER_LINKEDLIST_H diff --git a/main.c b/main.c index 931ad6b..dbcf222 100644 --- a/main.c +++ b/main.c @@ -21,7 +21,7 @@ /** GLOBALS **/ // Our rule we use to blackhole domains const char *blockString = "0.0.0.0 "; -LinkedList *hosts = (LinkedList *) NULL; +LinkedList *hosts = NULL; // The current hardcoded location of the hosts file. static char *HOSTFILE = "/etc/hosts"; @@ -140,6 +140,9 @@ void daemonize() { int main(int argc, char **argv) { // Install a sigint handler to help us clean up. + linkedlist_add(hosts, "hello.com"); + linkedlist_add(hosts, "heloworld.com"); + linkedlist_print(hosts); signal(SIGINT, int_handler); if (getuid() != 0) {