summaryrefslogtreecommitdiff
path: root/libgo/go
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-04-03 23:44:53 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-04-03 23:44:53 +0000
commitf3e524e9b8908cdecba4eb7be58506ae60f6601a (patch)
tree9b5a391c0add620934f478e4ed676f965739b6fd /libgo/go
parentbb2288b7d8e3bbca6175656a70f0a179a7cff7be (diff)
downloadgcc-f3e524e9b8908cdecba4eb7be58506ae60f6601a.tar.gz
syscall, net: Fix GNU/Linux netlink code for big-endian systems.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186123 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go')
-rw-r--r--libgo/go/net/interface_linux.go13
-rw-r--r--libgo/go/syscall/netlink_linux.go54
2 files changed, 48 insertions, 19 deletions
diff --git a/libgo/go/net/interface_linux.go b/libgo/go/net/interface_linux.go
index 825b20227ae..0d7017f301e 100644
--- a/libgo/go/net/interface_linux.go
+++ b/libgo/go/net/interface_linux.go
@@ -64,7 +64,11 @@ func newLink(ifim *syscall.IfInfomsg, attrs []syscall.NetlinkRouteAttr) Interfac
case syscall.IFLA_IFNAME:
ifi.Name = string(a.Value[:len(a.Value)-1])
case syscall.IFLA_MTU:
- ifi.MTU = int(uint32(a.Value[3])<<24 | uint32(a.Value[2])<<16 | uint32(a.Value[1])<<8 | uint32(a.Value[0]))
+ if syscall.BigEndian {
+ ifi.MTU = int(uint32(a.Value[0])<<24 | uint32(a.Value[1])<<16 | uint32(a.Value[2])<<8 | uint32(a.Value[3]))
+ } else {
+ ifi.MTU = int(uint32(a.Value[3])<<24 | uint32(a.Value[2])<<16 | uint32(a.Value[1])<<8 | uint32(a.Value[0]))
+ }
}
}
return ifi
@@ -196,7 +200,12 @@ func parseProcNetIGMP(path string, ifi *Interface) []Addr {
for i := 0; i+1 < len(f[0]); i += 2 {
b[i/2], _ = xtoi2(f[0][i:i+2], 0)
}
- ifma := IPAddr{IP: IPv4(b[3], b[2], b[1], b[0])}
+ var ifma IPAddr
+ if syscall.BigEndian {
+ ifma = IPAddr{IP: IPv4(b[0], b[1], b[2], b[3])}
+ } else {
+ ifma = IPAddr{IP: IPv4(b[3], b[2], b[1], b[0])}
+ }
ifmat = append(ifmat, ifma.toAddr())
}
}
diff --git a/libgo/go/syscall/netlink_linux.go b/libgo/go/syscall/netlink_linux.go
index 8683bb3dacb..1c99a81785f 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
}