diff --git a/README.md b/README.md index 75e58cbbd0..d755bd7611 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-01-05, For [#1543][bug #1543], use getpeername to retrieve client ip. 3.0.92 * v3.0, 2020-01-02, For [#1042][bug #1042], improve test coverage for config. 3.0.91 * v3.0, 2019-12-30, Fix mp4 security issue, check buffer when required size is variable. * v3.0, 2019-12-29, [3.0 alpha7(3.0.90)][r3.0a7] released. 116356 lines. @@ -1581,6 +1582,7 @@ Winlin [bug #1105]: https://github.com/ossrs/srs/issues/1105 [bug #1544]: https://github.com/ossrs/srs/issues/1544 [bug #1255]: https://github.com/ossrs/srs/issues/1255 +[bug #1543]: https://github.com/ossrs/srs/issues/1543 [bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index 9374f4e4b8..d82dfdf6a4 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -1142,7 +1142,7 @@ string srs_get_peer_ip(int fd) // discovery client information sockaddr_storage addr; socklen_t addrlen = sizeof(addr); - if (getsockname(fd, (sockaddr*)&addr, &addrlen) == -1) { + if (getpeername(fd, (sockaddr*)&addr, &addrlen) == -1) { return ""; } diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 06f93f5cbc..10dbe06cab 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -27,7 +27,7 @@ // The version config. #define VERSION_MAJOR 3 #define VERSION_MINOR 0 -#define VERSION_REVISION 91 +#define VERSION_REVISION 92 // The macros generated by configure script. #include diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index 1a38c7e1e0..1cab2c9691 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -183,11 +183,11 @@ string srs_dns_resolve(string host, int& family) char* h = (char*)saddr; socklen_t nbh = sizeof(saddr); const int r0 = getnameinfo(r->ai_addr, r->ai_addrlen, h, nbh, NULL, 0, NI_NUMERICHOST); - if(!r0) { family = r->ai_family; return string(saddr); } + return ""; } diff --git a/trunk/src/utest/srs_utest_service.cpp b/trunk/src/utest/srs_utest_service.cpp index d58638105f..c4dda4dd62 100644 --- a/trunk/src/utest/srs_utest_service.cpp +++ b/trunk/src/utest/srs_utest_service.cpp @@ -35,6 +35,7 @@ using namespace std; #include #include #include +#include class MockSrsConnection : public ISrsConnection { @@ -924,3 +925,60 @@ VOID TEST(TCPServerTest, TCPClientServer) } } +VOID TEST(TCPServerTest, CoverUtility) +{ + EXPECT_TRUE(srs_string_is_http("http://")); + EXPECT_TRUE(srs_string_is_http("https://")); + EXPECT_TRUE(srs_string_is_http("http://localhost")); + EXPECT_TRUE(srs_string_is_http("https://localhost")); + EXPECT_FALSE(srs_string_is_http("ftp://")); + EXPECT_FALSE(srs_string_is_http("ftps://")); + EXPECT_FALSE(srs_string_is_http("http:")); + EXPECT_FALSE(srs_string_is_http("https:")); + EXPECT_TRUE(srs_string_is_rtmp("rtmp://")); + EXPECT_TRUE(srs_string_is_rtmp("rtmp://localhost")); + EXPECT_FALSE(srs_string_is_rtmp("http://")); + EXPECT_FALSE(srs_string_is_rtmp("rtmp:")); + + if (true) { + sockaddr_in6 addr; + memset(&addr, 0, sizeof(addr)); + addr.sin6_family = AF_INET6; + EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)&addr)); + } + + EXPECT_FALSE(srs_net_device_is_internet("eth0")); + + if (true) { + sockaddr_in addr; + addr.sin_family = AF_INET; + + addr.sin_addr.s_addr = htonl(0x12000000); + EXPECT_TRUE(srs_net_device_is_internet((sockaddr*)&addr)); + + addr.sin_addr.s_addr = htonl(0x7f000000); + EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)&addr)); + + addr.sin_addr.s_addr = htonl(0x7f000001); + EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)&addr)); + + addr.sin_addr.s_addr = htonl(0x0a000000); + EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)&addr)); + + addr.sin_addr.s_addr = htonl(0x0a000001); + EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)&addr)); + + addr.sin_addr.s_addr = htonl(0x0affffff); + EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)&addr)); + + addr.sin_addr.s_addr = htonl(0xc0a80000); + EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)&addr)); + + addr.sin_addr.s_addr = htonl(0xc0a80001); + EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)&addr)); + + addr.sin_addr.s_addr = htonl(0xc0a8ffff); + EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)&addr)); + } +} +