Allow multiple interfaces with the same IP address, for "simple routed" full mesh network

This commit is contained in:
Vitaliy Filippov
2023-12-17 13:25:56 +03:00
parent 575475de71
commit 1a704e06ab
+4 -3
View File
@@ -8,6 +8,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdexcept> #include <stdexcept>
#include <set>
#include "addr_util.h" #include "addr_util.h"
@@ -135,7 +136,7 @@ std::vector<std::string> getifaddr_list(std::vector<std::string> mask_cfg, bool
throw std::runtime_error((include_v6 ? "Invalid IPv4 address mask: " : "Invalid IP address mask: ") + mask); throw std::runtime_error((include_v6 ? "Invalid IPv4 address mask: " : "Invalid IP address mask: ") + mask);
} }
} }
std::vector<std::string> addresses; std::set<std::string> addresses;
ifaddrs *list, *ifa; ifaddrs *list, *ifa;
if (getifaddrs(&list) == -1) if (getifaddrs(&list) == -1)
{ {
@@ -183,11 +184,11 @@ std::vector<std::string> getifaddr_list(std::vector<std::string> mask_cfg, bool
{ {
throw std::runtime_error(std::string("inet_ntop: ") + strerror(errno)); throw std::runtime_error(std::string("inet_ntop: ") + strerror(errno));
} }
addresses.push_back(std::string(addr)); addresses.insert(std::string(addr));
} }
} }
freeifaddrs(list); freeifaddrs(list);
return addresses; return std::vector<std::string>(addresses.begin(), addresses.end());
} }
int create_and_bind_socket(std::string bind_address, int bind_port, int listen_backlog, int *listening_port) int create_and_bind_socket(std::string bind_address, int bind_port, int listen_backlog, int *listening_port)