1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-12 11:21:52 +00:00

We prefer ipv4, only use ipv6 if ipv4 is disabled. 3.0.59

This commit is contained in:
winlin 2019-10-07 10:34:55 +08:00
parent b0227e0d22
commit e045b0a619
7 changed files with 30 additions and 18 deletions

View file

@ -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
* <strong>v3.0, 2019-10-04, [3.0 alpha0(3.0.56)][r3.0a0] released. 107946 lines.</strong>

View file

@ -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();
}

View file

@ -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);
}
}

View file

@ -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 <srs_auto_headers.hpp>

View file

@ -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());
}
}

View file

@ -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);

View file

@ -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 == "::");
}