Skip to content

Commit

Permalink
fix: change imcp to icmp (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtDaJim authored and tonobo committed Feb 13, 2019
1 parent 07c7d6b commit 01a0c5b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions hop/hop.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

gm "github.com/buger/goterm"
"github.com/tonobo/mtr/imcp"
"github.com/tonobo/mtr/icmp"
)

type HopStatistic struct {
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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] = '.'
Expand Down
12 changes: 6 additions & 6 deletions imcp/icmp.go → icmp/icmp.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package imcp
package icmp

import (
"bytes"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions mtr/mtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 01a0c5b

Please sign in to comment.