1
2
3
4
5
6
7
8 package route
9
10 import "runtime"
11
12 func (w *wireFormat) parseInterfaceMessage(_ RIBType, b []byte) (Message, error) {
13 if len(b) < w.bodyOff {
14 return nil, errMessageTooShort
15 }
16 l := int(nativeEndian.Uint16(b[:2]))
17 if len(b) < l {
18 return nil, errInvalidMessage
19 }
20 attrs := uint(nativeEndian.Uint32(b[4:8]))
21 if attrs&sysRTA_IFP == 0 {
22 return nil, nil
23 }
24 m := &InterfaceMessage{
25 Version: int(b[2]),
26 Type: int(b[3]),
27 Addrs: make([]Addr, sysRTAX_MAX),
28 Flags: int(nativeEndian.Uint32(b[8:12])),
29 Index: int(nativeEndian.Uint16(b[12:14])),
30 extOff: w.extOff,
31 raw: b[:l],
32 }
33 a, err := parseLinkAddr(b[w.bodyOff:])
34 if err != nil {
35 return nil, err
36 }
37 m.Addrs[sysRTAX_IFP] = a
38 m.Name = a.(*LinkAddr).Name
39 return m, nil
40 }
41
42 func (w *wireFormat) parseInterfaceAddrMessage(_ RIBType, b []byte) (Message, error) {
43 if len(b) < w.bodyOff {
44 return nil, errMessageTooShort
45 }
46 l := int(nativeEndian.Uint16(b[:2]))
47 if len(b) < l {
48 return nil, errInvalidMessage
49 }
50 m := &InterfaceAddrMessage{
51 Version: int(b[2]),
52 Type: int(b[3]),
53 Flags: int(nativeEndian.Uint32(b[8:12])),
54 raw: b[:l],
55 }
56 if runtime.GOOS == "netbsd" {
57 m.Index = int(nativeEndian.Uint16(b[16:18]))
58 } else {
59 m.Index = int(nativeEndian.Uint16(b[12:14]))
60 }
61 var err error
62 m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[4:8])), parseKernelInetAddr, b[w.bodyOff:])
63 if err != nil {
64 return nil, err
65 }
66 return m, nil
67 }
68
View as plain text