diff --git a/README.md b/README.md
index 118e17db0..ceebbbf54 100755
--- a/README.md
+++ b/README.md
@@ -151,6 +151,7 @@ Please select according to languages:
### V3 changes
+* v3.0, 2019-10-06, We prefer ipv4, only use ipv6 if ipv4 is disabled. 3.0.59
* v3.0, 2019-10-05, Support systemctl service for CentOS7. 3.0.58
* v3.0, 2019-10-04, Disable SO_REUSEPORT if not supported. 3.0.57
* v3.0, 2019-10-04, [3.0 alpha0(3.0.56)][r3.0a0] released. 107946 lines.
diff --git a/trunk/src/app/srs_app_rtsp.cpp b/trunk/src/app/srs_app_rtsp.cpp
index 35fffa620..b96b2190e 100644
--- a/trunk/src/app/srs_app_rtsp.cpp
+++ b/trunk/src/app/srs_app_rtsp.cpp
@@ -52,7 +52,7 @@ SrsRtpConn::SrsRtpConn(SrsRtspConn* r, int p, int sid)
_port = p;
stream_id = sid;
// TODO: support listen at <[ip:]port>
- listener = new SrsUdpListener(this, srs_any_address4listener(), p);
+ listener = new SrsUdpListener(this, srs_any_address_for_listener(), p);
cache = new SrsRtpPacket();
pprint = SrsPithyPrint::create_caster();
}
diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp
index 1901da4db..33f571d32 100644
--- a/trunk/src/app/srs_app_server.cpp
+++ b/trunk/src/app/srs_app_server.cpp
@@ -1017,9 +1017,8 @@ srs_error_t SrsServer::listen_rtmp()
for (int i = 0; i < (int)ip_ports.size(); i++) {
SrsListener* listener = new SrsBufferListener(this, SrsListenerRtmpStream);
listeners.push_back(listener);
-
- std::string ip;
- int port;
+
+ int port; string ip;
srs_parse_endpoint(ip_ports[i], ip, port);
if ((err = listener->listen(ip, port)) != srs_success) {
@@ -1113,7 +1112,7 @@ srs_error_t SrsServer::listen_stream_caster()
}
// TODO: support listen at <[ip:]port>
- if ((err = listener->listen(srs_any_address4listener(), port)) != srs_success) {
+ if ((err = listener->listen(srs_any_address_for_listener(), port)) != srs_success) {
return srs_error_wrap(err, "listen at %d", port);
}
}
diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp
index 8ae0953a5..1753f1708 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 58
+#define VERSION_REVISION 59
// 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 d0f19d86c..93ea6a895 100644
--- a/trunk/src/kernel/srs_kernel_utility.cpp
+++ b/trunk/src/kernel/srs_kernel_utility.cpp
@@ -210,18 +210,29 @@ void srs_parse_hostport(const string& hostport, string& host, int& port)
}
}
-string srs_any_address4listener()
+string srs_any_address_for_listener()
{
- int fd = socket(AF_INET6, SOCK_DGRAM, 0);
-
- // socket()
- // A -1 is returned if an error occurs, otherwise the return value is a
- // descriptor referencing the socket.
- if(fd != -1) {
- close(fd);
+ bool ipv4_active = false;
+ bool ipv6_active = false;
+
+ if (true) {
+ int fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if(fd != -1) {
+ ipv4_active = true;
+ close(fd);
+ }
+ }
+ if (true) {
+ int fd = socket(AF_INET6, SOCK_DGRAM, 0);
+ if(fd != -1) {
+ ipv6_active = true;
+ close(fd);
+ }
+ }
+
+ if (ipv6_active && !ipv4_active) {
return "::";
}
-
return "0.0.0.0";
}
@@ -240,7 +251,7 @@ void srs_parse_endpoint(string hostport, string& ip, int& port)
const string sport = hostport.substr(pos + 1);
port = ::atoi(sport.c_str());
} else {
- ip = srs_any_address4listener();
+ ip = srs_any_address_for_listener();
port = ::atoi(hostport.c_str());
}
}
diff --git a/trunk/src/kernel/srs_kernel_utility.hpp b/trunk/src/kernel/srs_kernel_utility.hpp
index 99a3fdc6a..3b55a520f 100644
--- a/trunk/src/kernel/srs_kernel_utility.hpp
+++ b/trunk/src/kernel/srs_kernel_utility.hpp
@@ -48,7 +48,8 @@ extern srs_utime_t srs_get_system_startup_time();
extern srs_utime_t srs_update_system_time();
// The "ANY" address to listen, it's "0.0.0.0" for ipv4, and "::" for ipv6.
-extern std::string srs_any_address4listener();
+// @remark We prefer ipv4, only use ipv6 if ipv4 is disabled.
+extern std::string srs_any_address_for_listener();
// The dns resolve utility, return the resolved ip address.
extern std::string srs_dns_resolve(std::string host, int& family);
diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp
index 2e4e0960c..7f0479ddb 100644
--- a/trunk/src/utest/srs_utest_kernel.cpp
+++ b/trunk/src/utest/srs_utest_kernel.cpp
@@ -4086,7 +4086,7 @@ VOID TEST(KernelUtilityTest, CoverTimeUtilityAll)
}
if (true) {
- string ep = srs_any_address4listener();
+ string ep = srs_any_address_for_listener();
EXPECT_TRUE(ep == "0.0.0.0" || ep == "::");
}