From ea8505da9065b468420470afd10efec62a0048ad Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor <ian@gcc.gnu.org>
Date: Tue, 3 Apr 2012 23:44:53 +0000
Subject: syscall, net: Fix GNU/Linux netlink code for big-endian systems.

From-SVN: r186123
---
 libgo/go/syscall/netlink_linux.go | 54 +++++++++++++++++++++++++++------------
 1 file changed, 37 insertions(+), 17 deletions(-)

(limited to 'libgo/go/syscall/netlink_linux.go')

diff --git a/libgo/go/syscall/netlink_linux.go b/libgo/go/syscall/netlink_linux.go
index 8683bb3..1c99a81 100644
--- a/libgo/go/syscall/netlink_linux.go
+++ b/libgo/go/syscall/netlink_linux.go
@@ -30,23 +30,43 @@ type NetlinkRouteRequest struct {
 
 func (rr *NetlinkRouteRequest) toWireFormat() []byte {
 	b := make([]byte, rr.Header.Len)
-	b[0] = byte(rr.Header.Len)
-	b[1] = byte(rr.Header.Len >> 8)
-	b[2] = byte(rr.Header.Len >> 16)
-	b[3] = byte(rr.Header.Len >> 24)
-	b[4] = byte(rr.Header.Type)
-	b[5] = byte(rr.Header.Type >> 8)
-	b[6] = byte(rr.Header.Flags)
-	b[7] = byte(rr.Header.Flags >> 8)
-	b[8] = byte(rr.Header.Seq)
-	b[9] = byte(rr.Header.Seq >> 8)
-	b[10] = byte(rr.Header.Seq >> 16)
-	b[11] = byte(rr.Header.Seq >> 24)
-	b[12] = byte(rr.Header.Pid)
-	b[13] = byte(rr.Header.Pid >> 8)
-	b[14] = byte(rr.Header.Pid >> 16)
-	b[15] = byte(rr.Header.Pid >> 24)
-	b[16] = byte(rr.Data.Family)
+	if BigEndian {
+		b[0] = byte(rr.Header.Len >> 24)
+		b[1] = byte(rr.Header.Len >> 16)
+		b[2] = byte(rr.Header.Len >> 8)
+		b[3] = byte(rr.Header.Len)
+		b[4] = byte(rr.Header.Type >> 8)
+		b[5] = byte(rr.Header.Type)
+		b[6] = byte(rr.Header.Flags >> 8)
+		b[7] = byte(rr.Header.Flags)
+		b[8] = byte(rr.Header.Seq >> 24)
+		b[9] = byte(rr.Header.Seq >> 16)
+		b[10] = byte(rr.Header.Seq >> 8)
+		b[11] = byte(rr.Header.Seq)
+		b[12] = byte(rr.Header.Pid >> 24)
+		b[13] = byte(rr.Header.Pid >> 16)
+		b[14] = byte(rr.Header.Pid >> 8)
+		b[15] = byte(rr.Header.Pid)
+		b[16] = byte(rr.Data.Family)
+	} else {
+		b[0] = byte(rr.Header.Len)
+		b[1] = byte(rr.Header.Len >> 8)
+		b[2] = byte(rr.Header.Len >> 16)
+		b[3] = byte(rr.Header.Len >> 24)
+		b[4] = byte(rr.Header.Type)
+		b[5] = byte(rr.Header.Type >> 8)
+		b[6] = byte(rr.Header.Flags)
+		b[7] = byte(rr.Header.Flags >> 8)
+		b[8] = byte(rr.Header.Seq)
+		b[9] = byte(rr.Header.Seq >> 8)
+		b[10] = byte(rr.Header.Seq >> 16)
+		b[11] = byte(rr.Header.Seq >> 24)
+		b[12] = byte(rr.Header.Pid)
+		b[13] = byte(rr.Header.Pid >> 8)
+		b[14] = byte(rr.Header.Pid >> 16)
+		b[15] = byte(rr.Header.Pid >> 24)
+		b[16] = byte(rr.Data.Family)
+	}
 	return b
 }
 
-- 
cgit v1.1