This commit is contained in:
Jim Colderwood 2024-04-09 23:33:11 +01:00
parent 1a9f5fc4da
commit d14091306e
2 changed files with 25 additions and 23 deletions

38
main.go
View File

@ -11,38 +11,40 @@ import (
func main() {
rip := ripv2.New()
addr := net.UDPAddr{
Port: 520,
IP: net.ParseIP("224.0.0.9"),
Port: 5111,
IP: net.ParseIP("0.0.0.0"),
}
conn, err := net.ListenMulticastUDP("udp", nil, &addr)
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)
}
bytes, err := rip.Request(conn)
if err != nil {
log.Fatalln(err)
}
RipAddr := net.UDPAddr{
Port: 520,
IP: net.ParseIP("224.0.0.9"),
}
bw, err := conn.WriteToUDP(bytes, &RipAddr)
if err != nil {
log.Fatalln(err)
}
fmt.Println(bytes)
log.Printf("wrote %d bytes\n", bw)
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")
}

View File

@ -11,7 +11,7 @@ type Message struct {
Command uint8
Version uint8
Zero uint16
RIP [25]RIP
RIP RIP
}
type RIP struct {
@ -33,7 +33,7 @@ func (m *Message) Parse(b *[]byte) error {
bytes := bytes.NewBuffer(*b)
if err := binary.Read(bytes, binary.LittleEndian, &m); err != nil {
if err := binary.Read(bytes, binary.BigEndian, &m); err != nil {
return err
}
@ -41,15 +41,15 @@ func (m *Message) Parse(b *[]byte) error {
}
func (m *Message) Request(conn *net.UDPConn) ([]byte, error) {
var buffer = make([]byte, 1024)
var buffer = make([]byte, 24)
m.Command = REQUEST
m.Version = 2
m.RIP.Metric = 16
buff := bytes.NewBuffer(buffer)
buff.Reset()
if err := binary.Write(buff, binary.LittleEndian, m); err != nil {
if err := binary.Write(buff, binary.BigEndian, m); err != nil {
return []byte{}, err
}
fmt.Println(buff)
return buffer, nil
}