diff options
Diffstat (limited to 'Semestr 4/sieci/pracownia2')
-rw-r--r-- | Semestr 4/sieci/pracownia2/router/dist_vector.c | 5 | ||||
-rw-r--r-- | Semestr 4/sieci/pracownia2/router/linked_list.c | 5 | ||||
-rw-r--r-- | Semestr 4/sieci/pracownia2/router/makefile | 18 | ||||
-rw-r--r-- | Semestr 4/sieci/pracownia2/router/network_addr.c | 7 | ||||
-rw-r--r-- | Semestr 4/sieci/pracownia2/router/router.c | 5 | ||||
-rw-r--r-- | Semestr 4/sieci/pracownia2/router/test.c | 5 | ||||
-rw-r--r-- | Semestr 4/sieci/pracownia2/router/utils.c | 30 |
7 files changed, 43 insertions, 32 deletions
diff --git a/Semestr 4/sieci/pracownia2/router/dist_vector.c b/Semestr 4/sieci/pracownia2/router/dist_vector.c index 15ad851..74ae82e 100644 --- a/Semestr 4/sieci/pracownia2/router/dist_vector.c +++ b/Semestr 4/sieci/pracownia2/router/dist_vector.c @@ -1,3 +1,8 @@ +/* + * Program: router + * Autor: Franciszek Malinka, 316093 + */ + #include "dist_vector.h" #include <stdio.h> #include <time.h> diff --git a/Semestr 4/sieci/pracownia2/router/linked_list.c b/Semestr 4/sieci/pracownia2/router/linked_list.c index c0f1930..16113ac 100644 --- a/Semestr 4/sieci/pracownia2/router/linked_list.c +++ b/Semestr 4/sieci/pracownia2/router/linked_list.c @@ -1,3 +1,8 @@ +/* + * Program: router + * Autor: Franciszek Malinka, 316093 + */ + #include "linked_list.h" #include <stdlib.h> #include <stdint.h> diff --git a/Semestr 4/sieci/pracownia2/router/makefile b/Semestr 4/sieci/pracownia2/router/makefile index 87bc15a..bf6a327 100644 --- a/Semestr 4/sieci/pracownia2/router/makefile +++ b/Semestr 4/sieci/pracownia2/router/makefile @@ -1,12 +1,12 @@ -CC := gcc -CFLAGS := -Og -std=gnu17 -Wall -Wall -fsanitize=address -fsanitize=undefined -TARGET := router -TEST := test -DEPS := config.h - -ODIR := obj -_OBJ := router.o utils.o linked_list.o network_addr.o dist_vector.o -OBJ := $(patsubst %,$(ODIR)/%,$(_OBJ)) +CC := gcc +CFLAGS := -O2 -std=gnu17 -Wall -Wall -Wno-unused-result +TARGET := router +TEST := test +DEPS := config.h + +ODIR := obj +_OBJ := router.o utils.o linked_list.o network_addr.o dist_vector.o +OBJ := $(patsubst %,$(ODIR)/%,$(_OBJ)) _TEST_OBJ := test.o linked_list.o TEST_OBJ := $(patsubst %,$(ODIR)/%,$(_TEST_OBJ)) diff --git a/Semestr 4/sieci/pracownia2/router/network_addr.c b/Semestr 4/sieci/pracownia2/router/network_addr.c index d1982c2..cac1060 100644 --- a/Semestr 4/sieci/pracownia2/router/network_addr.c +++ b/Semestr 4/sieci/pracownia2/router/network_addr.c @@ -1,3 +1,8 @@ +/* + * Program: router + * Autor: Franciszek Malinka, 316093 + */ + #include "network_addr.h" #include <stdio.h> #include <string.h> @@ -52,7 +57,7 @@ struct network_addr stona(char *str) { char addr[20]; size_t ip_preffix = strcspn(str, "/"); - strncpy(addr, str, strlen(str)); + strncpy(addr, str, ip_preffix); addr[ip_preffix] = 0; inet_pton(AF_INET, addr, &(result.addr)); result.netmask = atoi(str + ip_preffix + 1); diff --git a/Semestr 4/sieci/pracownia2/router/router.c b/Semestr 4/sieci/pracownia2/router/router.c index 3831aac..b5e732c 100644 --- a/Semestr 4/sieci/pracownia2/router/router.c +++ b/Semestr 4/sieci/pracownia2/router/router.c @@ -1,3 +1,8 @@ +/* + * Program: router + * Autor: Franciszek Malinka, 316093 + */ + #include <stdio.h> #include <errno.h> #include <strings.h> diff --git a/Semestr 4/sieci/pracownia2/router/test.c b/Semestr 4/sieci/pracownia2/router/test.c index e086e55..958ff36 100644 --- a/Semestr 4/sieci/pracownia2/router/test.c +++ b/Semestr 4/sieci/pracownia2/router/test.c @@ -1,3 +1,8 @@ +/* + * Program: router + * Autor: Franciszek Malinka, 316093 + */ + #include "linked_list.h" #include <stdlib.h> #include <stdio.h> diff --git a/Semestr 4/sieci/pracownia2/router/utils.c b/Semestr 4/sieci/pracownia2/router/utils.c index cd5a58d..0c0cae5 100644 --- a/Semestr 4/sieci/pracownia2/router/utils.c +++ b/Semestr 4/sieci/pracownia2/router/utils.c @@ -1,3 +1,8 @@ +/* + * Program: router + * Autor: Franciszek Malinka, 316093 + */ + #include "utils.h" #include <arpa/inet.h> #include <netinet/ip.h> @@ -86,23 +91,13 @@ size_t recv_message(int sockfd, char *buffer, struct sockaddr_in *sender) { fprintf(stderr, "recvfrom error: %s\n", strerror(errno)); exit(EXIT_FAILURE); } - // printf("Received a message: "); - // for (int i = 0 ; i < 9; i++) { - // printf("%u ", (uint8_t)buffer[i]); - // } - // printf("\n"); + return datagram_len; } struct vector_item parse_message(char *buffer, struct sockaddr_in *sender) { - // printf("Parsing a message: "); - // for (int i = 0 ; i < 9; i++) { - // printf("%u ", (uint8_t)buffer[i]); - // } - // printf("\n"); struct vector_item res; uint32_t ip_addr = *(uint32_t *)buffer; - // ip_addr = ip_addr; uint32_t dist = *(uint32_t *)(buffer + 5); dist = ntohl(dist); @@ -117,9 +112,6 @@ struct vector_item parse_message(char *buffer, struct sockaddr_in *sender) { inet_ntop(AF_INET, &res.network.addr, addr, sizeof(addr)); char via[20]; inet_ntop(AF_INET, &sender->sin_addr, via, sizeof(via)); - - // printf("Po ludzku: %s/%d, distance %d, via %s\n", addr, res.network.netmask, res.distance, via); - return res; } @@ -142,11 +134,7 @@ int _send_item(int sockfd, struct network_addr network, struct vector_item item) char addr[20]; inet_ntop(AF_INET, &na, addr, sizeof(addr)); - // printf("Sending datagram to %s: ", addr); - // for (int i = 0 ; i < DV_DATAGRAM_LEN; i++) { - // printf("%u ", (uint8_t)message[i]); - // } - // printf("\nmessage_len: %ld\n", message_len); + int result; if ((result = send_message(sockfd, message, message_len, na)) != message_len) { // fprintf(stderr, "sendto error: %s\n", strerror(errno)); @@ -155,12 +143,11 @@ int _send_item(int sockfd, struct network_addr network, struct vector_item item) } void listen_for_routers(int sockfd, int timeout, int networks_number, struct network_addr *networks, uint16_t *dists, list_t *dv) { - // printf("Listening for %dms.\n", timeout); char buffer[IP_MAXPACKET + 1]; struct sockaddr_in sender; while (poll_socket_modify_timeout(sockfd, &timeout)) { - size_t buf_len = recv_message(sockfd, buffer, &sender); + recv_message(sockfd, buffer, &sender); struct vector_item new_item = parse_message(buffer, &sender); bool is_neighbour = false; @@ -209,7 +196,6 @@ void propagate_distance_vector(int sockfd, int networks_number, struct network_a struct vector_item self_item; self_item.distance = dists[i]; self_item.network = networks[i]; - // printf("Sending self message: %d\n", dists[i]); _send_item(sockfd, networks[i], self_item); } } |