33 lines
820 B
Go
Raw Normal View History

2017-11-15 21:09:38 +09:00
package discovery
2017-11-16 20:01:42 +09:00
import (
"fmt"
"net"
2017-11-15 21:33:46 +09:00
2017-12-04 18:37:39 +09:00
discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
2017-11-18 00:12:38 +09:00
"git.loafle.net/overflow/overflow_discovery/discovery/ipv4"
"git.loafle.net/overflow/overflow_discovery/discovery/ipv6"
2017-11-16 20:01:42 +09:00
)
2017-12-04 18:37:39 +09:00
func scanHost(zone *discoveryM.Zone, dh *discoveryM.DiscoveryHost, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
2017-11-18 21:08:08 +09:00
defer func() {
doneChan <- struct{}{}
}()
2017-11-18 00:12:38 +09:00
_, ipNet, err := net.ParseCIDR(zone.Network)
2017-11-17 19:46:56 +09:00
if nil != err {
errChan <- err
return
}
2017-11-18 00:12:38 +09:00
switch len(ipNet.IP) {
case net.IPv4len:
2017-11-18 21:08:08 +09:00
ipv4.ScanHost(zone, dh, resultChan, errChan, stopChan)
2017-11-18 00:12:38 +09:00
case net.IPv6len:
2017-11-18 21:08:08 +09:00
ipv6.ScanHost(zone, dh, resultChan, errChan, stopChan)
2017-11-16 20:01:42 +09:00
2017-11-18 00:12:38 +09:00
default:
errChan <- fmt.Errorf("Discovery: Not supported ip length")
2017-11-17 19:46:56 +09:00
return
}
2017-11-15 21:09:38 +09:00
}