refact: renamed package net to network to avoid collision with golang net package.

This commit is contained in:
evilsocket 2018-02-15 21:34:46 +01:00
parent 21236c257e
commit 48d27f274a
28 changed files with 298 additions and 298 deletions

View file

@ -13,7 +13,7 @@ build: resources
resources: oui resources: oui
oui: oui:
@$(GOPATH)/bin/go-bindata -o net/oui_compiled.go -pkg net net/oui.dat @$(GOPATH)/bin/go-bindata -o network/oui_compiled.go -pkg network network/oui.dat
vet: vet:
@go vet ./... @go vet ./...

View file

@ -10,7 +10,7 @@ import (
"strings" "strings"
"github.com/evilsocket/bettercap-ng/core" "github.com/evilsocket/bettercap-ng/core"
"github.com/evilsocket/bettercap-ng/net" "github.com/evilsocket/bettercap-ng/network"
) )
var ( var (
@ -19,12 +19,12 @@ var (
) )
type PfFirewall struct { type PfFirewall struct {
iface *net.Endpoint iface *network.Endpoint
filename string filename string
forwarding bool forwarding bool
} }
func Make(iface *net.Endpoint) FirewallManager { func Make(iface *network.Endpoint) FirewallManager {
firewall := &PfFirewall{ firewall := &PfFirewall{
iface: iface, iface: iface,
filename: pfFilePath, filename: pfFilePath,

View file

@ -6,11 +6,11 @@ import (
"os" "os"
"github.com/evilsocket/bettercap-ng/core" "github.com/evilsocket/bettercap-ng/core"
"github.com/evilsocket/bettercap-ng/net" "github.com/evilsocket/bettercap-ng/network"
) )
type LinuxFirewall struct { type LinuxFirewall struct {
iface *net.Endpoint iface *network.Endpoint
forwarding bool forwarding bool
redirections map[string]*Redirection redirections map[string]*Redirection
} }
@ -19,7 +19,7 @@ const (
IPV4ForwardingFile = "/proc/sys/net/ipv4/ip_forward" IPV4ForwardingFile = "/proc/sys/net/ipv4/ip_forward"
) )
func Make(iface *net.Endpoint) FirewallManager { func Make(iface *network.Endpoint) FirewallManager {
firewall := &LinuxFirewall{ firewall := &LinuxFirewall{
iface: iface, iface: iface,
forwarding: false, forwarding: false,

View file

@ -5,16 +5,16 @@ import (
"strings" "strings"
"github.com/evilsocket/bettercap-ng/core" "github.com/evilsocket/bettercap-ng/core"
"github.com/evilsocket/bettercap-ng/net" "github.com/evilsocket/bettercap-ng/network"
) )
type WindowsFirewall struct { type WindowsFirewall struct {
iface *net.Endpoint iface *network.Endpoint
forwarding bool forwarding bool
redirections map[string]*Redirection redirections map[string]*Redirection
} }
func Make(iface *net.Endpoint) FirewallManager { func Make(iface *network.Endpoint) FirewallManager {
firewall := &WindowsFirewall{ firewall := &WindowsFirewall{
iface: iface, iface: iface,
forwarding: false, forwarding: false,

View file

@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/evilsocket/bettercap-ng/log" "github.com/evilsocket/bettercap-ng/log"
network "github.com/evilsocket/bettercap-ng/net" network "github.com/evilsocket/bettercap-ng/network"
"github.com/evilsocket/bettercap-ng/packets" "github.com/evilsocket/bettercap-ng/packets"
"github.com/evilsocket/bettercap-ng/session" "github.com/evilsocket/bettercap-ng/session"

View file

@ -6,7 +6,7 @@ import (
"strings" "strings"
"github.com/evilsocket/bettercap-ng/core" "github.com/evilsocket/bettercap-ng/core"
"github.com/evilsocket/bettercap-ng/net" "github.com/evilsocket/bettercap-ng/network"
"github.com/evilsocket/bettercap-ng/session" "github.com/evilsocket/bettercap-ng/session"
) )
@ -20,7 +20,7 @@ func (s EventsStream) viewLogEvent(e session.Event) {
} }
func (s EventsStream) viewEndpointEvent(e session.Event) { func (s EventsStream) viewEndpointEvent(e session.Event) {
t := e.Data.(*net.Endpoint) t := e.Data.(*network.Endpoint)
vend := "" vend := ""
name := "" name := ""

View file

@ -8,7 +8,7 @@ import (
"github.com/evilsocket/bettercap-ng/core" "github.com/evilsocket/bettercap-ng/core"
"github.com/evilsocket/bettercap-ng/log" "github.com/evilsocket/bettercap-ng/log"
bnet "github.com/evilsocket/bettercap-ng/net" bnet "github.com/evilsocket/bettercap-ng/network"
"github.com/evilsocket/bettercap-ng/session" "github.com/evilsocket/bettercap-ng/session"
) )

View file

@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/evilsocket/bettercap-ng/log" "github.com/evilsocket/bettercap-ng/log"
"github.com/evilsocket/bettercap-ng/net" "github.com/evilsocket/bettercap-ng/network"
"github.com/evilsocket/bettercap-ng/session" "github.com/evilsocket/bettercap-ng/session"
) )
@ -68,9 +68,9 @@ func (d Discovery) Author() string {
return "Simone Margaritelli <evilsocket@protonmail.com>" return "Simone Margaritelli <evilsocket@protonmail.com>"
} }
func (d *Discovery) runDiff(cache net.ArpTable) { func (d *Discovery) runDiff(cache network.ArpTable) {
// check for endpoints who disappeared // check for endpoints who disappeared
var rem net.ArpTable = make(net.ArpTable) var rem network.ArpTable = make(network.ArpTable)
for mac, t := range d.Session.Targets.Targets { for mac, t := range d.Session.Targets.Targets {
if _, found := cache[mac]; found == false { if _, found := cache[mac]; found == false {
rem[mac] = t.IpAddress rem[mac] = t.IpAddress
@ -101,7 +101,7 @@ func (d *Discovery) Start() error {
iface := d.Session.Interface.Name() iface := d.Session.Interface.Name()
for d.Running() { for d.Running() {
if table, err := net.ArpUpdate(iface); err != nil { if table, err := network.ArpUpdate(iface); err != nil {
log.Error("%s", err) log.Error("%s", err)
} else { } else {
d.runDiff(table) d.runDiff(table)

View file

@ -8,7 +8,7 @@ import (
"time" "time"
"github.com/evilsocket/bettercap-ng/core" "github.com/evilsocket/bettercap-ng/core"
"github.com/evilsocket/bettercap-ng/net" "github.com/evilsocket/bettercap-ng/network"
"github.com/evilsocket/bettercap-ng/packets" "github.com/evilsocket/bettercap-ng/packets"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
@ -47,7 +47,7 @@ func rankByProtoHits(protos map[string]uint64) (ProtoPairList, uint64) {
return pl, max return pl, max
} }
func (d *Discovery) getRow(e *net.Endpoint) []string { func (d *Discovery) getRow(e *network.Endpoint) []string {
sinceStarted := time.Since(d.Session.StartedAt) sinceStarted := time.Since(d.Session.StartedAt)
sinceFirstSeen := time.Since(e.FirstSeen) sinceFirstSeen := time.Since(e.FirstSeen)
@ -127,9 +127,9 @@ func (d *Discovery) Show(by string) error {
pad := 1 pad := 1
if d.Session.Interface.HwAddress == d.Session.Gateway.HwAddress { if d.Session.Interface.HwAddress == d.Session.Gateway.HwAddress {
pad = 0 pad = 0
targets = append([]*net.Endpoint{d.Session.Interface}, targets...) targets = append([]*network.Endpoint{d.Session.Interface}, targets...)
} else { } else {
targets = append([]*net.Endpoint{d.Session.Interface, d.Session.Gateway}, targets...) targets = append([]*network.Endpoint{d.Session.Interface, d.Session.Gateway}, targets...)
} }
rows := make([][]string, 0) rows := make([][]string, 0)

View file

@ -1,12 +1,12 @@
package modules package modules
import ( import (
"github.com/evilsocket/bettercap-ng/net" "github.com/evilsocket/bettercap-ng/network"
"github.com/evilsocket/bettercap-ng/packets" "github.com/evilsocket/bettercap-ng/packets"
"github.com/evilsocket/bettercap-ng/session" "github.com/evilsocket/bettercap-ng/session"
) )
type ByAddressSorter []*net.Endpoint type ByAddressSorter []*network.Endpoint
func (a ByAddressSorter) Len() int { return len(a) } 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) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
@ -17,13 +17,13 @@ func (a ByAddressSorter) Less(i, j int) bool {
return a[i].IpAddressUint32 < a[j].IpAddressUint32 return a[i].IpAddressUint32 < a[j].IpAddressUint32
} }
type BySeenSorter []*net.Endpoint type BySeenSorter []*network.Endpoint
func (a BySeenSorter) Len() int { return len(a) } func (a BySeenSorter) Len() int { return len(a) }
func (a BySeenSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a BySeenSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a BySeenSorter) Less(i, j int) bool { return a[i].LastSeen.After(a[j].LastSeen) } func (a BySeenSorter) Less(i, j int) bool { return a[i].LastSeen.After(a[j].LastSeen) }
type BySentSorter []*net.Endpoint type BySentSorter []*network.Endpoint
func (a BySentSorter) Len() int { return len(a) } func (a BySentSorter) Len() int { return len(a) }
func (a BySentSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a BySentSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
@ -46,7 +46,7 @@ func (a BySentSorter) Less(i, j int) bool {
return bTraffic.Sent < aTraffic.Sent return bTraffic.Sent < aTraffic.Sent
} }
type ByRcvdSorter []*net.Endpoint type ByRcvdSorter []*network.Endpoint
func (a ByRcvdSorter) Len() int { return len(a) } func (a ByRcvdSorter) Len() int { return len(a) }
func (a ByRcvdSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByRcvdSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

View file

@ -1,2 +0,0 @@
// Package net contains network specific code.
package net

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
package net package network
import ( import (
"fmt" "fmt"

View file

@ -1,4 +1,4 @@
package net package network
import "regexp" import "regexp"

View file

@ -1,4 +1,4 @@
package net package network
import "regexp" import "regexp"

View file

@ -1,4 +1,4 @@
package net package network
import "regexp" import "regexp"

2
network/doc.go Normal file
View file

@ -0,0 +1,2 @@
// Package network contains network specific code ... lol.
package network

View file

@ -1,4 +1,4 @@
package net package network
import ( import (
"encoding/binary" "encoding/binary"

View file

@ -1,4 +1,4 @@
package net package network
import ( import (
"fmt" "fmt"

View file

@ -1,4 +1,4 @@
package net package network
import ( import (
"net" "net"

View file

@ -1,4 +1,4 @@
package net package network
import ( import (
"net" "net"

View file

@ -1,4 +1,4 @@
package net package network
import ( import (
"net" "net"

View file

@ -1,4 +1,4 @@
package net package network
import ( import (
"strings" "strings"
@ -11,7 +11,7 @@ var (
) )
func OuiInit() { func OuiInit() {
bytes, err := Asset("net/oui.dat") bytes, err := Asset("network/oui.dat")
if err != nil { if err != nil {
panic(err) panic(err)
} }

237
network/oui_compiled.go Normal file

File diff suppressed because one or more lines are too long

View file

@ -7,7 +7,7 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
bnet "github.com/evilsocket/bettercap-ng/net" "github.com/evilsocket/bettercap-ng/network"
"github.com/google/gopacket" "github.com/google/gopacket"
"github.com/google/gopacket/layers" "github.com/google/gopacket/layers"
@ -41,13 +41,13 @@ type Queue struct {
Protos map[string]uint64 Protos map[string]uint64
Traffic map[string]*Traffic Traffic map[string]*Traffic
iface *bnet.Endpoint iface *network.Endpoint
handle *pcap.Handle handle *pcap.Handle
source *gopacket.PacketSource source *gopacket.PacketSource
active bool active bool
} }
func NewQueue(iface *bnet.Endpoint) (q *Queue, err error) { func NewQueue(iface *network.Endpoint) (q *Queue, err error) {
q = &Queue{ q = &Queue{
Protos: make(map[string]uint64), Protos: make(map[string]uint64),
Traffic: make(map[string]*Traffic), Traffic: make(map[string]*Traffic),

View file

@ -19,7 +19,7 @@ import (
"github.com/evilsocket/bettercap-ng/core" "github.com/evilsocket/bettercap-ng/core"
"github.com/evilsocket/bettercap-ng/firewall" "github.com/evilsocket/bettercap-ng/firewall"
bnet "github.com/evilsocket/bettercap-ng/net" "github.com/evilsocket/bettercap-ng/network"
"github.com/evilsocket/bettercap-ng/packets" "github.com/evilsocket/bettercap-ng/packets"
) )
@ -34,8 +34,8 @@ var (
type Session struct { type Session struct {
Options core.Options `json:"options"` Options core.Options `json:"options"`
Interface *bnet.Endpoint `json:"interface"` Interface *network.Endpoint `json:"interface"`
Gateway *bnet.Endpoint `json:"gateway"` Gateway *network.Endpoint `json:"gateway"`
Firewall firewall.FirewallManager `json:"-"` Firewall firewall.FirewallManager `json:"-"`
Env *Environment `json:"env"` Env *Environment `json:"env"`
Targets *Targets `json:"targets"` Targets *Targets `json:"targets"`
@ -306,9 +306,9 @@ func (s *Session) Start() error {
return s.Modules[i].Name() < s.Modules[j].Name() return s.Modules[i].Name() < s.Modules[j].Name()
}) })
bnet.OuiInit() network.OuiInit()
if s.Interface, err = bnet.FindInterface(*s.Options.InterfaceName); err != nil { if s.Interface, err = network.FindInterface(*s.Options.InterfaceName); err != nil {
return err return err
} }
@ -316,7 +316,7 @@ func (s *Session) Start() error {
return err return err
} }
if s.Gateway, err = bnet.FindGateway(s.Interface); err != nil { if s.Gateway, err = network.FindGateway(s.Interface); err != nil {
s.Events.Log(core.WARNING, "%s", err.Error()) s.Events.Log(core.WARNING, "%s", err.Error())
} }

View file

@ -10,7 +10,7 @@ import (
"sync" "sync"
"github.com/evilsocket/bettercap-ng/core" "github.com/evilsocket/bettercap-ng/core"
bnet "github.com/evilsocket/bettercap-ng/net" "github.com/evilsocket/bettercap-ng/network"
) )
const TargetsDefaultTTL = 10 const TargetsDefaultTTL = 10
@ -20,21 +20,21 @@ type Targets struct {
sync.Mutex sync.Mutex
Session *Session `json:"-"` Session *Session `json:"-"`
Interface *bnet.Endpoint Interface *network.Endpoint
Gateway *bnet.Endpoint Gateway *network.Endpoint
Targets map[string]*bnet.Endpoint Targets map[string]*network.Endpoint
TTL map[string]uint TTL map[string]uint
Aliases map[string]string Aliases map[string]string
aliasesFileName string aliasesFileName string
} }
func NewTargets(s *Session, iface, gateway *bnet.Endpoint) *Targets { func NewTargets(s *Session, iface, gateway *network.Endpoint) *Targets {
t := &Targets{ t := &Targets{
Session: s, Session: s,
Interface: iface, Interface: iface,
Gateway: gateway, Gateway: gateway,
Targets: make(map[string]*bnet.Endpoint), Targets: make(map[string]*network.Endpoint),
TTL: make(map[string]uint), TTL: make(map[string]uint),
Aliases: make(map[string]string), Aliases: make(map[string]string),
} }
@ -49,11 +49,11 @@ func NewTargets(s *Session, iface, gateway *bnet.Endpoint) *Targets {
return t return t
} }
func (tp *Targets) List() (list []*bnet.Endpoint) { func (tp *Targets) List() (list []*network.Endpoint) {
tp.Lock() tp.Lock()
defer tp.Unlock() defer tp.Unlock()
list = make([]*bnet.Endpoint, 0) list = make([]*network.Endpoint, 0)
for _, t := range tp.Targets { for _, t := range tp.Targets {
list = append(list, t) list = append(list, t)
} }
@ -168,7 +168,7 @@ func (tp *Targets) Has(ip string) bool {
return false return false
} }
func (tp *Targets) AddIfNew(ip, mac string) *bnet.Endpoint { func (tp *Targets) AddIfNew(ip, mac string) *network.Endpoint {
tp.Lock() tp.Lock()
defer tp.Unlock() defer tp.Unlock()
@ -176,7 +176,7 @@ func (tp *Targets) AddIfNew(ip, mac string) *bnet.Endpoint {
return nil return nil
} }
mac = bnet.NormalizeMac(mac) mac = network.NormalizeMac(mac)
if t, found := tp.Targets[mac]; found { if t, found := tp.Targets[mac]; found {
if tp.TTL[mac] < TargetsDefaultTTL { if tp.TTL[mac] < TargetsDefaultTTL {
tp.TTL[mac]++ tp.TTL[mac]++
@ -184,9 +184,9 @@ func (tp *Targets) AddIfNew(ip, mac string) *bnet.Endpoint {
return t return t
} }
e := bnet.NewEndpoint(ip, mac) e := network.NewEndpoint(ip, mac)
/* /*
e.ResolvedCallback = func(e *bnet.Endpoint) { e.ResolvedCallback = func(e *network.Endpoint) {
tp.Session.Events.Add("endpoint.resolved", e) tp.Session.Events.Add("endpoint.resolved", e)
} }
*/ */