Browse Source

ipv6: use socket.NativeEndian

Change-Id: Ia73c7bfff664f91c8a4c97656d0bd9e576145aa4
Reviewed-on: https://go-review.googlesource.com/46230
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Mikio Hara 8 years ago
parent
commit
454122b185
3 changed files with 5 additions and 19 deletions
  1. 1 1
      ipv6/control_rfc2292_unix.go
  2. 4 4
      ipv6/control_rfc3542_unix.go
  3. 0 14
      ipv6/helper.go

+ 1 - 1
ipv6/control_rfc2292_unix.go

@@ -17,7 +17,7 @@ func marshal2292HopLimit(b []byte, cm *ControlMessage) []byte {
 	m := socket.ControlMessage(b)
 	m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_2292HOPLIMIT, 4)
 	if cm != nil {
-		nativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
+		socket.NativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
 	}
 	return m.Next(4)
 }

+ 4 - 4
ipv6/control_rfc3542_unix.go

@@ -18,26 +18,26 @@ func marshalTrafficClass(b []byte, cm *ControlMessage) []byte {
 	m := socket.ControlMessage(b)
 	m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_TCLASS, 4)
 	if cm != nil {
-		nativeEndian.PutUint32(m.Data(4), uint32(cm.TrafficClass))
+		socket.NativeEndian.PutUint32(m.Data(4), uint32(cm.TrafficClass))
 	}
 	return m.Next(4)
 }
 
 func parseTrafficClass(cm *ControlMessage, b []byte) {
-	cm.TrafficClass = int(nativeEndian.Uint32(b[:4]))
+	cm.TrafficClass = int(socket.NativeEndian.Uint32(b[:4]))
 }
 
 func marshalHopLimit(b []byte, cm *ControlMessage) []byte {
 	m := socket.ControlMessage(b)
 	m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_HOPLIMIT, 4)
 	if cm != nil {
-		nativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
+		socket.NativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
 	}
 	return m.Next(4)
 }
 
 func parseHopLimit(cm *ControlMessage, b []byte) {
-	cm.HopLimit = int(nativeEndian.Uint32(b[:4]))
+	cm.HopLimit = int(socket.NativeEndian.Uint32(b[:4]))
 }
 
 func marshalPacketInfo(b []byte, cm *ControlMessage) []byte {

+ 0 - 14
ipv6/helper.go

@@ -5,10 +5,8 @@
 package ipv6
 
 import (
-	"encoding/binary"
 	"errors"
 	"net"
-	"unsafe"
 )
 
 var (
@@ -17,20 +15,8 @@ var (
 	errInvalidConnType = errors.New("invalid conn type")
 	errOpNoSupport     = errors.New("operation not supported")
 	errNoSuchInterface = errors.New("no such interface")
-
-	nativeEndian binary.ByteOrder
 )
 
-func init() {
-	i := uint32(1)
-	b := (*[4]byte)(unsafe.Pointer(&i))
-	if b[0] == 1 {
-		nativeEndian = binary.LittleEndian
-	} else {
-		nativeEndian = binary.BigEndian
-	}
-}
-
 func boolint(b bool) int {
 	if b {
 		return 1