From 2e52c2b1220d0a90e42a98e57ce772c937564c74 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Sun, 11 Feb 2018 21:13:51 +0100 Subject: [PATCH] misc: small fix or general refactoring i did not bother commenting --- modules/net_sniff.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/net_sniff.go b/modules/net_sniff.go index 2363492d..09b21e05 100644 --- a/modules/net_sniff.go +++ b/modules/net_sniff.go @@ -1,6 +1,7 @@ package modules import ( + "bytes" "fmt" "net" "time" @@ -105,11 +106,11 @@ func same(a, b net.HardwareAddr) bool { } func (s Sniffer) isLocalPacket(packet gopacket.Packet) bool { - local_hw := s.Session.Interface.HW eth := packet.Layer(layers.LayerTypeEthernet) if eth != nil { - eth_packet, _ := eth.(*layers.Ethernet) - if same(eth_packet.SrcMAC, local_hw) || same(eth_packet.DstMAC, local_hw) { + eth, _ := eth.(*layers.Ethernet) + ifHw := s.Session.Interface.HW + if bytes.Compare(eth.SrcMAC, ifHw) == 0 || bytes.Compare(eth.DstMAC, ifHw) == 0 { return true } } @@ -158,13 +159,12 @@ func (s *Sniffer) Start() error { } s.Stats.LastPacket = now - is_local := false - if s.isLocalPacket(packet) { - is_local = true + isLocal := s.isLocalPacket(packet) + if isLocal { s.Stats.NumLocal++ } - if s.Ctx.DumpLocal == true || is_local == false { + if s.Ctx.DumpLocal == true || isLocal == false { data := packet.Data() if s.Ctx.Compiled == nil || s.Ctx.Compiled.Match(data) == true { s.Stats.NumMatched++