crip/main.go

51 lines
982 B
Go
Raw Normal View History

2024-04-09 22:20:07 +01:00
package main
import (
"fmt"
"log"
"net"
"github.com/crip/ripv2"
2024-04-10 16:33:33 +01:00
"github.com/crip/ripv2/routes"
2024-04-15 11:26:37 +01:00
"github.com/crip/rtable"
2024-04-09 22:20:07 +01:00
)
func main() {
rip := ripv2.New()
2024-04-10 16:33:33 +01:00
routes := routes.New()
2024-04-09 22:20:07 +01:00
addr := net.UDPAddr{
2024-04-10 09:50:56 +01:00
Port: 520,
IP: net.ParseIP("224.0.0.9"),
2024-04-09 22:20:07 +01:00
}
2024-04-10 09:50:56 +01:00
iface := net.Interface{
Name: "enp1s0f1",
Flags: net.FlagMulticast,
}
conn, err := net.ListenMulticastUDP("udp4", &iface, &addr)
2024-04-09 22:20:07 +01:00
if err != nil {
log.Fatalln(err)
}
defer conn.Close()
buff := make([]byte, 1024)
2024-04-11 21:15:36 +01:00
log.Println("Running")
routes.Timer()
2024-04-10 13:59:01 +01:00
for {
n, UDPAddr, err := conn.ReadFromUDP(buff)
2024-04-10 09:50:56 +01:00
if err != nil {
log.Fatalln(err)
}
2024-04-10 13:59:01 +01:00
_ = UDPAddr
2024-04-09 23:33:11 +01:00
2024-04-10 13:59:01 +01:00
if err := rip.MParse(&buff, n); err != nil {
log.Fatalln(err)
}
2024-04-10 16:33:33 +01:00
routes.ParseRoutes(*UDPAddr, &rip.RIP)
2024-04-11 21:15:36 +01:00
for _, v := range routes.Routes {
2024-04-10 20:42:12 +01:00
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())
}
2024-04-15 11:26:37 +01:00
rtable.Add(routes)
2024-04-10 20:42:12 +01:00
fmt.Println("")
2024-04-10 09:50:56 +01:00
}
2024-04-09 22:20:07 +01:00
}