Explorar o código

internal/socket: make ipv4, ipv6 and icmp work again on android

On android, runtime.GOOS returns "android" instead of "linux".

Fixes golang/go#22115.

Change-Id: Idd24d5602f8fa9be1fca0b64bd8966849ea2b5e7
Reviewed-on: https://go-review.googlesource.com/67770
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Mikio Hara %!s(int64=8) %!d(string=hai) anos
pai
achega
a04bdaca5b
Modificáronse 2 ficheiros con 5 adicións e 5 borrados
  1. 2 2
      internal/socket/socket_go1_9_test.go
  2. 3 3
      internal/socket/sys_posix.go

+ 2 - 2
internal/socket/socket_go1_9_test.go

@@ -145,7 +145,7 @@ func TestUDP(t *testing.T) {
 		}
 	})
 	switch runtime.GOOS {
-	case "linux":
+	case "android", "linux":
 		t.Run("Messages", func(t *testing.T) {
 			data := []byte("HELLO-R-U-THERE")
 			wmbs := bytes.SplitAfter(data, []byte("-"))
@@ -233,7 +233,7 @@ func BenchmarkUDP(b *testing.B) {
 			}
 		})
 		switch runtime.GOOS {
-		case "linux":
+		case "android", "linux":
 			wms := make([]socket.Message, M)
 			for i := range wms {
 				wms[i].Buffers = [][]byte{data}

+ 3 - 3
internal/socket/sys_posix.go

@@ -34,7 +34,7 @@ func marshalSockaddr(ip net.IP, port int, zone string) []byte {
 	if ip4 := ip.To4(); ip4 != nil {
 		b := make([]byte, sizeofSockaddrInet)
 		switch runtime.GOOS {
-		case "linux", "solaris", "windows":
+		case "android", "linux", "solaris", "windows":
 			NativeEndian.PutUint16(b[:2], uint16(sysAF_INET))
 		default:
 			b[0] = sizeofSockaddrInet
@@ -47,7 +47,7 @@ func marshalSockaddr(ip net.IP, port int, zone string) []byte {
 	if ip6 := ip.To16(); ip6 != nil && ip.To4() == nil {
 		b := make([]byte, sizeofSockaddrInet6)
 		switch runtime.GOOS {
-		case "linux", "solaris", "windows":
+		case "android", "linux", "solaris", "windows":
 			NativeEndian.PutUint16(b[:2], uint16(sysAF_INET6))
 		default:
 			b[0] = sizeofSockaddrInet6
@@ -69,7 +69,7 @@ func parseInetAddr(b []byte, network string) (net.Addr, error) {
 	}
 	var af int
 	switch runtime.GOOS {
-	case "linux", "solaris", "windows":
+	case "android", "linux", "solaris", "windows":
 		af = int(NativeEndian.Uint16(b[:2]))
 	default:
 		af = int(b[1])