mirror of
https://github.com/golang/net.git
synced 2026-03-31 18:37:08 +09:00
This change introduces a package that provides basic functions for the manipulation of logical network interfaces, interface addresses and data links on Solaris. As BSD variants implement routing socket and routing messages, Linux implements netlink socket and netlink messages, Solaris implements STREAMS-like interface for reading, writing network facility information inside the kernel. The package wraps various I/O control calls which involve message exchanges between kernel protocol modules in exposed APIs. At present, the package supports Solaris 11 or above. Updates golang/go#7177. Change-Id: I192d85e53b0bee942dfefca0f73a3eb94ab8bfe9 Reviewed-on: https://go-review.googlesource.com/29893 Reviewed-by: Ian Lance Taylor <iant@golang.org>
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build solaris
|
|
|
|
package lif
|
|
|
|
// This file contains duplicates of encoding/binary package.
|
|
//
|
|
// This package is supposed to be used by the net package of standard
|
|
// library. Therefore the package set used in the package must be the
|
|
// same as net package.
|
|
|
|
var littleEndian binaryLittleEndian
|
|
|
|
type binaryByteOrder interface {
|
|
Uint16([]byte) uint16
|
|
Uint32([]byte) uint32
|
|
Uint64([]byte) uint64
|
|
PutUint16([]byte, uint16)
|
|
PutUint32([]byte, uint32)
|
|
PutUint64([]byte, uint64)
|
|
}
|
|
|
|
type binaryLittleEndian struct{}
|
|
|
|
func (binaryLittleEndian) Uint16(b []byte) uint16 {
|
|
_ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
|
|
return uint16(b[0]) | uint16(b[1])<<8
|
|
}
|
|
|
|
func (binaryLittleEndian) PutUint16(b []byte, v uint16) {
|
|
_ = b[1] // early bounds check to guarantee safety of writes below
|
|
b[0] = byte(v)
|
|
b[1] = byte(v >> 8)
|
|
}
|
|
|
|
func (binaryLittleEndian) Uint32(b []byte) uint32 {
|
|
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
|
|
return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
|
|
}
|
|
|
|
func (binaryLittleEndian) PutUint32(b []byte, v uint32) {
|
|
_ = b[3] // early bounds check to guarantee safety of writes below
|
|
b[0] = byte(v)
|
|
b[1] = byte(v >> 8)
|
|
b[2] = byte(v >> 16)
|
|
b[3] = byte(v >> 24)
|
|
}
|
|
|
|
func (binaryLittleEndian) Uint64(b []byte) uint64 {
|
|
_ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
|
|
return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
|
|
uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
|
|
}
|
|
|
|
func (binaryLittleEndian) PutUint64(b []byte, v uint64) {
|
|
_ = b[7] // early bounds check to guarantee safety of writes below
|
|
b[0] = byte(v)
|
|
b[1] = byte(v >> 8)
|
|
b[2] = byte(v >> 16)
|
|
b[3] = byte(v >> 24)
|
|
b[4] = byte(v >> 32)
|
|
b[5] = byte(v >> 40)
|
|
b[6] = byte(v >> 48)
|
|
b[7] = byte(v >> 56)
|
|
}
|