Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gamera_videos_no_ui
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liusq
gamera_videos_no_ui
Commits
6aca3f45
Commit
6aca3f45
authored
Oct 11, 2024
by
郭峰
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-1007488' into 'release'
新增gb28181日志11 See merge request
!56
parents
516fd6bb
c893fa4a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
4 deletions
+21
-4
Common.cpp
+21
-4
No files found.
Common.cpp
View file @
6aca3f45
...
...
@@ -128,8 +128,8 @@ unsigned short Common::calculate_checksum(void *b, int len) {
bool
Common
::
pingAddress
(
const
QString
&
address
)
{
QByteArray
&&
byJsonIp
=
address
.
toUtf8
();
const
char
*
target
=
byJsonIp
.
data
();
QByteArray
&&
byJsonIp
=
address
.
toUtf8
();
const
char
*
target
=
byJsonIp
.
data
();
struct
sockaddr_in
dest
;
struct
hostent
*
host_entity
;
...
...
@@ -151,6 +151,16 @@ bool Common::pingAddress(const QString &address) {
return
false
;
// 套接字创建失败,返回false
}
// 设置2秒的接收超时
struct
timeval
timeout
;
timeout
.
tv_sec
=
2
;
// 2秒
timeout
.
tv_usec
=
0
;
// 0微秒
if
(
setsockopt
(
sock
,
SOL_SOCKET
,
SO_RCVTIMEO
,
&
timeout
,
sizeof
(
timeout
))
<
0
)
{
perror
(
"setsockopt"
);
close
(
sock
);
return
false
;
// 设置超时失败,返回false
}
// 设置ICMP包头
struct
icmphdr
icmp_hdr
;
icmp_hdr
.
type
=
ICMP_ECHO
;
// ICMP Echo Request
...
...
@@ -175,9 +185,15 @@ bool Common::pingAddress(const QString &address) {
socklen_t
addr_len
=
sizeof
(
recv_addr
);
if
(
recvfrom
(
sock
,
buffer
,
sizeof
(
buffer
),
0
,
(
struct
sockaddr
*
)
&
recv_addr
,
&
addr_len
)
<=
0
)
{
perror
(
"recvfrom"
);
if
(
errno
==
EAGAIN
||
errno
==
EWOULDBLOCK
)
{
// 超时错误处理
printf
(
"Ping timeout.
\n
"
);
}
else
{
// 其他接收错误
perror
(
"recvfrom"
);
}
close
(
sock
);
return
false
;
// 接收失败,返回false
return
false
;
//
超时或
接收失败,返回false
}
// 关闭套接字
...
...
@@ -188,6 +204,7 @@ bool Common::pingAddress(const QString &address) {
//获取本机mask
bool
GetLocalNetMask
(
const
char
*
eth_inf
,
char
*
netmask_addr
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment