1
0
Fork 0

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

pull/1/head
Vitaliy Filippov 2023-12-17 13:25:56 +03:00
parent 575475de71
commit 1a704e06ab
1 changed files with 4 additions and 3 deletions

View File

@ -8,6 +8,7 @@
#include <stdio.h>
#include <stdexcept>
#include <set>
#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);
}
}
std::vector<std::string> addresses;
std::set<std::string> addresses;
ifaddrs *list, *ifa;
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));
}
addresses.push_back(std::string(addr));
addresses.insert(std::string(addr));
}
}
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)