1
0
mirror of https://github.com/taigrr/go-fastping synced 2025-01-18 05:03:15 -08:00

Added const for default packet size

This commit is contained in:
Simon Whitehead 2014-11-05 11:30:06 +11:00 committed by Tatsushi Demachi
parent c6c53385e0
commit 1a8c22e90d

View File

@ -47,7 +47,12 @@ import (
"time"
)
const TimeSliceLengh = 8
func byteSliceOfSize(n int) []byte {
if n == 0 {
n = TimeSliceLengh // if its 0 .. default it to 8
}
b := make([]byte, n)
for i := 0; i < len(b); i++ {
b[i] = 1
@ -134,7 +139,7 @@ func NewPinger() *Pinger {
addrs: make(map[string]*net.IPAddr),
hasIPv4: false,
hasIPv6: false,
Size: 64,
Size: TimeSliceLengh,
MaxRTT: time.Second,
OnRecv: nil,
OnIdle: nil,
@ -409,7 +414,7 @@ func (p *Pinger) sendICMP(conn, conn6 *net.IPConn) (map[string]*net.IPAddr, erro
Type: typ, Code: 0,
Body: &icmpEcho{
ID: p.id, Seq: p.seq,
Data: append(t, byteSliceOfSize(p.Size-len(t))...),
Data: append(t, byteSliceOfSize(p.Size-TimeSliceLengh)...),
},
}).Marshal()
p.mu.Unlock()
@ -515,7 +520,7 @@ func (p *Pinger) procRecv(recv *packet, queue map[string]*net.IPAddr) {
case *icmpEcho:
p.mu.Lock()
if pkt.ID == p.id && pkt.Seq == p.seq {
rtt = time.Since(bytesToTime(pkt.Data[:8]))
rtt = time.Since(bytesToTime(pkt.Data[:TimeSliceLengh]))
}
p.mu.Unlock()
default: