2024-03-17 13:35:50 +11:00
|
|
|
package aurp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RDPacket struct {
|
|
|
|
Header
|
|
|
|
|
2024-03-17 18:19:36 +11:00
|
|
|
ErrorCode ErrorCode
|
2024-03-17 13:35:50 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
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{
|
2024-03-17 18:19:36 +11:00
|
|
|
ErrorCode: ErrorCode(binary.BigEndian.Uint16(p[:2])),
|
2024-03-17 13:35:50 +11:00
|
|
|
}, nil
|
|
|
|
}
|