From 813ae0a5e99e7ceafc30aceb0488b7ed927adb26 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Thu, 26 Apr 2018 12:25:35 +0200 Subject: [PATCH] and more --- packets/dhcp6.go | 2 +- packets/dot11.go | 6 +++--- packets/queue.go | 17 ++++++++--------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packets/dhcp6.go b/packets/dhcp6.go index 656f5ae9..01056597 100644 --- a/packets/dhcp6.go +++ b/packets/dhcp6.go @@ -38,7 +38,7 @@ func DHCP6For(what dhcp6.MessageType, to dhcp6.Packet, duid []byte) (err error, } var rawCID []byte - if raw, found := to.Options[dhcp6.OptionClientID]; found == false || len(raw) < 1 { + if raw, found := to.Options[dhcp6.OptionClientID]; !found || len(raw) < 1 { return ErrNoCID, p } else { rawCID = raw[0] diff --git a/packets/dot11.go b/packets/dot11.go index eec6ff2c..2411a330 100644 --- a/packets/dot11.go +++ b/packets/dot11.go @@ -107,7 +107,7 @@ func Dot11Parse(packet gopacket.Packet) (ok bool, radiotap *layers.RadioTap, dot return } radiotap, ok = radiotapLayer.(*layers.RadioTap) - if ok == false || radiotap == nil { + if !ok || radiotap == nil { return } @@ -165,7 +165,7 @@ func Dot11ParseEncryption(packet gopacket.Packet, dot11 *layers.Dot11) (bool, st auth = rsn.AuthKey.Suites[i].Type.String() } } - } else if enc == "" && info.ID == layers.Dot11InformationElementIDVendor && info.Length >= 8 && bytes.Compare(info.OUI, wpaSignatureBytes) == 0 && bytes.HasPrefix(info.Info, []byte{1, 0}) { + } else if enc == "" && info.ID == layers.Dot11InformationElementIDVendor && info.Length >= 8 && bytes.Equal(info.OUI, wpaSignatureBytes) && bytes.HasPrefix(info.Info, []byte{1, 0}) { enc = "WPA" vendor, err := Dot11InformationElementVendorInfoDecode(info.Info) if err == nil { @@ -195,7 +195,7 @@ func Dot11IsDataFor(dot11 *layers.Dot11, station net.HardwareAddr) bool { return false } // packet going to this specific BSSID? - return bytes.Compare(dot11.Address1, station) == 0 + return bytes.Equal(dot11.Address1, station) } func Dot11ParseDSSet(packet gopacket.Packet) (bool, int) { diff --git a/packets/queue.go b/packets/queue.go index e795e5d8..d76ae69d 100644 --- a/packets/queue.go +++ b/packets/queue.go @@ -1,7 +1,6 @@ package packets import ( - "bytes" "fmt" "net" "sync" @@ -104,7 +103,7 @@ func (q *Queue) trackProtocols(pkt gopacket.Packet) { q.Lock() name := proto.String() - if _, found := q.Protos[name]; found == false { + if _, found := q.Protos[name]; !found { q.Protos[name] = 1 } else { q.Protos[name] += 1 @@ -126,7 +125,7 @@ func (q *Queue) trackActivity(eth *layers.Ethernet, ip4 *layers.IPv4, address ne // initialize or update stats addr := address.String() - if _, found := q.Traffic[addr]; found == false { + if _, found := q.Traffic[addr]; !found { if isSent { q.Traffic[addr] = &Traffic{Sent: pktSize} } else { @@ -165,7 +164,7 @@ func (q *Queue) TrackError() { func (q *Queue) worker() { for pkt := range q.srcChannel { - if q.active == false { + if !q.active { return } @@ -188,16 +187,16 @@ func (q *Queue) worker() { // we manage to sniff // something coming from someone on the LAN - isFromMe := bytes.Compare(q.iface.IP, ip4.SrcIP) == 0 + isFromMe := q.iface.IP.Equal(ip4.SrcIP) isFromLAN := q.iface.Net.Contains(ip4.SrcIP) - if isFromMe == false && isFromLAN { + if !isFromMe && isFromLAN { q.trackActivity(eth, ip4, ip4.SrcIP, pktSize, true) } // something going to someone on the LAN - isToMe := bytes.Compare(q.iface.IP, ip4.DstIP) == 0 + isToMe := q.iface.IP.Equal(ip4.DstIP) isToLAN := q.iface.Net.Contains(ip4.DstIP) - if isToMe == false && isToLAN { + if !isToMe && isToLAN { q.trackActivity(eth, ip4, ip4.DstIP, pktSize, false) } } @@ -208,7 +207,7 @@ func (q *Queue) Send(raw []byte) error { q.Lock() defer q.Unlock() - if q.active == false { + if !q.active { return fmt.Errorf("Packet queue is not active.") }