callback function

This commit is contained in:
Jim Colderwood 2024-04-17 20:37:48 +01:00
parent 71c249746f
commit 095fb9243f
2 changed files with 8 additions and 3 deletions

View File

@ -5,8 +5,13 @@ import (
"github.com/crip/config"
"github.com/crip/ripv2"
"github.com/crip/rtable"
)
func callback(r *ripv2.Routes) {
rtable.Add(r)
}
func main() {
config := config.Read("config.json")
rip := ripv2.New()
@ -14,6 +19,6 @@ func main() {
log.Println("Running")
routes.Timer()
rip.Run(config)
rip.Run(config, callback)
/* NOT REACHED */
}

View File

@ -59,7 +59,7 @@ func (m *Message) MParse(b *[]byte, n int) error {
return nil
}
func (m *Message) Run(c *config.Config) {
func (m *Message) Run(c *config.Config, callback func(*Routes)) {
iface := net.Interface{
Name: c.MulticastInterface,
Flags: net.FlagMulticast,
@ -105,6 +105,6 @@ func (m *Message) Run(c *config.Config) {
for _, v := range routes.Routes {
fmt.Printf("Route:%s\tSubnet:%s\tNexthop:%s\tMetric:%d\tTime: %v\n", v.Addr.String(), v.Subnet.String(), v.Nexthop.String(), v.Metric, v.TTL.Unix())
}
//rtable.Add(routes)
(callback(routes))
}
}