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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
3 deletions
+72
-3
Common.cpp
+67
-0
VidesData.h
+5
-3
No files found.
Common.cpp
View file @
dcd3dc5e
...
@@ -107,4 +107,71 @@ QString Common::GetLocalIp() {
...
@@ -107,4 +107,71 @@ QString Common::GetLocalIp() {
}
}
return
ipAddress
;
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
(){}
Common
::~
Common
(){}
VidesData.h
View file @
dcd3dc5e
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
#include <string>
#include <string>
#include <sstream>
#include <sstream>
#include <list>
#include <list>
#include "Common.h"
namespace
vides_data
{
namespace
vides_data
{
constexpr
const
char
*
HEADER_TYPE_KAY
=
"Content-Type"
;
constexpr
const
char
*
HEADER_TYPE_KAY
=
"Content-Type"
;
constexpr
const
char
*
HEADER_TYPE_VALUE
=
"application/json"
;
constexpr
const
char
*
HEADER_TYPE_VALUE
=
"application/json"
;
...
@@ -350,6 +351,7 @@ struct DetectionParams {
...
@@ -350,6 +351,7 @@ struct DetectionParams {
float
recConfidenceThreshold
;
///< 识别置信度阈值
float
recConfidenceThreshold
;
///< 识别置信度阈值
};
};
inline
bool
isVirtualMachine
()
inline
bool
isVirtualMachine
()
{
{
QString
dmiPath
;
QString
dmiPath
;
...
@@ -382,7 +384,7 @@ inline QString getDefaultGateway() {
...
@@ -382,7 +384,7 @@ inline QString getDefaultGateway() {
#endif
#endif
process
.
start
(
command
,
arguments
);
process
.
start
(
command
,
arguments
);
// 等待进程结束
// 等待进程结束
process
.
waitForFinished
();
process
.
waitForFinished
();
...
@@ -493,11 +495,11 @@ inline bool pingAddress(const QString &address) {
...
@@ -493,11 +495,11 @@ inline bool pingAddress(const QString &address) {
#else
#else
// Linux 指令 "ping -c 1 IP"
// Linux 指令 "ping -c 1 IP"
QStringList
arguments
;
QStringList
arguments
;
arguments
<<
"-c"
<<
"
ping -c 1 "
+
address
;
arguments
<<
"-c"
<<
"
1"
<<
address
;
#endif
#endif
// 启动进程
// 启动进程
cmd
.
start
(
"
bash
"
,
arguments
);
cmd
.
start
(
"
/bin/ping
"
,
arguments
);
// 等待进程准备好读取
// 等待进程准备好读取
if
(
!
cmd
.
waitForStarted
())
{
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