1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 func (m *RouteMessage) marshal() ([]byte, error) {
10 l := sizeofRtMsghdr + addrsSpace(m.Addrs)
12 nativeEndian.PutUint16(b[:2], uint16(l))
16 b[2] = byte(m.Version)
19 nativeEndian.PutUint16(b[4:6], uint16(sizeofRtMsghdr))
20 nativeEndian.PutUint32(b[16:20], uint32(m.Flags))
21 nativeEndian.PutUint16(b[6:8], uint16(m.Index))
22 nativeEndian.PutUint32(b[24:28], uint32(m.ID))
23 nativeEndian.PutUint32(b[28:32], uint32(m.Seq))
24 attrs, err := marshalAddrs(b[sizeofRtMsghdr:], m.Addrs)
29 nativeEndian.PutUint32(b[12:16], uint32(attrs))
34 func (*wireFormat) parseRouteMessage(_ RIBType, b []byte) (Message, error) {
35 if len(b) < sizeofRtMsghdr {
36 return nil, errMessageTooShort
38 l := int(nativeEndian.Uint16(b[:2]))
40 return nil, errInvalidMessage
45 Flags: int(nativeEndian.Uint32(b[16:20])),
46 Index: int(nativeEndian.Uint16(b[6:8])),
47 ID: uintptr(nativeEndian.Uint32(b[24:28])),
48 Seq: int(nativeEndian.Uint32(b[28:32])),
51 ll := int(nativeEndian.Uint16(b[4:6]))
53 return nil, errInvalidMessage
55 errno := syscall.Errno(nativeEndian.Uint32(b[32:36]))
59 as, err := parseAddrs(uint(nativeEndian.Uint32(b[12:16])), parseKernelInetAddr, b[ll:])