diff --git a/hop/hop.go b/hop/hop.go index 31e0612..f4c6407 100644 --- a/hop/hop.go +++ b/hop/hop.go @@ -8,7 +8,7 @@ import ( "time" gm "github.com/buger/goterm" - "github.com/tonobo/mtr/imcp" + "github.com/tonobo/mtr/icmp" ) type HopStatistic struct { @@ -18,9 +18,9 @@ type HopStatistic struct { Sent int TTL int Target string - Last imcp.ICMPReturn - Best imcp.ICMPReturn - Worst imcp.ICMPReturn + Last icmp.ICMPReturn + Best icmp.ICMPReturn + Worst icmp.ICMPReturn SumElapsed time.Duration Lost int Packets *ring.Ring @@ -38,7 +38,7 @@ func (s *HopStatistic) Next(srcAddr string) { return } s.pingSeq++ - r, _ := imcp.SendIMCP(srcAddr, s.Dest, s.Target, s.TTL, s.PID, s.Timeout, s.pingSeq) + r, _ := icmp.SendICMP(srcAddr, s.Dest, s.Target, s.TTL, s.PID, s.Timeout, s.pingSeq) s.Packets = s.Packets.Prev() s.Packets.Value = r @@ -107,7 +107,7 @@ func (h *HopStatistic) packets() []*packet { i++ return } - x := f.(imcp.ICMPReturn) + x := f.(icmp.ICMPReturn) if x.Success { v[i] = &packet{ Success: true, @@ -130,7 +130,7 @@ func (h *HopStatistic) Render() { h.Packets.Do(func(f interface{}) { if f == nil { packets[i] = ' ' - } else if !f.(imcp.ICMPReturn).Success { + } else if !f.(icmp.ICMPReturn).Success { packets[i] = '?' } else { packets[i] = '.' diff --git a/imcp/icmp.go b/icmp/icmp.go similarity index 91% rename from imcp/icmp.go rename to icmp/icmp.go index 16447b3..22e4fd0 100644 --- a/imcp/icmp.go +++ b/icmp/icmp.go @@ -1,4 +1,4 @@ -package imcp +package icmp import ( "bytes" @@ -11,15 +11,15 @@ import ( "golang.org/x/net/ipv4" ) -// ICMPReturn contains the info for a returned IMCP +// ICMPReturn contains the info for a returned ICMP type ICMPReturn struct { Success bool Addr string Elapsed time.Duration } -// SendDiscoverIMCP sends a IMCP to a given destination with a TTL to discover hops -func SendDiscoverIMCP(localAddr string, dst net.Addr, ttl, pid int, timeout time.Duration, seq int) (hop ICMPReturn, err error) { +// SendDiscoverICMP sends a ICMP to a given destination with a TTL to discover hops +func SendDiscoverICMP(localAddr string, dst net.Addr, ttl, pid int, timeout time.Duration, seq int) (hop ICMPReturn, err error) { hop.Success = false start := time.Now() c, err := icmp.ListenPacket("ip4:icmp", localAddr) @@ -67,8 +67,8 @@ func SendDiscoverIMCP(localAddr string, dst net.Addr, ttl, pid int, timeout time return hop, err } -// SendIMCP sends a IMCP to a given destination which requires a reply from that specific destination -func SendIMCP(localAddr string, dst net.Addr, target string, ttl, pid int, timeout time.Duration, seq int) (hop ICMPReturn, err error) { +// SendICMP sends a ICMP to a given destination which requires a reply from that specific destination +func SendICMP(localAddr string, dst net.Addr, target string, ttl, pid int, timeout time.Duration, seq int) (hop ICMPReturn, err error) { hop.Success = false start := time.Now() c, err := icmp.ListenPacket("ip4:icmp", localAddr) diff --git a/mtr/mtr.go b/mtr/mtr.go index 006c6e7..ab59fd5 100644 --- a/mtr/mtr.go +++ b/mtr/mtr.go @@ -10,7 +10,7 @@ import ( gm "github.com/buger/goterm" "github.com/tonobo/mtr/hop" - "github.com/tonobo/mtr/imcp" + "github.com/tonobo/mtr/icmp" ) type MTR struct { @@ -41,7 +41,7 @@ func NewMTR(addr, srcAddr string, timeout time.Duration, interval time.Duration, }, make(chan struct{}) } -func (m *MTR) registerStatistic(ttl int, r imcp.ICMPReturn) *hop.HopStatistic { +func (m *MTR) registerStatistic(ttl int, r icmp.ICMPReturn) *hop.HopStatistic { m.Statistic[ttl] = &hop.HopStatistic{ Sent: 1, TTL: ttl, @@ -99,7 +99,7 @@ func (m *MTR) discover(ch chan struct{}) { unknownHopsCount := 0 for ttl := 1; ttl < m.maxHops; ttl++ { time.Sleep(m.hopsleep) - hopReturn, err := imcp.SendDiscoverIMCP(m.SrcAddress, &ipAddr, ttl, pid, m.timeout, 1) + hopReturn, err := icmp.SendDiscoverICMP(m.SrcAddress, &ipAddr, ttl, pid, m.timeout, 1) m.mutex.Lock() s := m.registerStatistic(ttl, hopReturn)