mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-11-08 11:10:27 +01:00
37 lines
587 B
Go
37 lines
587 B
Go
// Copyright 2014 by Sascha L. Teichmann
|
|
// Use of this source code is governed by the MIT license
|
|
// that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import (
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
func ipsFromHosts(hosts string) ([]net.IP, error) {
|
|
|
|
ips := []net.IP{}
|
|
|
|
if len(hosts) == 0 { // Empty list: allow all hosts.
|
|
return ips, nil
|
|
}
|
|
|
|
for _, host := range strings.Split(hosts, ";") {
|
|
if hips, err := net.LookupIP(host); err != nil {
|
|
return nil, err
|
|
} else {
|
|
ips = append(ips, hips...)
|
|
}
|
|
}
|
|
|
|
return ips, nil
|
|
}
|
|
|
|
func min(a, b int) int {
|
|
if a < b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|