avoid broadcast addr
This commit is contained in:
parent
d0c33994f8
commit
12e8158725
4
add.go
4
add.go
@ -7,7 +7,9 @@ func Add(hostname string, owner string, description string) {//, publicKey strin
|
|||||||
presharedKey := GenerateJSONKey()
|
presharedKey := GenerateJSONKey()
|
||||||
publicKey := privateKey.PublicKey()
|
publicKey := privateKey.PublicKey()
|
||||||
|
|
||||||
conf.ChooseIP()
|
IP, err := conf.ChooseIP()
|
||||||
|
|
||||||
|
check(err)
|
||||||
|
|
||||||
peer := PeerConfig{
|
peer := PeerConfig{
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
|
4
types.go
4
types.go
@ -100,8 +100,8 @@ func (conf DsnetConfig) ChooseIP() (net.IP, error) {
|
|||||||
network := conf.Network.IPNet
|
network := conf.Network.IPNet
|
||||||
ones, bits := network.Mask.Size()
|
ones, bits := network.Mask.Size()
|
||||||
zeros := bits - ones
|
zeros := bits - ones
|
||||||
min := 1
|
min := 1 // avoids network addr
|
||||||
max := (1 << zeros) -1
|
max := (1 << zeros) -2 // avoids broadcast addr + overflow
|
||||||
|
|
||||||
for i := min; i <= max; i++ {
|
for i := min; i <= max; i++ {
|
||||||
IP := make(net.IP, len(network.IP))
|
IP := make(net.IP, len(network.IP))
|
||||||
|
Loading…
Reference in New Issue
Block a user