avoid broadcast addr

This commit is contained in:
Callan Bryant 2020-03-02 19:02:09 +00:00
parent d0c33994f8
commit 12e8158725
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
2 changed files with 5 additions and 3 deletions

4
add.go
View File

@ -7,7 +7,9 @@ func Add(hostname string, owner string, description string) {//, publicKey strin
presharedKey := GenerateJSONKey()
publicKey := privateKey.PublicKey()
conf.ChooseIP()
IP, err := conf.ChooseIP()
check(err)
peer := PeerConfig{
Owner: owner,

View File

@ -100,8 +100,8 @@ func (conf DsnetConfig) ChooseIP() (net.IP, error) {
network := conf.Network.IPNet
ones, bits := network.Mask.Size()
zeros := bits - ones
min := 1
max := (1 << zeros) -1
min := 1 // avoids network addr
max := (1 << zeros) -2 // avoids broadcast addr + overflow
for i := min; i <= max; i++ {
IP := make(net.IP, len(network.IP))