icmp: use socket.NativeEndian

Change-Id: I991e893a0f0b0aea680ef18e09008b30e8a972c6
Reviewed-on: https://go-review.googlesource.com/46231
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/icmp/helper.go b/icmp/helper.go
deleted file mode 100644
index 6c4e633..0000000
--- a/icmp/helper.go
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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.
-
-package icmp
-
-import (
-	"encoding/binary"
-	"unsafe"
-)
-
-var (
-	// See http://www.freebsd.org/doc/en/books/porters-handbook/freebsd-versions.html.
-	freebsdVersion uint32
-
-	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
-	}
-}
diff --git a/icmp/ipv4.go b/icmp/ipv4.go
index 729ddc9..ffc66ed 100644
--- a/icmp/ipv4.go
+++ b/icmp/ipv4.go
@@ -9,9 +9,14 @@
 	"net"
 	"runtime"
 
+	"golang.org/x/net/internal/socket"
 	"golang.org/x/net/ipv4"
 )
 
+// freebsdVersion is set in sys_freebsd.go.
+// See http://www.freebsd.org/doc/en/books/porters-handbook/freebsd-versions.html.
+var freebsdVersion uint32
+
 // ParseIPv4Header parses b as an IPv4 header of ICMP error message
 // invoking packet, which is contained in ICMP error message.
 func ParseIPv4Header(b []byte) (*ipv4.Header, error) {
@@ -36,12 +41,12 @@
 	}
 	switch runtime.GOOS {
 	case "darwin":
-		h.TotalLen = int(nativeEndian.Uint16(b[2:4]))
+		h.TotalLen = int(socket.NativeEndian.Uint16(b[2:4]))
 	case "freebsd":
 		if freebsdVersion >= 1000000 {
 			h.TotalLen = int(binary.BigEndian.Uint16(b[2:4]))
 		} else {
-			h.TotalLen = int(nativeEndian.Uint16(b[2:4]))
+			h.TotalLen = int(socket.NativeEndian.Uint16(b[2:4]))
 		}
 	default:
 		h.TotalLen = int(binary.BigEndian.Uint16(b[2:4]))
diff --git a/icmp/ipv4_test.go b/icmp/ipv4_test.go
index 47cc00d..058953f 100644
--- a/icmp/ipv4_test.go
+++ b/icmp/ipv4_test.go
@@ -11,6 +11,7 @@
 	"runtime"
 	"testing"
 
+	"golang.org/x/net/internal/socket"
 	"golang.org/x/net/ipv4"
 )
 
@@ -55,7 +56,7 @@
 
 func TestParseIPv4Header(t *testing.T) {
 	tt := &ipv4HeaderLittleEndianTest
-	if nativeEndian != binary.LittleEndian {
+	if socket.NativeEndian != binary.LittleEndian {
 		t.Skip("no test for non-little endian machine yet")
 	}