misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2018-02-11 21:13:51 +01:00
commit 2e52c2b122

View file

@ -1,6 +1,7 @@
package modules package modules
import ( import (
"bytes"
"fmt" "fmt"
"net" "net"
"time" "time"
@ -105,11 +106,11 @@ func same(a, b net.HardwareAddr) bool {
} }
func (s Sniffer) isLocalPacket(packet gopacket.Packet) bool { func (s Sniffer) isLocalPacket(packet gopacket.Packet) bool {
local_hw := s.Session.Interface.HW
eth := packet.Layer(layers.LayerTypeEthernet) eth := packet.Layer(layers.LayerTypeEthernet)
if eth != nil { if eth != nil {
eth_packet, _ := eth.(*layers.Ethernet) eth, _ := eth.(*layers.Ethernet)
if same(eth_packet.SrcMAC, local_hw) || same(eth_packet.DstMAC, local_hw) { ifHw := s.Session.Interface.HW
if bytes.Compare(eth.SrcMAC, ifHw) == 0 || bytes.Compare(eth.DstMAC, ifHw) == 0 {
return true return true
} }
} }
@ -158,13 +159,12 @@ func (s *Sniffer) Start() error {
} }
s.Stats.LastPacket = now s.Stats.LastPacket = now
is_local := false isLocal := s.isLocalPacket(packet)
if s.isLocalPacket(packet) { if isLocal {
is_local = true
s.Stats.NumLocal++ s.Stats.NumLocal++
} }
if s.Ctx.DumpLocal == true || is_local == false { if s.Ctx.DumpLocal == true || isLocal == false {
data := packet.Data() data := packet.Data()
if s.Ctx.Compiled == nil || s.Ctx.Compiled.Match(data) == true { if s.Ctx.Compiled == nil || s.Ctx.Compiled.Match(data) == true {
s.Stats.NumMatched++ s.Stats.NumMatched++