From 0dacd15b6ee8cdb3fe6b375a430f0e2c1ea36d7f Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Thu, 22 Apr 2021 21:44:03 +0200 Subject: Added one feature --- Semestr 4/sieci/pracownia2/router/utils.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'Semestr 4/sieci/pracownia2') diff --git a/Semestr 4/sieci/pracownia2/router/utils.c b/Semestr 4/sieci/pracownia2/router/utils.c index b975934..cd5a58d 100644 --- a/Semestr 4/sieci/pracownia2/router/utils.c +++ b/Semestr 4/sieci/pracownia2/router/utils.c @@ -162,24 +162,37 @@ void listen_for_routers(int sockfd, int timeout, int networks_number, struct net while (poll_socket_modify_timeout(sockfd, &timeout)) { size_t buf_len = recv_message(sockfd, buffer, &sender); struct vector_item new_item = parse_message(buffer, &sender); - // char addr[20]; - // inet_ntop(AF_INET, &sender.sin_addr, addr, sizeof(addr)); - // printf("Via ip: %s\n", addr); + + bool is_neighbour = false; + for (int i = 0; i < networks_number; i++) { + if (is_from_network(sender.sin_addr, networks[i])) { + is_neighbour = true; + break; + } + } + + /* Shouldn't happen, just in case. */ + if (!is_neighbour) { + char addr[20]; + inet_ntop(AF_INET, &sender.sin_addr, addr, sizeof(addr)); + fprintf(stderr, "Received datagram from %s, he is in none of my networks, ignoring\n. Maybe his VM routing table is configured incorrectly?\n", addr); + continue; + } if (!is_from_network(sender.sin_addr, new_item.network)) { + new_item.is_connected_directly = false; + for (int i = 0; i < networks_number; i++) { if (is_from_network(sender.sin_addr, networks[i])) { new_item.distance += dists[i]; break; } } - new_item.is_connected_directly = false; } update_dv_new_item(dv, new_item); } update_dv_reachability(dv); - // printf("Finished listening\n\n"); } void propagate_distance_vector(int sockfd, int networks_number, struct network_addr *networks, uint16_t *dists, list_t *dv) { -- cgit v1.2.3