diff --git a/src/main.cpp b/src/main.cpp index 14429b6..a0beee3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -208,6 +208,14 @@ namespace { //printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", //eport, iport, iaddr, r, strupnperror(r)); } + + bool has_mapping (const std::vector& parRedirs, const std::string& parAddr, uint16_t parPort, Protocol parProtocol) { + for (auto& redir : parRedirs) { + if (redir.protocol == parProtocol and redir.internal_port == parPort and redir.internal_client == parAddr) + return true; + } + return false; + } } //unnamed namespace int main() { @@ -257,11 +265,19 @@ int main() { #endif const auto redirs = get_redirections(urls); - for (auto& redir : redirs) { - std::cout << redir.protocol << ", " << redir.remote_host << ":" << redir.external_port << " --> " << - redir.internal_client << ":" << redir.internal_port << ", " << redir.duration << ", " << - redir.enabled << R"(, ")" << redir.desc << "\"\n"; - } + + if (not has_mapping(redirs, urls.lanaddr(), 6881, Protocol::TCP)) + add_port_mapping(urls, 6881, 6881, urls.lanaddr(), "RoutArm redir", 0, Protocol::TCP); + if (not has_mapping(redirs, urls.lanaddr(), 49164, Protocol::TCP)) + add_port_mapping(urls, 49164, 49164, urls.lanaddr(), "RoutArm redir", 0, Protocol::TCP); + if (not has_mapping(redirs, urls.lanaddr(), 49164, Protocol::UDP)) + add_port_mapping(urls, 49164, 49164, urls.lanaddr(), "RoutArm redir", 0, Protocol::UDP); + + //for (auto& redir : redirs) { + // std::cout << redir.protocol << ", " << redir.remote_host << ":" << redir.external_port << " --> " << + // redir.internal_client << ":" << redir.internal_port << ", " << redir.duration << ", " << + // redir.enabled << R"(, ")" << redir.desc << "\"\n"; + //} return 0; }