IPNet -> JSONIPnet

This commit is contained in:
Callan Bryant 2020-03-01 22:29:11 +00:00
parent 099324b7f8
commit 0e118b3b6f
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
2 changed files with 5 additions and 5 deletions

View File

@ -35,12 +35,12 @@ func Init() {
// get a random /22 subnet on 10.0.0.0 (1023 hosts) (or /24?) // get a random /22 subnet on 10.0.0.0 (1023 hosts) (or /24?)
// TODO also the 20 bit block and 16 bit block? // TODO also the 20 bit block and 16 bit block?
func getRandomNetwork() IPNet { func getRandomNetwork() JSONIPNet {
rbs := make([]byte, 2) rbs := make([]byte, 2)
rand.Seed(time.Now().UTC().UnixNano()) rand.Seed(time.Now().UTC().UnixNano())
rand.Read(rbs) rand.Read(rbs)
return IPNet{ return JSONIPNet{
net.IPNet { net.IPNet {
net.IP{10,rbs[0],rbs[1]<<2,0}, net.IP{10,rbs[0],rbs[1]<<2,0},
net.IPMask{255,255,252,0}, net.IPMask{255,255,252,0},

View File

@ -64,14 +64,14 @@ type Dsnet struct {
Peers []Peer Peers []Peer
} }
type IPNet struct { type JSONIPNet struct {
ipNet net.IPNet ipNet net.IPNet
} }
func (n IPNet) MarshalJSON() ([]byte, error) { func (n JSONIPNet) MarshalJSON() ([]byte, error) {
return []byte("\"" + n.ipNet.String() + "\""), nil return []byte("\"" + n.ipNet.String() + "\""), nil
} }
func (n *IPNet) String() string { func (n *JSONIPNet) String() string {
return n.ipNet.String() return n.ipNet.String()
} }