Developing lightweight computation at the DSG edge
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
LightKone
go-ping
Commits
ee05482e
Unverified
Commit
ee05482e
authored
Jun 05, 2019
by
Cam
Browse files
Don't separate ping response header from received bytes
parent
e33cfb8a
Changes
1
Hide whitespace changes
Inline
Side-by-side
ping.go
View file @
ee05482e
...
...
@@ -441,23 +441,16 @@ func (p *Pinger) recvICMP(
func
(
p
*
Pinger
)
processPacket
(
recv
*
packet
)
error
{
receivedAt
:=
time
.
Now
()
var
bytes
[]
byte
var
proto
int
if
p
.
ipv4
{
if
p
.
network
==
"ip"
{
bytes
=
ipv4Payload
(
recv
)
}
else
{
bytes
=
recv
.
bytes
}
proto
=
protocolICMP
}
else
{
bytes
=
recv
.
bytes
proto
=
protocolIPv6ICMP
}
var
m
*
icmp
.
Message
var
err
error
if
m
,
err
=
icmp
.
ParseMessage
(
proto
,
bytes
[
:
recv
.
n
bytes
]
);
err
!=
nil
{
if
m
,
err
=
icmp
.
ParseMessage
(
proto
,
recv
.
bytes
);
err
!=
nil
{
return
fmt
.
Errorf
(
"error parsing icmp message: %s"
,
err
.
Error
())
}
...
...
@@ -475,8 +468,7 @@ func (p *Pinger) processPacket(recv *packet) error {
switch
pkt
:=
m
.
Body
.
(
type
)
{
case
*
icmp
.
Echo
:
// If we are priviledged, we can match icmp.ID
// If we are privileged, we can match icmp.ID
if
p
.
network
==
"ip"
{
// Check if reply from same ID
if
pkt
.
ID
!=
p
.
id
{
...
...
@@ -574,16 +566,6 @@ func (p *Pinger) listen(netProto string) *icmp.PacketConn {
return
conn
}
func
ipv4Payload
(
recv
*
packet
)
[]
byte
{
b
:=
recv
.
bytes
if
len
(
b
)
<
ipv4
.
HeaderLen
{
return
b
}
hdrlen
:=
int
(
b
[
0
]
&
0x0f
)
<<
2
recv
.
nbytes
-=
hdrlen
return
b
[
hdrlen
:
]
}
func
bytesToTime
(
b
[]
byte
)
time
.
Time
{
var
nsec
int64
for
i
:=
uint8
(
0
);
i
<
8
;
i
++
{
...
...
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