From 12e815872510707c3e74fbb89fd3f71f1648ef8f Mon Sep 17 00:00:00 2001 From: Callan Bryant Date: Mon, 2 Mar 2020 19:02:09 +0000 Subject: [PATCH] avoid broadcast addr --- add.go | 4 +++- types.go | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/add.go b/add.go index 15ee751..62718e4 100644 --- a/add.go +++ b/add.go @@ -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, diff --git a/types.go b/types.go index b684c53..be051ff 100644 --- a/types.go +++ b/types.go @@ -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))