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
277d3943
Commit
277d3943
authored
Oct 11, 2024
by
郭峰
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-1007488' into 'release'
新增gb28181日志08 See merge request
!53
parents
4d32a442
f38613f1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
3 deletions
+12
-3
Common.cpp
+11
-3
Common.h
+1
-0
No files found.
Common.cpp
View file @
277d3943
...
...
@@ -138,9 +138,9 @@ bool Common::sendPingRequest(int sockfd, const char *ipAddress, int sequence) {
icmpHeader
.
sequence
=
sequence
;
icmpHeader
.
checksum
=
0
;
char
packet
[
sizeof
(
struct
ICMPHeader
)
+
32
];
char
packet
[
sizeof
(
struct
ICMPHeader
)
+
8
];
memcpy
(
packet
,
&
icmpHeader
,
sizeof
(
icmpHeader
));
memset
(
packet
+
sizeof
(
icmpHeader
),
0
,
32
);
memset
(
packet
+
sizeof
(
icmpHeader
),
0
,
8
);
icmpHeader
.
checksum
=
calculateChecksum
((
uint16_t
*
)
packet
,
sizeof
(
packet
));
memcpy
(
packet
,
&
icmpHeader
,
sizeof
(
icmpHeader
));
...
...
@@ -157,6 +157,13 @@ bool Common::receivePingReply(int sockfd, int sequence) {
char
buffer
[
1024
];
struct
sockaddr_in
srcAddr
;
socklen_t
srcAddrLen
=
sizeof
(
srcAddr
);
struct
timeval
tv
;
tv
.
tv_sec
=
2
;
// 设置超时时间为2秒
tv
.
tv_usec
=
0
;
if
(
setsockopt
(
sockfd
,
SOL_SOCKET
,
SO_RCVTIMEO
,
&
tv
,
sizeof
(
tv
))
<
0
)
{
perror
(
"setsockopt"
);
return
false
;
}
ssize_t
bytesRead
=
recvfrom
(
sockfd
,
buffer
,
sizeof
(
buffer
),
0
,
(
struct
sockaddr
*
)
&
srcAddr
,
&
srcAddrLen
);
if
(
bytesRead
<
0
)
{
...
...
@@ -187,7 +194,8 @@ bool Common::pingAddress(const QString &address) {
perror
(
"socket"
);
return
1
;
}
int
flags
=
fcntl
(
sockfd
,
F_GETFL
,
0
);
fcntl
(
sockfd
,
F_SETFL
,
flags
|
O_NONBLOCK
);
int
sequence
=
1
;
if
(
sendPingRequest
(
sockfd
,
ipAddress
,
sequence
))
{
if
(
receivePingReply
(
sockfd
,
sequence
))
{
...
...
Common.h
View file @
277d3943
...
...
@@ -30,6 +30,7 @@
#include <linux/route.h>
#include <ifaddrs.h>
#include <netdb.h>
#include <fcntl.h>
#define NAME_SIZE 8
#define MAC_SIZE 18
...
...
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