github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/golang.org/x/net/route/interface_classic.go (about) 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. 4 5 // +build darwin dragonfly netbsd 6 7 package route 8 9 import "runtime" 10 11 func (w *wireFormat) parseInterfaceMessage(_ RIBType, b []byte) (Message, error) { 12 if len(b) < w.bodyOff { 13 return nil, errMessageTooShort 14 } 15 l := int(nativeEndian.Uint16(b[:2])) 16 if len(b) < l { 17 return nil, errInvalidMessage 18 } 19 attrs := uint(nativeEndian.Uint32(b[4:8])) 20 if attrs&sysRTA_IFP == 0 { 21 return nil, nil 22 } 23 m := &InterfaceMessage{ 24 Version: int(b[2]), 25 Type: int(b[3]), 26 Addrs: make([]Addr, sysRTAX_MAX), 27 Flags: int(nativeEndian.Uint32(b[8:12])), 28 Index: int(nativeEndian.Uint16(b[12:14])), 29 extOff: w.extOff, 30 raw: b[:l], 31 } 32 a, err := parseLinkAddr(b[w.bodyOff:]) 33 if err != nil { 34 return nil, err 35 } 36 m.Addrs[sysRTAX_IFP] = a 37 m.Name = a.(*LinkAddr).Name 38 return m, nil 39 } 40 41 func (w *wireFormat) parseInterfaceAddrMessage(_ RIBType, b []byte) (Message, error) { 42 if len(b) < w.bodyOff { 43 return nil, errMessageTooShort 44 } 45 l := int(nativeEndian.Uint16(b[:2])) 46 if len(b) < l { 47 return nil, errInvalidMessage 48 } 49 m := &InterfaceAddrMessage{ 50 Version: int(b[2]), 51 Type: int(b[3]), 52 Flags: int(nativeEndian.Uint32(b[8:12])), 53 raw: b[:l], 54 } 55 if runtime.GOOS == "netbsd" { 56 m.Index = int(nativeEndian.Uint16(b[16:18])) 57 } else { 58 m.Index = int(nativeEndian.Uint16(b[12:14])) 59 } 60 var err error 61 m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[4:8])), parseKernelInetAddr, b[w.bodyOff:]) 62 if err != nil { 63 return nil, err 64 } 65 return m, nil 66 }