github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/golang.org/x/net/route/interface_announce.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 dragonfly freebsd netbsd
     6  
     7  package route
     8  
     9  func (w *wireFormat) parseInterfaceAnnounceMessage(_ RIBType, b []byte) (Message, error) {
    10  	if len(b) < w.bodyOff {
    11  		return nil, errMessageTooShort
    12  	}
    13  	l := int(nativeEndian.Uint16(b[:2]))
    14  	if len(b) < l {
    15  		return nil, errInvalidMessage
    16  	}
    17  	m := &InterfaceAnnounceMessage{
    18  		Version: int(b[2]),
    19  		Type:    int(b[3]),
    20  		Index:   int(nativeEndian.Uint16(b[4:6])),
    21  		What:    int(nativeEndian.Uint16(b[22:24])),
    22  		raw:     b[:l],
    23  	}
    24  	for i := 0; i < 16; i++ {
    25  		if b[6+i] != 0 {
    26  			continue
    27  		}
    28  		m.Name = string(b[6 : 6+i])
    29  		break
    30  	}
    31  	return m, nil
    32  }