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
dcd3dc5e
Commit
dcd3dc5e
authored
Oct 10, 2024
by
“liusq”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改ping命令
parent
5603d29d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
2 deletions
+71
-2
Common.cpp
+67
-0
VidesData.h
+4
-2
No files found.
Common.cpp
View file @
dcd3dc5e
...
...
@@ -107,4 +107,71 @@ QString Common::GetLocalIp() {
}
return
ipAddress
;
}
// 计算校验和
uint16_t
Common
::
calculateChecksum
(
uint16_t
*
buffer
,
int
size
)
{
uint32_t
checksum
=
0
;
while
(
size
>
1
)
{
checksum
+=
*
buffer
++
;
size
-=
sizeof
(
uint16_t
);
}
if
(
size
)
{
checksum
+=
*
(
uint8_t
*
)
buffer
;
}
checksum
=
(
checksum
>>
16
)
+
(
checksum
&
0xffff
);
checksum
+=
(
checksum
>>
16
);
return
(
uint16_t
)(
~
checksum
);
}
// 发送 ICMP 请求
bool
Common
::
sendPingRequest
(
int
sockfd
,
const
char
*
ipAddress
,
int
sequence
)
{
struct
sockaddr_in
destAddr
;
memset
(
&
destAddr
,
0
,
sizeof
(
destAddr
));
destAddr
.
sin_family
=
AF_INET
;
inet_pton
(
AF_INET
,
ipAddress
,
&
destAddr
.
sin_addr
);
struct
ICMPHeader
icmpHeader
;
icmpHeader
.
type
=
ICMP_ECHO
;
icmpHeader
.
code
=
0
;
icmpHeader
.
id
=
getpid
()
&
0xffff
;
icmpHeader
.
sequence
=
sequence
;
icmpHeader
.
checksum
=
0
;
char
packet
[
sizeof
(
struct
ICMPHeader
)
+
32
];
memcpy
(
packet
,
&
icmpHeader
,
sizeof
(
icmpHeader
));
memset
(
packet
+
sizeof
(
icmpHeader
),
0
,
32
);
icmpHeader
.
checksum
=
calculateChecksum
((
uint16_t
*
)
packet
,
sizeof
(
packet
));
memcpy
(
packet
,
&
icmpHeader
,
sizeof
(
icmpHeader
));
if
(
sendto
(
sockfd
,
packet
,
sizeof
(
packet
),
0
,
(
struct
sockaddr
*
)
&
destAddr
,
sizeof
(
destAddr
))
<
0
)
{
perror
(
"sendto"
);
return
false
;
}
return
true
;
}
// 接收 ICMP 回复
bool
Common
::
receivePingReply
(
int
sockfd
,
int
sequence
)
{
char
buffer
[
1024
];
struct
sockaddr_in
srcAddr
;
socklen_t
srcAddrLen
=
sizeof
(
srcAddr
);
ssize_t
bytesRead
=
recvfrom
(
sockfd
,
buffer
,
sizeof
(
buffer
),
0
,
(
struct
sockaddr
*
)
&
srcAddr
,
&
srcAddrLen
);
if
(
bytesRead
<
0
)
{
perror
(
"recvfrom"
);
return
false
;
}
struct
iphdr
*
ipHeader
=
(
struct
iphdr
*
)
buffer
;
struct
ICMPHeader
*
icmpHeader
=
(
struct
ICMPHeader
*
)(
buffer
+
(
ipHeader
->
ihl
<<
2
));
if
(
icmpHeader
->
type
==
ICMP_ECHOREPLY
&&
icmpHeader
->
sequence
==
sequence
)
{
std
::
cout
<<
"Ping successful!"
<<
std
::
endl
;
return
true
;
}
return
false
;
}
Common
::~
Common
(){}
VidesData.h
View file @
dcd3dc5e
...
...
@@ -16,6 +16,7 @@
#include <string>
#include <sstream>
#include <list>
#include "Common.h"
namespace
vides_data
{
constexpr
const
char
*
HEADER_TYPE_KAY
=
"Content-Type"
;
constexpr
const
char
*
HEADER_TYPE_VALUE
=
"application/json"
;
...
...
@@ -350,6 +351,7 @@ struct DetectionParams {
float
recConfidenceThreshold
;
///< 识别置信度阈值
};
inline
bool
isVirtualMachine
()
{
QString
dmiPath
;
...
...
@@ -493,11 +495,11 @@ inline bool pingAddress(const QString &address) {
#else
// Linux 指令 "ping -c 1 IP"
QStringList
arguments
;
arguments
<<
"-c"
<<
"
ping -c 1 "
+
address
;
arguments
<<
"-c"
<<
"
1"
<<
address
;
#endif
// 启动进程
cmd
.
start
(
"
bash
"
,
arguments
);
cmd
.
start
(
"
/bin/ping
"
,
arguments
);
// 等待进程准备好读取
if
(
!
cmd
.
waitForStarted
())
{
...
...
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