This commit is contained in:
crusader 2018-09-12 16:45:05 +09:00
parent 6653ea4a87
commit 4f409f59f3

View File

@ -2,7 +2,6 @@ package pcap
import ( import (
"fmt" "fmt"
"sort"
"sync" "sync"
omd "git.loafle.net/overflow/model/discovery" omd "git.loafle.net/overflow/model/discovery"
@ -123,13 +122,12 @@ func (ps *pCapScan) CloseARP(ch chan *layers.ARP) {
ps.arpListenerChanMtx.Lock() ps.arpListenerChanMtx.Lock()
defer ps.arpListenerChanMtx.Unlock() defer ps.arpListenerChanMtx.Unlock()
i := sort.Search(len(ps.arpListenerChans), func(i int) bool { for indexI := 0; indexI < len(ps.arpListenerChans); indexI++ {
return ch == ps.arpListenerChans[i] if ch == ps.arpListenerChans[indexI] {
}) close(ch)
ps.arpListenerChans = append(ps.arpListenerChans[:indexI], ps.arpListenerChans[indexI+1:]...)
if -1 != i { break
close(ch) }
ps.arpListenerChans = append(ps.arpListenerChans[:i], ps.arpListenerChans[i+1:]...)
} }
} }
@ -145,13 +143,12 @@ func (ps *pCapScan) CloseICMP4(ch chan gopacket.Packet) {
ps.icmp4ListenerChanMtx.Lock() ps.icmp4ListenerChanMtx.Lock()
defer ps.icmp4ListenerChanMtx.Unlock() defer ps.icmp4ListenerChanMtx.Unlock()
i := sort.Search(len(ps.icmp4ListenerChans), func(i int) bool { for indexI := 0; indexI < len(ps.icmp4ListenerChans); indexI++ {
return ch == ps.icmp4ListenerChans[i] if ch == ps.icmp4ListenerChans[indexI] {
}) close(ch)
ps.icmp4ListenerChans = append(ps.icmp4ListenerChans[:indexI], ps.icmp4ListenerChans[indexI+1:]...)
if -1 != i { break
close(ch) }
ps.icmp4ListenerChans = append(ps.icmp4ListenerChans[:i], ps.icmp4ListenerChans[i+1:]...)
} }
} }
@ -167,13 +164,12 @@ func (ps *pCapScan) CloseICMP6(ch chan gopacket.Packet) {
ps.icmp6ListenerChanMtx.Lock() ps.icmp6ListenerChanMtx.Lock()
defer ps.icmp6ListenerChanMtx.Unlock() defer ps.icmp6ListenerChanMtx.Unlock()
i := sort.Search(len(ps.icmp6ListenerChans), func(i int) bool { for indexI := 0; indexI < len(ps.icmp6ListenerChans); indexI++ {
return ch == ps.icmp6ListenerChans[i] if ch == ps.icmp6ListenerChans[indexI] {
}) close(ch)
ps.icmp6ListenerChans = append(ps.icmp6ListenerChans[:indexI], ps.icmp6ListenerChans[indexI+1:]...)
if -1 != i { break
close(ch) }
ps.icmp6ListenerChans = append(ps.icmp6ListenerChans[:i], ps.icmp6ListenerChans[i+1:]...)
} }
} }
@ -198,14 +194,16 @@ func (ps *pCapScan) CloseTCP(ip string, ch chan *layers.TCP) {
return return
} }
chs := ps.tcpListenerChans[ip] chs, ok := ps.tcpListenerChans[ip]
i := sort.Search(len(chs), func(i int) bool { if !ok {
return ch == chs[i] return
}) }
for indexI := 0; indexI < len(chs); indexI++ {
if -1 != i && len(chs) > i { if ch == chs[indexI] {
close(ch) close(ch)
ps.tcpListenerChans[ip] = append(ps.tcpListenerChans[ip][:i], ps.tcpListenerChans[ip][i+1:]...) ps.tcpListenerChans[ip] = append(ps.tcpListenerChans[ip][:indexI], ps.tcpListenerChans[ip][indexI+1:]...)
break
}
} }
} }
@ -231,14 +229,16 @@ func (ps *pCapScan) CloseUDP(ip string, ch chan gopacket.Packet) {
return return
} }
chs := ps.udpListenerChans[ip] chs, ok := ps.udpListenerChans[ip]
i := sort.Search(len(chs), func(i int) bool { if !ok {
return ch == chs[i] return
}) }
for indexI := 0; indexI < len(chs); indexI++ {
if -1 != i { if ch == chs[indexI] {
close(ch) close(ch)
ps.udpListenerChans[ip] = append(ps.udpListenerChans[ip][:i], ps.udpListenerChans[ip][i+1:]...) ps.udpListenerChans[ip] = append(ps.udpListenerChans[ip][:indexI], ps.udpListenerChans[ip][indexI+1:]...)
break
}
} }
} }