diff --git a/ripv2/ripv2.go b/ripv2/ripv2.go index f3c33c1..875e430 100644 --- a/ripv2/ripv2.go +++ b/ripv2/ripv2.go @@ -14,11 +14,14 @@ import ( ) func New() Message { - var message Message - message.RIP = make([]RIP, 25) - return message + return Message{ + RIP: make([]RIP, 25), + } } +/* Parse the raw data packet + * Store the serialised data in the Message slice + */ func (m *Message) MParse(b *[]byte, n int) error { if n == 0 { return errors.New("can't parse empty data") @@ -59,6 +62,7 @@ func (m *Message) MParse(b *[]byte, n int) error { return nil } +/* Listen for network packets */ func (m *Message) Run(c *config.Config, callback func(*Routes)) error { iface := net.Interface{ Name: c.MulticastInterface, diff --git a/ripv2/routes.go b/ripv2/routes.go index e5b4f56..120954f 100644 --- a/ripv2/routes.go +++ b/ripv2/routes.go @@ -10,7 +10,7 @@ import ( type Routes struct { Routes map[string]Route - sync.Mutex + *sync.Mutex } type Route struct { @@ -23,9 +23,10 @@ type Route struct { } func Init() *Routes { - var routes Routes - routes.Routes = make(map[string]Route, 25) - return &routes + return &Routes{ + Routes: make(map[string]Route, 25), + Mutex: new(sync.Mutex), + } } func (r *Routes) append(route Route) {