File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
+ "encoding/binary"
4
5
"fmt"
5
6
"log"
6
7
"net"
@@ -95,8 +96,15 @@ func getBroadcastAddresses() ([]string, error) {
95
96
continue
96
97
}
97
98
for _ , addr := range addrs {
98
- if n , ok := addr .(* net.IPNet ); ok && ! n .IP .IsLoopback () && n .IP .To4 () != nil {
99
- baddrs = append (baddrs , n .IP .Mask (n .IP .DefaultMask ()).String ())
99
+ if n , ok := addr .(* net.IPNet ); ok && ! n .IP .IsLoopback () {
100
+ if v4addr := n .IP .To4 (); v4addr != nil {
101
+ // convert all parts of the masked bits to its maximum value
102
+ // by converting the address into a 32 bit integer and then
103
+ // ORing it with the inverted mask
104
+ baddr := make (net.IP , len (v4addr ))
105
+ binary .BigEndian .PutUint32 (baddr , binary .BigEndian .Uint32 (v4addr )| ^ binary .BigEndian .Uint32 (n .IP .DefaultMask ()))
106
+ baddrs = append (baddrs , baddr .String ())
107
+ }
100
108
}
101
109
}
102
110
}
You can’t perform that action at this time.
0 commit comments