57 lines
834 B
Go
57 lines
834 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net"
|
|
|
|
"github.com/crip/ripv2"
|
|
)
|
|
|
|
func main() {
|
|
rip := ripv2.New()
|
|
addr := net.UDPAddr{
|
|
Port: 5111,
|
|
IP: net.ParseIP("0.0.0.0"),
|
|
}
|
|
conn, err := net.ListenUDP("udp", &addr)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
defer conn.Close()
|
|
buff := make([]byte, 1024)
|
|
|
|
bytes, err := rip.Request(conn)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
fmt.Println(bytes)
|
|
|
|
RipAddr := net.UDPAddr{
|
|
Port: 520,
|
|
IP: net.ParseIP("224.0.0.9"),
|
|
}
|
|
bw, err := conn.WriteToUDP(bytes, &RipAddr)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
log.Printf("wrote %d bytes\n", bw)
|
|
|
|
log.Println("waiting")
|
|
n, err := conn.Read(buff)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
fmt.Println("here")
|
|
if n == 0 {
|
|
log.Fatalln("empty")
|
|
}
|
|
|
|
if err := rip.Parse(&buff); err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
fmt.Println(rip)
|
|
}
|