ossrs / srs

SRS is a simple, high-efficiency, real-time video server supporting RTMP, WebRTC, HLS, HTTP-FLV, SRT, MPEG-DASH, and GB28181.

Home Page:https://ossrs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SRS 3.0 does not check if the address is empty when reading IP.

typcn opened this issue · comments

commented

image

In srs_service_utility.cpp line 135, ifa_addr may be empty, causing a crash at startup.

TRANS_BY_GPT3

Can't the network card be read?

TRANS_BY_GPT3

commented
--- a/trunk/src/service/srs_service_utility.cpp
+++ b/trunk/src/service/srs_service_utility.cpp
@@ -149,7 +149,7 @@ void retrieve_local_ips()
     // Discover IPv4 first.
     for (ifaddrs* p = ifap; p ; p = p->ifa_next) {
         ifaddrs* cur = p;
-        
+        if(!cur->ifa_addr) continue;
         // retrieve IP address, ignore the tun0 network device, whose addr is NULL.
         // @see: https://github.com/ossrs/srs/issues/141
         bool ipv4 = (cur->ifa_addr->sa_family == AF_INET);
@@ -163,7 +163,7 @@ void retrieve_local_ips()
     // Then, discover IPv6 addresses.
     for (ifaddrs* p = ifap; p ; p = p->ifa_next) {
         ifaddrs* cur = p;
-        
+        if(!cur->ifa_addr) continue;
         // retrieve IP address, ignore the tun0 network device, whose addr is NULL.
         // @see: https://github.com/ossrs/srs/issues/141
         bool ipv6 = (cur->ifa_addr->sa_family == AF_INET6);

If a network card does not have any IP address, ifa_addr will be empty, so it needs to be checked.

TRANS_BY_GPT3

👍

srs did not obtain an IPv4 address, but obtained an IPv6 address, causing an error in the RTMP connection socket. It is necessary to specify the network card address, as automatic DHCP address acquisition is not working. Therefore, configure the specified IP or server_id configuration.

TRANS_BY_GPT3