container_discovery/internal/discoverer/port.go

33 lines
812 B
Go
Raw Normal View History

2018-04-19 11:36:56 +00:00
package discoverer
import (
"fmt"
"net"
2018-04-26 09:00:24 +00:00
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
2018-04-19 11:36:56 +00:00
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv4"
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv6"
)
2018-04-27 16:20:01 +00:00
func scanPort(host *ocmd.Host, dp *ocmd.DiscoverPort, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
2018-04-19 11:36:56 +00:00
defer func() {
doneChan <- struct{}{}
}()
_, ipNet, err := net.ParseCIDR(host.Zone.Network)
if nil != err {
errChan <- err
return
}
switch len(ipNet.IP) {
case net.IPv4len:
ipv4.ScanPort(host, dp, resultChan, errChan, stopChan)
case net.IPv6len:
ipv6.ScanPort(host, dp, resultChan, errChan, stopChan)
default:
errChan <- fmt.Errorf("Discovery: Not supported ip length")
return
}
}