Commit 454122b1 authored by Mikio Hara's avatar Mikio Hara

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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent fe686d45
...@@ -17,7 +17,7 @@ func marshal2292HopLimit(b []byte, cm *ControlMessage) []byte { ...@@ -17,7 +17,7 @@ func marshal2292HopLimit(b []byte, cm *ControlMessage) []byte {
m := socket.ControlMessage(b) m := socket.ControlMessage(b)
m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_2292HOPLIMIT, 4) m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_2292HOPLIMIT, 4)
if cm != nil { if cm != nil {
nativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit)) socket.NativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
} }
return m.Next(4) return m.Next(4)
} }
......
...@@ -18,26 +18,26 @@ func marshalTrafficClass(b []byte, cm *ControlMessage) []byte { ...@@ -18,26 +18,26 @@ func marshalTrafficClass(b []byte, cm *ControlMessage) []byte {
m := socket.ControlMessage(b) m := socket.ControlMessage(b)
m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_TCLASS, 4) m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_TCLASS, 4)
if cm != nil { if cm != nil {
nativeEndian.PutUint32(m.Data(4), uint32(cm.TrafficClass)) socket.NativeEndian.PutUint32(m.Data(4), uint32(cm.TrafficClass))
} }
return m.Next(4) return m.Next(4)
} }
func parseTrafficClass(cm *ControlMessage, b []byte) { 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 { func marshalHopLimit(b []byte, cm *ControlMessage) []byte {
m := socket.ControlMessage(b) m := socket.ControlMessage(b)
m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_HOPLIMIT, 4) m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_HOPLIMIT, 4)
if cm != nil { if cm != nil {
nativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit)) socket.NativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
} }
return m.Next(4) return m.Next(4)
} }
func parseHopLimit(cm *ControlMessage, b []byte) { 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 { func marshalPacketInfo(b []byte, cm *ControlMessage) []byte {
......
...@@ -5,10 +5,8 @@ ...@@ -5,10 +5,8 @@
package ipv6 package ipv6
import ( import (
"encoding/binary"
"errors" "errors"
"net" "net"
"unsafe"
) )
var ( var (
...@@ -17,20 +15,8 @@ var ( ...@@ -17,20 +15,8 @@ var (
errInvalidConnType = errors.New("invalid conn type") errInvalidConnType = errors.New("invalid conn type")
errOpNoSupport = errors.New("operation not supported") errOpNoSupport = errors.New("operation not supported")
errNoSuchInterface = errors.New("no such interface") 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 { func boolint(b bool) int {
if b { if b {
return 1 return 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment