Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't override the default port if a value of 0 is sent explicitly #1754

Merged
merged 1 commit into from Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions trunk/src/kernel/srs_kernel_utility.cpp
Original file line number Diff line number Diff line change
@@ -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());
}
}
8 changes: 8 additions & 0 deletions trunk/src/utest/srs_utest_kernel.cpp
Original file line number Diff line number Diff line change
@@ -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();