From f31c5fa59ee3afafc66bfb53c159eff301b537af Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Mon, 26 Apr 2021 14:46:52 +0200 Subject: Aktualizacja routera, juz ostatnia --- Semestr 4/rr1r/lista2/L2Z9.pdf | Bin 0 -> 378611 bytes Semestr 4/rr1r/lista4/RR1R-04.pdf | Bin 0 -> 137777 bytes Semestr 4/rr1r/lista5/RR1R-05.pdf | Bin 0 -> 99963 bytes Semestr 4/rr1r/lista6/RR1R-06.pdf | Bin 0 -> 120530 bytes Semestr 4/rr1r/lista7/RR1R-07.pdf | Bin 0 -> 85380 bytes Semestr 4/rr1r/lista8/RR1R-08.pdf | Bin 0 -> 94183 bytes Semestr 4/rr1r/lista9/RR1R-09.pdf | Bin 0 -> 99502 bytes Semestr 4/sieci/pracownia2/router/dist_vector.c | 5 ++++ Semestr 4/sieci/pracownia2/router/linked_list.c | 5 ++++ Semestr 4/sieci/pracownia2/router/makefile | 18 +++++++------- Semestr 4/sieci/pracownia2/router/network_addr.c | 7 +++++- Semestr 4/sieci/pracownia2/router/router.c | 5 ++++ Semestr 4/sieci/pracownia2/router/test.c | 5 ++++ Semestr 4/sieci/pracownia2/router/utils.c | 30 ++++++----------------- 14 files changed, 43 insertions(+), 32 deletions(-) create mode 100644 Semestr 4/rr1r/lista2/L2Z9.pdf create mode 100644 Semestr 4/rr1r/lista4/RR1R-04.pdf create mode 100644 Semestr 4/rr1r/lista5/RR1R-05.pdf create mode 100644 Semestr 4/rr1r/lista6/RR1R-06.pdf create mode 100644 Semestr 4/rr1r/lista7/RR1R-07.pdf create mode 100644 Semestr 4/rr1r/lista8/RR1R-08.pdf create mode 100644 Semestr 4/rr1r/lista9/RR1R-09.pdf diff --git a/Semestr 4/rr1r/lista2/L2Z9.pdf b/Semestr 4/rr1r/lista2/L2Z9.pdf new file mode 100644 index 0000000..0f3675c Binary files /dev/null and b/Semestr 4/rr1r/lista2/L2Z9.pdf differ diff --git a/Semestr 4/rr1r/lista4/RR1R-04.pdf b/Semestr 4/rr1r/lista4/RR1R-04.pdf new file mode 100644 index 0000000..4dfc8c3 Binary files /dev/null and b/Semestr 4/rr1r/lista4/RR1R-04.pdf differ diff --git a/Semestr 4/rr1r/lista5/RR1R-05.pdf b/Semestr 4/rr1r/lista5/RR1R-05.pdf new file mode 100644 index 0000000..7dfa8d2 Binary files /dev/null and b/Semestr 4/rr1r/lista5/RR1R-05.pdf differ diff --git a/Semestr 4/rr1r/lista6/RR1R-06.pdf b/Semestr 4/rr1r/lista6/RR1R-06.pdf new file mode 100644 index 0000000..596bb38 Binary files /dev/null and b/Semestr 4/rr1r/lista6/RR1R-06.pdf differ diff --git a/Semestr 4/rr1r/lista7/RR1R-07.pdf b/Semestr 4/rr1r/lista7/RR1R-07.pdf new file mode 100644 index 0000000..7a6c6e1 Binary files /dev/null and b/Semestr 4/rr1r/lista7/RR1R-07.pdf differ diff --git a/Semestr 4/rr1r/lista8/RR1R-08.pdf b/Semestr 4/rr1r/lista8/RR1R-08.pdf new file mode 100644 index 0000000..4e39081 Binary files /dev/null and b/Semestr 4/rr1r/lista8/RR1R-08.pdf differ diff --git a/Semestr 4/rr1r/lista9/RR1R-09.pdf b/Semestr 4/rr1r/lista9/RR1R-09.pdf new file mode 100644 index 0000000..44191db Binary files /dev/null and b/Semestr 4/rr1r/lista9/RR1R-09.pdf differ 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 #include 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 #include 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 #include @@ -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 #include #include 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 #include 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 #include @@ -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); } } -- cgit v1.2.3