From cf37e364ce7f148bd73af5074404fb02eb772c07 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 12 Mar 2020 09:35:49 -0700 Subject: [PATCH] modules/console: Add net service console cmd. --- modules/console.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/modules/console.cc b/modules/console.cc index 5783dc79e..590413313 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -5419,6 +5419,45 @@ console_cmd__net__addrs(opt &out, const string_view &line) return true; } +bool +console_cmd__net__service(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "service", "proto" + }}; + + const string_view &service + { + param.at("service") + }; + + const string_view &proto + { + param.at("proto", "tcp"_sv) + }; + + if(lex_castable(service)) + { + char buf[64]; + const auto name + { + net::dns::service_name(buf, lex_cast(service), proto) + }; + + out << name << std::endl; + return true; + } + + const auto port + { + net::dns::service_port(service, proto) + }; + + out << port << std::endl; + return true; +} + bool console_cmd__net__host(opt &out, const string_view &line) {