diff options
author | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-04-22 21:44:03 +0200 |
---|---|---|
committer | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-04-22 21:44:03 +0200 |
commit | 0dacd15b6ee8cdb3fe6b375a430f0e2c1ea36d7f (patch) | |
tree | ab5aa37e6a6a3676f5dedbc9d5a18bea364752e0 /Semestr 4/sieci/pracownia2/router | |
parent | 7dd4ef3c7c724badfe66a027ea3289d12ec0da46 (diff) |
Added one feature
Diffstat (limited to 'Semestr 4/sieci/pracownia2/router')
-rw-r--r-- | Semestr 4/sieci/pracownia2/router/utils.c | 23 |
1 files changed, 18 insertions, 5 deletions
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) { |