mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-21 14:24:26 +03:00
506b459842
Merge in DNS/adguard-home from 3225-bsd-dhcp to master Closes #3225. Closes #3417. Squashed commit of the following: commit e7ea691824c7ebc8cafd8c9e206679346cbc8592 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Aug 12 17:02:02 2021 +0300 all: imp code, docs commit 5b598fc18a9b69a0256569f4c691bb6a2193dfbd Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Aug 12 16:28:12 2021 +0300 all: mv logic, imp code, docs, log changes commit e3e1577a668fe3e5c61d075c390e4bd7268181ba Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Aug 12 14:15:10 2021 +0300 dhcpd: imp checkother commit 3cc8b058195c30a7ef0b7741ee8463270d9e47ff Author: Eugene Burkov <e.burkov@adguard.com> Date: Wed Aug 11 13:20:18 2021 +0300 all: imp bsd support
36 lines
586 B
Go
36 lines
586 B
Go
package dhcpd
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
func tryTo4(ip net.IP) (ip4 net.IP, err error) {
|
|
if ip == nil {
|
|
return nil, fmt.Errorf("%v is not an IP address", ip)
|
|
}
|
|
|
|
ip4 = ip.To4()
|
|
if ip4 == nil {
|
|
return nil, fmt.Errorf("%v is not an IPv4 address", ip)
|
|
}
|
|
|
|
return ip4, 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
|
|
}
|