diff --git a/src/cpp/rtps/transport/TCPv6Transport.cpp b/src/cpp/rtps/transport/TCPv6Transport.cpp index ae0a225cfcd..5473aac671d 100644 --- a/src/cpp/rtps/transport/TCPv6Transport.cpp +++ b/src/cpp/rtps/transport/TCPv6Transport.cpp @@ -80,9 +80,29 @@ TCPv6Transport::TCPv6Transport( : TCPTransportInterface(LOCATOR_KIND_TCPv6) , configuration_(descriptor) { - for (const auto& interface : descriptor.interfaceWhiteList) + if (!descriptor.interfaceWhiteList.empty()) { - interface_whitelist_.emplace_back(ip::address_v6::from_string(interface)); + const auto white_begin = descriptor.interfaceWhiteList.begin(); + const auto white_end = descriptor.interfaceWhiteList.end(); + + std::vector local_interfaces; + get_ipv6s(local_interfaces, true); + for (const IPFinder::info_IP& infoIP : local_interfaces) + { + if (std::find_if(white_begin, white_end, [this, infoIP](const std::string& white_list_element) + { + return compare_ips(white_list_element, infoIP.name); + }) != white_end ) + { + interface_whitelist_.emplace_back(ip::address_v6::from_string(infoIP.name)); + } + } + + if (interface_whitelist_.empty()) + { + EPROSIMA_LOG_ERROR(TRANSPORT, "All whitelist interfaces were filtered out"); + interface_whitelist_.emplace_back(ip::address_v6::from_string("2001:db8::")); + } } for (uint16_t& port : configuration_.listening_ports)