crip/main.go

50 lines
905 B
Go
Raw Normal View History

2024-04-09 22:20:07 +01:00
package main
import (
"fmt"
"log"
"net"
"github.com/crip/ripv2"
)
func main() {
rip := ripv2.New()
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-10 13:59:01 +01:00
log.Println("waiting")
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-09 22:20:07 +01:00
2024-04-10 13:59:01 +01:00
/* Just testing the parsing output */
for i := 0; i < 24; i++ {
if rip.RIP[i].Metric == 0 {
break
2024-04-10 09:50:56 +01:00
}
2024-04-10 13:59:01 +01:00
fmt.Printf("%d\t%s\t%s\t%s\t%d\n", rip.RIP[i].AFI, rip.RIP[i].Addr.String(), rip.RIP[i].Subnet.String(), rip.RIP[i].Nexthop.String(), rip.RIP[i].Metric)
}
fmt.Println("")
2024-04-10 09:50:56 +01:00
}
2024-04-09 22:20:07 +01:00
}