mirror of
https://github.com/jsimonetti/rtnetlink.git
synced 2026-03-28 15:31:09 +01:00
Merge branch 'master' into upstream_concurrency
Signed-off-by: Jeroen Simonetti <jeroen@simonetti.nl>
This commit is contained in:
commit
66f9b418de
20
route.go
20
route.go
@ -37,6 +37,26 @@ const routeMessageLength = 12
|
||||
func (m *RouteMessage) MarshalBinary() ([]byte, error) {
|
||||
b := make([]byte, routeMessageLength)
|
||||
|
||||
// ensure that DstLength and SrcLength are correct
|
||||
if m.Attributes.Dst != nil {
|
||||
if m.Attributes.Dst.To4() != nil {
|
||||
m.DstLength = 32
|
||||
} else if m.Attributes.Dst.To16() != nil {
|
||||
m.DstLength = 128
|
||||
} else {
|
||||
return nil, errInvalidRouteMessageAttr
|
||||
}
|
||||
}
|
||||
if m.Attributes.Src != nil {
|
||||
if m.Attributes.Src.To4() != nil {
|
||||
m.SrcLength = 32
|
||||
} else if m.Attributes.Src.To16() != nil {
|
||||
m.SrcLength = 128
|
||||
} else {
|
||||
return nil, errInvalidRouteMessageAttr
|
||||
}
|
||||
}
|
||||
|
||||
b[0] = m.Family
|
||||
b[1] = m.DstLength
|
||||
b[2] = m.SrcLength
|
||||
|
||||
@ -46,7 +46,7 @@ func TestRouteMessageMarshalBinary(t *testing.T) {
|
||||
},
|
||||
},
|
||||
b: []byte{
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00,
|
||||
0x0a, 0x00, 0x00, 0x00, 0x08, 0x00, 0x05, 0x00,
|
||||
0x0a, 0x0a, 0x0a, 0x0a, 0x08, 0x00, 0x04, 0x00,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user