ing
This commit is contained in:
parent
f8a302e632
commit
76eb21a8d5
|
@ -18,7 +18,7 @@ import (
|
|||
)
|
||||
|
||||
func Scan(discoverySession session.DiscoverySession) error {
|
||||
oub.Elapsed("mDNS")
|
||||
oub.Elapsed("ARP")
|
||||
|
||||
targetHosts := discoverySession.TargetHosts()
|
||||
if nil == targetHosts || 0 == len(targetHosts) {
|
||||
|
@ -59,6 +59,7 @@ func Scan(discoverySession session.DiscoverySession) error {
|
|||
delay.Store(true)
|
||||
if h := handlePacketARP(zone, targetHosts, hosts, packet); nil != h {
|
||||
if h != nil {
|
||||
// log.Print("Host ", h)
|
||||
discoverySession.AddHost(h)
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ func scanV4(discoverySession session.DiscoverySession) error {
|
|||
delay.Store(true)
|
||||
if h := handlePacketICMP4(zone, targetHosts, hosts, packet); nil != h {
|
||||
if h != nil {
|
||||
// log.Print("Host ", h)
|
||||
discoverySession.AddHost(h)
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ type ofDiscoverySession struct {
|
|||
|
||||
discoveryDelegator chan<- interface{}
|
||||
|
||||
discoveredMtx sync.RWMutex
|
||||
hosts map[string]*omd.Host
|
||||
includeMachosts map[string]*omd.Host
|
||||
ports map[*omd.Host]map[json.Number]map[string]*omd.Port
|
||||
|
@ -201,6 +202,9 @@ func (ds *ofDiscoverySession) TargetHosts() []net.IP {
|
|||
}
|
||||
|
||||
func (ds *ofDiscoverySession) AddHost(host *omd.Host) *omd.Host {
|
||||
ds.discoveredMtx.Lock()
|
||||
defer ds.discoveredMtx.Unlock()
|
||||
|
||||
h, modified := ds.findHost(host, true)
|
||||
|
||||
if "" == h.Mac && "" != host.Mac {
|
||||
|
@ -222,6 +226,9 @@ func (ds *ofDiscoverySession) AddHost(host *omd.Host) *omd.Host {
|
|||
}
|
||||
|
||||
func (ds *ofDiscoverySession) AddPort(port *omd.Port) *omd.Port {
|
||||
ds.discoveredMtx.Lock()
|
||||
defer ds.discoveredMtx.Unlock()
|
||||
|
||||
p, modified := ds.findPort(port, true)
|
||||
|
||||
meta, metaModified := ds.appendMeta(p.Meta, port.Meta)
|
||||
|
@ -238,6 +245,9 @@ func (ds *ofDiscoverySession) AddPort(port *omd.Port) *omd.Port {
|
|||
}
|
||||
|
||||
func (ds *ofDiscoverySession) AddService(service *omd.Service) *omd.Service {
|
||||
ds.discoveredMtx.Lock()
|
||||
defer ds.discoveredMtx.Unlock()
|
||||
|
||||
s, modified := ds.findService(service, true)
|
||||
|
||||
meta, metaModified := ds.appendMeta(s.Meta, service.Meta)
|
||||
|
@ -254,6 +264,9 @@ func (ds *ofDiscoverySession) AddService(service *omd.Service) *omd.Service {
|
|||
}
|
||||
|
||||
func (ds *ofDiscoverySession) DiscoveredHost(address string) *omd.Host {
|
||||
ds.discoveredMtx.RLock()
|
||||
defer ds.discoveredMtx.RUnlock()
|
||||
|
||||
h, ok := ds.hosts[address]
|
||||
if !ok {
|
||||
return nil
|
||||
|
@ -270,6 +283,9 @@ func (ds *ofDiscoverySession) DiscoveredAllHosts(includeMac bool) map[string]*om
|
|||
}
|
||||
|
||||
func (ds *ofDiscoverySession) DiscoveredPort(host *omd.Host, portNumber int) map[string]*omd.Port {
|
||||
ds.discoveredMtx.RLock()
|
||||
defer ds.discoveredMtx.RUnlock()
|
||||
|
||||
h, _ := ds.findHost(host, false)
|
||||
if nil == h {
|
||||
return nil
|
||||
|
@ -293,6 +309,9 @@ func (ds *ofDiscoverySession) DiscoveredAllPorts() map[*omd.Host]map[json.Number
|
|||
}
|
||||
|
||||
func (ds *ofDiscoverySession) DiscoveredService(port *omd.Port, name string) map[string]*omd.Service {
|
||||
ds.discoveredMtx.RLock()
|
||||
defer ds.discoveredMtx.RUnlock()
|
||||
|
||||
p, _ := ds.findPort(port, false)
|
||||
if nil == p {
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue
Block a user