...

Source file src/vendor/golang.org/x/net/route/interface_openbsd.go

Documentation: vendor/golang.org/x/net/route

     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  package route
     6  
     7  import "syscall"
     8  
     9  func (*wireFormat) parseInterfaceMessage(_ RIBType, b []byte) (Message, error) {
    10  	if len(b) < 32 {
    11  		return nil, errMessageTooShort
    12  	}
    13  	l := int(nativeEndian.Uint16(b[:2]))
    14  	if len(b) < l {
    15  		return nil, errInvalidMessage
    16  	}
    17  	attrs := uint(nativeEndian.Uint32(b[12:16]))
    18  	if attrs&syscall.RTA_IFP == 0 {
    19  		return nil, nil
    20  	}
    21  	m := &InterfaceMessage{
    22  		Version: int(b[2]),
    23  		Type:    int(b[3]),
    24  		Flags:   int(nativeEndian.Uint32(b[16:20])),
    25  		Index:   int(nativeEndian.Uint16(b[6:8])),
    26  		Addrs:   make([]Addr, syscall.RTAX_MAX),
    27  		raw:     b[:l],
    28  	}
    29  	ll := int(nativeEndian.Uint16(b[4:6]))
    30  	if len(b) < ll {
    31  		return nil, errInvalidMessage
    32  	}
    33  	a, err := parseLinkAddr(b[ll:])
    34  	if err != nil {
    35  		return nil, err
    36  	}
    37  	m.Addrs[syscall.RTAX_IFP] = a
    38  	m.Name = a.(*LinkAddr).Name
    39  	return m, nil
    40  }
    41  
    42  func (*wireFormat) parseInterfaceAddrMessage(_ RIBType, b []byte) (Message, error) {
    43  	if len(b) < 24 {
    44  		return nil, errMessageTooShort
    45  	}
    46  	l := int(nativeEndian.Uint16(b[:2]))
    47  	if len(b) < l {
    48  		return nil, errInvalidMessage
    49  	}
    50  	bodyOff := int(nativeEndian.Uint16(b[4:6]))
    51  	if len(b) < bodyOff {
    52  		return nil, errInvalidMessage
    53  	}
    54  	m := &InterfaceAddrMessage{
    55  		Version: int(b[2]),
    56  		Type:    int(b[3]),
    57  		Flags:   int(nativeEndian.Uint32(b[12:16])),
    58  		Index:   int(nativeEndian.Uint16(b[6:8])),
    59  		raw:     b[:l],
    60  	}
    61  	var err error
    62  	m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[12:16])), parseKernelInetAddr, b[bodyOff:])
    63  	if err != nil {
    64  		return nil, err
    65  	}
    66  	return m, nil
    67  }
    68  
    69  func (*wireFormat) parseInterfaceAnnounceMessage(_ RIBType, b []byte) (Message, error) {
    70  	if len(b) < 26 {
    71  		return nil, errMessageTooShort
    72  	}
    73  	l := int(nativeEndian.Uint16(b[:2]))
    74  	if len(b) < l {
    75  		return nil, errInvalidMessage
    76  	}
    77  	m := &InterfaceAnnounceMessage{
    78  		Version: int(b[2]),
    79  		Type:    int(b[3]),
    80  		Index:   int(nativeEndian.Uint16(b[6:8])),
    81  		What:    int(nativeEndian.Uint16(b[8:10])),
    82  		raw:     b[:l],
    83  	}
    84  	for i := 0; i < 16; i++ {
    85  		if b[10+i] != 0 {
    86  			continue
    87  		}
    88  		m.Name = string(b[10 : 10+i])
    89  		break
    90  	}
    91  	return m, nil
    92  }
    93  

View as plain text