mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-22 13:05:36 +03:00
3cc5bf210d
Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well
42 lines
741 B
Go
42 lines
741 B
Go
package dhcpd
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
func isTimeout(err error) bool {
|
|
operr, ok := err.(*net.OpError)
|
|
if !ok {
|
|
return false
|
|
}
|
|
return operr.Timeout()
|
|
}
|
|
|
|
func parseIPv4(text string) (net.IP, error) {
|
|
result := net.ParseIP(text)
|
|
if result == nil {
|
|
return nil, fmt.Errorf("%s is not an IP address", text)
|
|
}
|
|
if result.To4() == nil {
|
|
return nil, fmt.Errorf("%s is not an IPv4 address", text)
|
|
}
|
|
return result.To4(), nil
|
|
}
|
|
|
|
// Return TRUE if subnet mask is correct (e.g. 255.255.255.0)
|
|
func isValidSubnetMask(mask net.IP) bool {
|
|
var n uint32
|
|
n = binary.BigEndian.Uint32(mask)
|
|
for i := 0; i != 32; i++ {
|
|
if n == 0 {
|
|
break
|
|
}
|
|
if (n & 0x80000000) == 0 {
|
|
return false
|
|
}
|
|
n <<= 1
|
|
}
|
|
return true
|
|
}
|