From 5633af0904ca10e1fb50d23af85d0024f5fef8af Mon Sep 17 00:00:00 2001 From: Matheus Macabu Date: Mon, 11 May 2020 16:09:12 +0200 Subject: [PATCH] kernel/utility: if port is explicity set to 0, use default --- trunk/src/kernel/srs_kernel_utility.cpp | 4 ++-- trunk/src/utest/srs_utest_kernel.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index 72e2d705ee..4678da9dc1 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -209,7 +209,7 @@ void srs_parse_hostport(string hostport, string& host, int& port) if (hostport.find(":") == pos) { host = hostport.substr(0, pos); string p = hostport.substr(pos + 1); - if (!p.empty()) { + if (!p.empty() && p != "0") { port = ::atoi(p.c_str()); } return; @@ -224,7 +224,7 @@ void srs_parse_hostport(string hostport, string& host, int& port) // For ipv6, [host]:port. host = hostport.substr(1, pos - 1); string p = hostport.substr(pos + 2); - if (!p.empty()) { + if (!p.empty() && p != "0") { port = ::atoi(p.c_str()); } } diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp index b99a0e3b2b..9d43c507e5 100644 --- a/trunk/src/utest/srs_utest_kernel.cpp +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -4386,6 +4386,14 @@ VOID TEST(KernelUtilityTest, CoverTimeUtilityAll) srs_parse_hostport("domain.com", host, port); EXPECT_STREQ("domain.com", host.c_str()); } + + if (true) { + string host; + int port = 1935; + srs_parse_hostport("domain.com:0", host, port); + EXPECT_EQ(1935, port); + EXPECT_STREQ("domain.com", host.c_str()); + } if (true) { string ep = srs_any_address_for_listener();