From 1367663aa1d5d3ef2e65e6f2757a48cd511f54b8 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Sun, 21 Jan 2018 11:13:26 +0100 Subject: [PATCH] refact: starting refactoring new.show sorting in separate file --- modules/net_recon.go | 8 +------- modules/net_recon_sort.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 modules/net_recon_sort.go diff --git a/modules/net_recon.go b/modules/net_recon.go index 6d841130..0f5ec452 100644 --- a/modules/net_recon.go +++ b/modules/net_recon.go @@ -153,12 +153,6 @@ func (d *Discovery) Start() error { return nil } -type tSorter []*net.Endpoint - -func (a tSorter) Len() int { return len(a) } -func (a tSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a tSorter) Less(i, j int) bool { return a[i].IpAddressUint32 < a[j].IpAddressUint32 } - func rankByProtoHits(protos map[string]uint64) (ProtoPairList, uint64) { pl := make(ProtoPairList, len(protos)) max := uint64(0) @@ -216,7 +210,7 @@ func (d *Discovery) Show() error { targets = append(targets, t) } - sort.Sort(tSorter(targets)) + sort.Sort(ByAddressSorter(targets)) data = make([][]string, nTargets) for i, t := range targets { diff --git a/modules/net_recon_sort.go b/modules/net_recon_sort.go new file mode 100644 index 00000000..5c6aa906 --- /dev/null +++ b/modules/net_recon_sort.go @@ -0,0 +1,11 @@ +package modules + +import ( + "github.com/evilsocket/bettercap-ng/net" +) + +type ByAddressSorter []*net.Endpoint + +func (a ByAddressSorter) Len() int { return len(a) } +func (a ByAddressSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a ByAddressSorter) Less(i, j int) bool { return a[i].IpAddressUint32 < a[j].IpAddressUint32 }