Merge: * GetValidNetInterfaces: don't skip PointToPoint interfaces

Close #1534

* commit '2b1919137d88902d0cfc0cc8f480274e18b2d109':
  * GetValidNetInterfaces: don't skip PointToPoint interfaces
This commit is contained in:
Simon Zolin 2020-04-07 12:46:20 +03:00
commit 59b3a5bc6f
1 changed files with 6 additions and 10 deletions

View File

@ -36,11 +36,6 @@ func GetValidNetInterfaces() ([]net.Interface, error) {
netIfaces := []net.Interface{} netIfaces := []net.Interface{}
for i := range ifaces { for i := range ifaces {
if ifaces[i].Flags&net.FlagPointToPoint != 0 {
// this interface is ppp, we're not interested in this one
continue
}
iface := ifaces[i] iface := ifaces[i]
netIfaces = append(netIfaces, iface) netIfaces = append(netIfaces, iface)
} }
@ -48,7 +43,7 @@ func GetValidNetInterfaces() ([]net.Interface, error) {
return netIfaces, nil return netIfaces, nil
} }
// getValidNetInterfacesMap returns interfaces that are eligible for DNS and WEB only // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and WEB only
// we do not return link-local addresses here // we do not return link-local addresses here
func GetValidNetInterfacesForWeb() ([]NetInterface, error) { func GetValidNetInterfacesForWeb() ([]NetInterface, error) {
ifaces, err := GetValidNetInterfaces() ifaces, err := GetValidNetInterfaces()
@ -101,7 +96,7 @@ func GetValidNetInterfacesForWeb() ([]NetInterface, error) {
return netInterfaces, nil return netInterfaces, nil
} }
// Get interface name by its IP address. // GetInterfaceByIP - Get interface name by its IP address.
func GetInterfaceByIP(ip string) string { func GetInterfaceByIP(ip string) string {
ifaces, err := GetValidNetInterfacesForWeb() ifaces, err := GetValidNetInterfacesForWeb()
if err != nil { if err != nil {
@ -119,7 +114,7 @@ func GetInterfaceByIP(ip string) string {
return "" return ""
} }
// Get IP address with netmask for the specified interface // GetSubnet - Get IP address with netmask for the specified interface
// Returns an empty string if it fails to find it // Returns an empty string if it fails to find it
func GetSubnet(ifaceName string) string { func GetSubnet(ifaceName string) string {
netIfaces, err := GetValidNetInterfacesForWeb() netIfaces, err := GetValidNetInterfacesForWeb()
@ -137,7 +132,7 @@ func GetSubnet(ifaceName string) string {
return "" return ""
} }
// checkPortAvailable is not a cheap test to see if the port is bindable, because it's actually doing the bind momentarily // CheckPortAvailable - check if TCP port is available
func CheckPortAvailable(host string, port int) error { func CheckPortAvailable(host string, port int) error {
ln, err := net.Listen("tcp", net.JoinHostPort(host, strconv.Itoa(port))) ln, err := net.Listen("tcp", net.JoinHostPort(host, strconv.Itoa(port)))
if err != nil { if err != nil {
@ -151,6 +146,7 @@ func CheckPortAvailable(host string, port int) error {
return nil return nil
} }
// CheckPacketPortAvailable - check if UDP port is available
func CheckPacketPortAvailable(host string, port int) error { func CheckPacketPortAvailable(host string, port int) error {
ln, err := net.ListenPacket("udp", net.JoinHostPort(host, strconv.Itoa(port))) ln, err := net.ListenPacket("udp", net.JoinHostPort(host, strconv.Itoa(port)))
if err != nil { if err != nil {
@ -164,7 +160,7 @@ func CheckPacketPortAvailable(host string, port int) error {
return err return err
} }
// check if error is "address already in use" // ErrorIsAddrInUse - check if error is "address already in use"
func ErrorIsAddrInUse(err error) bool { func ErrorIsAddrInUse(err error) bool {
errOpError, ok := err.(*net.OpError) errOpError, ok := err.(*net.OpError)
if !ok { if !ok {