Skip to content

Commit

Permalink
Fix #1543, use getpeername to retrieve client ip. 3.0.92
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jan 5, 2020
1 parent 498f3c5 commit bc6c61e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <strong>v3.0, 2019-12-29, [3.0 alpha7(3.0.90)][r3.0a7] released. 116356 lines.</strong>
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}

Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <srs_auto_headers.hpp>
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/kernel/srs_kernel_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}

Expand Down
58 changes: 58 additions & 0 deletions trunk/src/utest/srs_utest_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using namespace std;
#include <srs_core_autofree.hpp>
#include <srs_utest_protocol.hpp>
#include <srs_utest_http.hpp>
#include <srs_service_utility.hpp>

class MockSrsConnection : public ISrsConnection
{
Expand Down Expand Up @@ -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));
}
}

0 comments on commit bc6c61e

Please sign in to comment.