mirror of
https://github.com/go-ping/ping.git
synced 2025-09-25 20:53:55 +00:00
Fix size issue when deserialising on Windows (#144)
This commit is contained in:
3
ping.go
3
ping.go
@@ -472,8 +472,7 @@ func (p *Pinger) recvICMP(
|
||||
case <-p.done:
|
||||
return nil
|
||||
default:
|
||||
// ICMP messages have an 8-byte header.
|
||||
bytes := make([]byte, p.Size+8)
|
||||
bytes := make([]byte, p.getMessageLength())
|
||||
if err := conn.SetReadDeadline(time.Now().Add(time.Millisecond * 100)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
8
utils_other.go
Normal file
8
utils_other.go
Normal file
@@ -0,0 +1,8 @@
|
||||
// +build !windows
|
||||
|
||||
package ping
|
||||
|
||||
// Returns the length of an ICMP message.
|
||||
func (p *Pinger) getMessageLength() int {
|
||||
return p.Size + 8
|
||||
}
|
16
utils_windows.go
Normal file
16
utils_windows.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// +build windows
|
||||
|
||||
package ping
|
||||
|
||||
import (
|
||||
"golang.org/x/net/ipv4"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
// Returns the length of an ICMP message, plus the IP packet header.
|
||||
func (p *Pinger) getMessageLength() int {
|
||||
if p.ipv4 {
|
||||
return p.Size + 8 + ipv4.HeaderLen
|
||||
}
|
||||
return p.Size + 8 + ipv6.HeaderLen
|
||||
}
|
Reference in New Issue
Block a user