This commit is contained in:
Josh Deprez 2024-03-17 13:35:50 +11:00
parent 7e1549607d
commit e18614bfec
Signed by: josh
SSH key fingerprint: SHA256:zZji7w1Ilh2RuUpbQcqkLPrqmRwpiCSycbF2EfKm6Kw
2 changed files with 37 additions and 0 deletions

View file

@ -210,6 +210,14 @@ func ParsePacket(p []byte) (Packet, error) {
riu.Header = h riu.Header = h
return riu, nil return riu, nil
case CmdCodeRD:
rd, err := parseRD(p)
if err != nil {
return nil, err
}
rd.Header = h
return rd, nil
default: default:
return nil, fmt.Errorf("unknown routing packet command code %d", h.CommandCode) return nil, fmt.Errorf("unknown routing packet command code %d", h.CommandCode)
} }

29
aurp/router_down.go Normal file
View file

@ -0,0 +1,29 @@
package aurp
import (
"encoding/binary"
"fmt"
"io"
)
type RDPacket struct {
Header
ErrorCode int16
}
func (p *RDPacket) WriteTo(w io.Writer) (int64, error) {
a := acc(w)
a.writeTo(&p.Header)
a.write16(uint16(p.ErrorCode))
return a.ret()
}
func parseRD(p []byte) (*RDPacket, error) {
if len(p) < 2 {
return nil, fmt.Errorf("insufficient input length %d for router down packet", len(p))
}
return &RDPacket{
ErrorCode: int16(binary.BigEndian.Uint16(p[:2])),
}, nil
}