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
c893fa4a
Commit
c893fa4a
authored
Oct 11, 2024
by
“liusq”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增gb28181日志11
parent
34258077
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
3 deletions
+20
-3
Common.cpp
+20
-3
No files found.
Common.cpp
View file @
c893fa4a
...
@@ -128,8 +128,8 @@ unsigned short Common::calculate_checksum(void *b, int len) {
...
@@ -128,8 +128,8 @@ unsigned short Common::calculate_checksum(void *b, int len) {
bool
Common
::
pingAddress
(
const
QString
&
address
)
{
bool
Common
::
pingAddress
(
const
QString
&
address
)
{
QByteArray
&&
byJsonIp
=
address
.
toUtf8
();
QByteArray
&&
byJsonIp
=
address
.
toUtf8
();
const
char
*
target
=
byJsonIp
.
data
();
const
char
*
target
=
byJsonIp
.
data
();
struct
sockaddr_in
dest
;
struct
sockaddr_in
dest
;
struct
hostent
*
host_entity
;
struct
hostent
*
host_entity
;
...
@@ -151,6 +151,16 @@ bool Common::pingAddress(const QString &address) {
...
@@ -151,6 +151,16 @@ bool Common::pingAddress(const QString &address) {
return
false
;
// 套接字创建失败,返回false
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包头
// 设置ICMP包头
struct
icmphdr
icmp_hdr
;
struct
icmphdr
icmp_hdr
;
icmp_hdr
.
type
=
ICMP_ECHO
;
// ICMP Echo Request
icmp_hdr
.
type
=
ICMP_ECHO
;
// ICMP Echo Request
...
@@ -175,9 +185,15 @@ bool Common::pingAddress(const QString &address) {
...
@@ -175,9 +185,15 @@ bool Common::pingAddress(const QString &address) {
socklen_t
addr_len
=
sizeof
(
recv_addr
);
socklen_t
addr_len
=
sizeof
(
recv_addr
);
if
(
recvfrom
(
sock
,
buffer
,
sizeof
(
buffer
),
0
,
(
struct
sockaddr
*
)
&
recv_addr
,
&
addr_len
)
<=
0
)
{
if
(
recvfrom
(
sock
,
buffer
,
sizeof
(
buffer
),
0
,
(
struct
sockaddr
*
)
&
recv_addr
,
&
addr_len
)
<=
0
)
{
if
(
errno
==
EAGAIN
||
errno
==
EWOULDBLOCK
)
{
// 超时错误处理
printf
(
"Ping timeout.
\n
"
);
}
else
{
// 其他接收错误
perror
(
"recvfrom"
);
perror
(
"recvfrom"
);
}
close
(
sock
);
close
(
sock
);
return
false
;
// 接收失败,返回false
return
false
;
//
超时或
接收失败,返回false
}
}
// 关闭套接字
// 关闭套接字
...
@@ -188,6 +204,7 @@ bool Common::pingAddress(const QString &address) {
...
@@ -188,6 +204,7 @@ bool Common::pingAddress(const QString &address) {
//获取本机mask
//获取本机mask
bool
GetLocalNetMask
(
const
char
*
eth_inf
,
char
*
netmask_addr
)
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