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
f38613f1
Commit
f38613f1
authored
Oct 11, 2024
by
“liusq”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增gb28181日志08
parent
eed904d5
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 @
f38613f1
...
@@ -138,9 +138,9 @@ bool Common::sendPingRequest(int sockfd, const char *ipAddress, int sequence) {
...
@@ -138,9 +138,9 @@ bool Common::sendPingRequest(int sockfd, const char *ipAddress, int sequence) {
icmpHeader
.
sequence
=
sequence
;
icmpHeader
.
sequence
=
sequence
;
icmpHeader
.
checksum
=
0
;
icmpHeader
.
checksum
=
0
;
char
packet
[
sizeof
(
struct
ICMPHeader
)
+
32
];
char
packet
[
sizeof
(
struct
ICMPHeader
)
+
8
];
memcpy
(
packet
,
&
icmpHeader
,
sizeof
(
icmpHeader
));
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
));
icmpHeader
.
checksum
=
calculateChecksum
((
uint16_t
*
)
packet
,
sizeof
(
packet
));
memcpy
(
packet
,
&
icmpHeader
,
sizeof
(
icmpHeader
));
memcpy
(
packet
,
&
icmpHeader
,
sizeof
(
icmpHeader
));
...
@@ -157,6 +157,13 @@ bool Common::receivePingReply(int sockfd, int sequence) {
...
@@ -157,6 +157,13 @@ bool Common::receivePingReply(int sockfd, int sequence) {
char
buffer
[
1024
];
char
buffer
[
1024
];
struct
sockaddr_in
srcAddr
;
struct
sockaddr_in
srcAddr
;
socklen_t
srcAddrLen
=
sizeof
(
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
);
ssize_t
bytesRead
=
recvfrom
(
sockfd
,
buffer
,
sizeof
(
buffer
),
0
,
(
struct
sockaddr
*
)
&
srcAddr
,
&
srcAddrLen
);
if
(
bytesRead
<
0
)
{
if
(
bytesRead
<
0
)
{
...
@@ -187,7 +194,8 @@ bool Common::pingAddress(const QString &address) {
...
@@ -187,7 +194,8 @@ bool Common::pingAddress(const QString &address) {
perror
(
"socket"
);
perror
(
"socket"
);
return
1
;
return
1
;
}
}
int
flags
=
fcntl
(
sockfd
,
F_GETFL
,
0
);
fcntl
(
sockfd
,
F_SETFL
,
flags
|
O_NONBLOCK
);
int
sequence
=
1
;
int
sequence
=
1
;
if
(
sendPingRequest
(
sockfd
,
ipAddress
,
sequence
))
{
if
(
sendPingRequest
(
sockfd
,
ipAddress
,
sequence
))
{
if
(
receivePingReply
(
sockfd
,
sequence
))
{
if
(
receivePingReply
(
sockfd
,
sequence
))
{
...
...
Common.h
View file @
f38613f1
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include <linux/route.h>
#include <linux/route.h>
#include <ifaddrs.h>
#include <ifaddrs.h>
#include <netdb.h>
#include <netdb.h>
#include <fcntl.h>
#define NAME_SIZE 8
#define NAME_SIZE 8
#define MAC_SIZE 18
#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