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
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:
@go vet ./...

View file

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

View file

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

View file

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

View file

@ -6,7 +6,7 @@ import (
"time"
"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/session"

View file

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

View file

@ -8,7 +8,7 @@ import (
"github.com/evilsocket/bettercap-ng/core"
"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"
)

View file

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

View file

@ -8,7 +8,7 @@ import (
"time"
"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/dustin/go-humanize"
@ -47,7 +47,7 @@ func rankByProtoHits(protos map[string]uint64) (ProtoPairList, uint64) {
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)
sinceFirstSeen := time.Since(e.FirstSeen)
@ -127,9 +127,9 @@ func (d *Discovery) Show(by string) error {
pad := 1
if d.Session.Interface.HwAddress == d.Session.Gateway.HwAddress {
pad = 0
targets = append([]*net.Endpoint{d.Session.Interface}, targets...)
targets = append([]*network.Endpoint{d.Session.Interface}, targets...)
} 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)

View file

@ -1,12 +1,12 @@
package modules
import (
"github.com/evilsocket/bettercap-ng/net"
"github.com/evilsocket/bettercap-ng/network"
"github.com/evilsocket/bettercap-ng/packets"
"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) 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
}
type BySeenSorter []*net.Endpoint
type BySeenSorter []*network.Endpoint
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) 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) 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
}
type ByRcvdSorter []*net.Endpoint
type ByRcvdSorter []*network.Endpoint
func (a ByRcvdSorter) Len() int { return len(a) }
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 (
"fmt"

View file

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

View file

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

View file

@ -1,4 +1,4 @@
package net
package network
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 (
"encoding/binary"

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
package net
package network
import (
"strings"
@ -11,7 +11,7 @@ var (
)
func OuiInit() {
bytes, err := Asset("net/oui.dat")
bytes, err := Asset("network/oui.dat")
if err != nil {
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/atomic"
bnet "github.com/evilsocket/bettercap-ng/net"
"github.com/evilsocket/bettercap-ng/network"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
@ -41,13 +41,13 @@ type Queue struct {
Protos map[string]uint64
Traffic map[string]*Traffic
iface *bnet.Endpoint
iface *network.Endpoint
handle *pcap.Handle
source *gopacket.PacketSource
active bool
}
func NewQueue(iface *bnet.Endpoint) (q *Queue, err error) {
func NewQueue(iface *network.Endpoint) (q *Queue, err error) {
q = &Queue{
Protos: make(map[string]uint64),
Traffic: make(map[string]*Traffic),

View file

@ -19,7 +19,7 @@ import (
"github.com/evilsocket/bettercap-ng/core"
"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"
)
@ -34,8 +34,8 @@ var (
type Session struct {
Options core.Options `json:"options"`
Interface *bnet.Endpoint `json:"interface"`
Gateway *bnet.Endpoint `json:"gateway"`
Interface *network.Endpoint `json:"interface"`
Gateway *network.Endpoint `json:"gateway"`
Firewall firewall.FirewallManager `json:"-"`
Env *Environment `json:"env"`
Targets *Targets `json:"targets"`
@ -306,9 +306,9 @@ func (s *Session) Start() error {
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
}
@ -316,7 +316,7 @@ func (s *Session) Start() error {
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())
}

View file

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