mirror of
https://github.com/go-ping/ping.git
synced 2025-05-03 04:56:22 +00:00
Fix runtime panic
This commit is contained in:
parent
3eec4c7c0d
commit
d596e7045d
6
ping.go
6
ping.go
@ -442,7 +442,7 @@ func (p *Pinger) processPacket(recv *packet) error {
|
|||||||
var proto int
|
var proto int
|
||||||
if p.ipv4 {
|
if p.ipv4 {
|
||||||
if p.network == "ip" {
|
if p.network == "ip" {
|
||||||
bytes = ipv4Payload(recv.bytes)
|
bytes = ipv4Payload(recv)
|
||||||
} else {
|
} else {
|
||||||
bytes = recv.bytes
|
bytes = recv.bytes
|
||||||
}
|
}
|
||||||
@ -591,11 +591,13 @@ func byteSliceOfSize(n int) []byte {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func ipv4Payload(b []byte) []byte {
|
func ipv4Payload(recv *packet) []byte {
|
||||||
|
b := recv.bytes
|
||||||
if len(b) < ipv4.HeaderLen {
|
if len(b) < ipv4.HeaderLen {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
hdrlen := int(b[0]&0x0f) << 2
|
hdrlen := int(b[0]&0x0f) << 2
|
||||||
|
recv.nbytes -= hdrlen
|
||||||
return b[hdrlen:]
|
return b[hdrlen:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user