Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2015-06-19 11:59:41 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8cd68a1eb3fe7136651a7408d4e5a1492e98c60d
8cd68a1e
1 parent
2e437a28
ignore any intranet bandwidth.
显示空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
57 行增加
和
4 行删除
trunk/src/app/srs_app_utility.cpp
trunk/src/app/srs_app_utility.hpp
trunk/src/app/srs_app_utility.cpp
查看文件 @
8cd68a1
...
...
@@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#endif
#include <stdlib.h>
#include <sys/time.h>
#include <map>
using
namespace
std
;
#include <srs_kernel_log.hpp>
...
...
@@ -1018,6 +1019,46 @@ void srs_update_network_devices()
#endif
}
// we detect all network device as internet or intranet device, by its ip address.
// key is device name, for instance, eth0
// value is whether internet, for instance, true.
static
std
::
map
<
std
::
string
,
bool
>
_srs_device_ifs
;
bool
srs_net_device_is_internet
(
string
ifname
)
{
if
(
_srs_device_ifs
.
find
(
ifname
)
==
_srs_device_ifs
.
end
())
{
return
false
;
}
return
_srs_device_ifs
[
ifname
];
}
bool
srs_net_device_is_internet
(
in_addr_t
addr
)
{
u_int32_t
addr_h
=
ntohl
(
addr
);
// lo, 127.0.0.0-127.0.0.1
if
(
addr_h
>=
0x7f000000
&&
addr_h
<=
0x7f000001
)
{
return
false
;
}
// Class A 10.0.0.0-10.255.255.255
if
(
addr_h
>=
0x0a000000
&&
addr_h
<=
0x0affffff
)
{
return
false
;
}
// Class B 172.16.0.0-172.31.255.255
if
(
addr_h
>=
0xac100000
&&
addr_h
<=
0xac1fffff
)
{
return
false
;
}
// Class C 192.168.0.0-192.168.255.255
if
(
addr_h
>=
0xc0a80000
&&
addr_h
<=
0xc0a8ffff
)
{
return
false
;
}
return
true
;
}
SrsNetworkRtmpServer
::
SrsNetworkRtmpServer
()
{
ok
=
false
;
...
...
@@ -1186,7 +1227,9 @@ void retrieve_local_ipv4_ips()
ifaddrs
*
p
=
ifap
;
while
(
p
!=
NULL
)
{
sockaddr
*
addr
=
p
->
ifa_addr
;
ifaddrs
*
cur
=
p
;
sockaddr
*
addr
=
cur
->
ifa_addr
;
p
=
p
->
ifa_next
;
// retrieve ipv4 addr
// ignore the tun0 network device,
...
...
@@ -1208,9 +1251,16 @@ void retrieve_local_ipv4_ips()
srs_trace
(
"retrieve local ipv4 ip=%s, index=%d"
,
ip
.
c_str
(),
(
int
)
ips
.
size
());
ips
.
push_back
(
ip
);
}
}
p
=
p
->
ifa_next
;
// set the device internet status.
if
(
!
srs_net_device_is_internet
(
inaddr
->
s_addr
))
{
srs_trace
(
"detect intranet address: %s"
,
ip
.
c_str
());
_srs_device_ifs
[
cur
->
ifa_name
]
=
false
;
}
else
{
srs_trace
(
"detect internet address: %s"
,
ip
.
c_str
());
_srs_device_ifs
[
cur
->
ifa_name
]
=
true
;
}
}
}
freeifaddrs
(
ifap
);
...
...
@@ -1326,7 +1376,7 @@ void srs_api_dump_summaries(std::stringstream& ss)
// ignore the lo interface.
std
::
string
inter
=
o
.
name
;
if
(
!
o
.
ok
||
inter
==
"lo"
)
{
if
(
!
o
.
ok
||
inter
==
"lo"
||
!
srs_net_device_is_internet
(
inter
)
)
{
continue
;
}
...
...
trunk/src/app/srs_app_utility.hpp
查看文件 @
8cd68a1
...
...
@@ -609,6 +609,9 @@ extern SrsNetworkDevices* srs_get_network_devices();
extern
int
srs_get_network_devices_count
();
// the deamon st-thread will update it.
extern
void
srs_update_network_devices
();
// detect whether specified device is internet public address.
extern
bool
srs_net_device_is_internet
(
std
::
string
ifname
);
extern
bool
srs_net_device_is_internet
(
in_addr_t
addr
);
// system connections, and srs rtmp network summary
class
SrsNetworkRtmpServer
...
...
请
注册
或
登录
后发表评论