1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +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 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-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, 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> * <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; _port = p;
stream_id = sid; stream_id = sid;
// TODO: support listen at <[ip:]port> // 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(); cache = new SrsRtpPacket();
pprint = SrsPithyPrint::create_caster(); pprint = SrsPithyPrint::create_caster();
} }

View file

@ -1018,8 +1018,7 @@ srs_error_t SrsServer::listen_rtmp()
SrsListener* listener = new SrsBufferListener(this, SrsListenerRtmpStream); SrsListener* listener = new SrsBufferListener(this, SrsListenerRtmpStream);
listeners.push_back(listener); listeners.push_back(listener);
std::string ip; int port; string ip;
int port;
srs_parse_endpoint(ip_ports[i], ip, port); srs_parse_endpoint(ip_ports[i], ip, port);
if ((err = listener->listen(ip, port)) != srs_success) { 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> // 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); return srs_error_wrap(err, "listen at %d", port);
} }
} }

View file

@ -27,7 +27,7 @@
// The version config. // The version config.
#define VERSION_MAJOR 3 #define VERSION_MAJOR 3
#define VERSION_MINOR 0 #define VERSION_MINOR 0
#define VERSION_REVISION 58 #define VERSION_REVISION 59
// The macros generated by configure script. // The macros generated by configure script.
#include <srs_auto_headers.hpp> #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); bool ipv4_active = false;
bool ipv6_active = false;
// socket() if (true) {
// A -1 is returned if an error occurs, otherwise the return value is a int fd = socket(AF_INET, SOCK_DGRAM, 0);
// descriptor referencing the socket.
if(fd != -1) { if(fd != -1) {
ipv4_active = true;
close(fd); close(fd);
return "::"; }
}
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"; 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); const string sport = hostport.substr(pos + 1);
port = ::atoi(sport.c_str()); port = ::atoi(sport.c_str());
} else { } else {
ip = srs_any_address4listener(); ip = srs_any_address_for_listener();
port = ::atoi(hostport.c_str()); 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(); extern srs_utime_t srs_update_system_time();
// The "ANY" address to listen, it's "0.0.0.0" for ipv4, and "::" for ipv6. // 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. // The dns resolve utility, return the resolved ip address.
extern std::string srs_dns_resolve(std::string host, int& family); extern std::string srs_dns_resolve(std::string host, int& family);

View file

@ -4086,7 +4086,7 @@ VOID TEST(KernelUtilityTest, CoverTimeUtilityAll)
} }
if (true) { if (true) {
string ep = srs_any_address4listener(); string ep = srs_any_address_for_listener();
EXPECT_TRUE(ep == "0.0.0.0" || ep == "::"); EXPECT_TRUE(ep == "0.0.0.0" || ep == "::");
} }