syscall, net: Fix GNU/Linux netlink code for big-endian systems.
From-SVN: r186123
This commit is contained in:
parent
a92873f127
commit
ea8505da90
@ -1559,6 +1559,7 @@ s-syscall_arch: Makefile
|
|||||||
echo "package syscall" > syscall_arch.go.tmp
|
echo "package syscall" > syscall_arch.go.tmp
|
||||||
echo 'const ARCH = "'$(GOARCH)'"' >> syscall_arch.go.tmp
|
echo 'const ARCH = "'$(GOARCH)'"' >> syscall_arch.go.tmp
|
||||||
echo 'const OS = "'$(GOOS)'"' >> syscall_arch.go.tmp
|
echo 'const OS = "'$(GOOS)'"' >> syscall_arch.go.tmp
|
||||||
|
echo 'const BigEndian = $(GO_BIGENDIAN)' >> syscall_arch.go.tmp
|
||||||
$(SHELL) $(srcdir)/../move-if-change syscall_arch.go.tmp syscall_arch.go
|
$(SHELL) $(srcdir)/../move-if-change syscall_arch.go.tmp syscall_arch.go
|
||||||
$(STAMP) $@
|
$(STAMP) $@
|
||||||
|
|
||||||
|
@ -369,6 +369,7 @@ GOARCH = @GOARCH@
|
|||||||
GOC = @GOC@
|
GOC = @GOC@
|
||||||
GOCFLAGS = $(CFLAGS)
|
GOCFLAGS = $(CFLAGS)
|
||||||
GOOS = @GOOS@
|
GOOS = @GOOS@
|
||||||
|
GO_BIGENDIAN = @GO_BIGENDIAN@
|
||||||
GO_LIBCALL_OS_ARCH_FILE = @GO_LIBCALL_OS_ARCH_FILE@
|
GO_LIBCALL_OS_ARCH_FILE = @GO_LIBCALL_OS_ARCH_FILE@
|
||||||
GO_LIBCALL_OS_FILE = @GO_LIBCALL_OS_FILE@
|
GO_LIBCALL_OS_FILE = @GO_LIBCALL_OS_FILE@
|
||||||
GO_SYSCALL_OS_ARCH_FILE = @GO_SYSCALL_OS_ARCH_FILE@
|
GO_SYSCALL_OS_ARCH_FILE = @GO_SYSCALL_OS_ARCH_FILE@
|
||||||
@ -4371,6 +4372,7 @@ s-syscall_arch: Makefile
|
|||||||
echo "package syscall" > syscall_arch.go.tmp
|
echo "package syscall" > syscall_arch.go.tmp
|
||||||
echo 'const ARCH = "'$(GOARCH)'"' >> syscall_arch.go.tmp
|
echo 'const ARCH = "'$(GOARCH)'"' >> syscall_arch.go.tmp
|
||||||
echo 'const OS = "'$(GOOS)'"' >> syscall_arch.go.tmp
|
echo 'const OS = "'$(GOOS)'"' >> syscall_arch.go.tmp
|
||||||
|
echo 'const BigEndian = $(GO_BIGENDIAN)' >> syscall_arch.go.tmp
|
||||||
$(SHELL) $(srcdir)/../move-if-change syscall_arch.go.tmp syscall_arch.go
|
$(SHELL) $(srcdir)/../move-if-change syscall_arch.go.tmp syscall_arch.go
|
||||||
$(STAMP) $@
|
$(STAMP) $@
|
||||||
|
|
||||||
|
11
libgo/configure
vendored
11
libgo/configure
vendored
@ -612,6 +612,7 @@ HAVE_STRERROR_R_FALSE
|
|||||||
HAVE_STRERROR_R_TRUE
|
HAVE_STRERROR_R_TRUE
|
||||||
HAVE_SYS_MMAN_H_FALSE
|
HAVE_SYS_MMAN_H_FALSE
|
||||||
HAVE_SYS_MMAN_H_TRUE
|
HAVE_SYS_MMAN_H_TRUE
|
||||||
|
GO_BIGENDIAN
|
||||||
PTHREAD_LIBS
|
PTHREAD_LIBS
|
||||||
PTHREAD_CFLAGS
|
PTHREAD_CFLAGS
|
||||||
NET_LIBS
|
NET_LIBS
|
||||||
@ -11100,7 +11101,7 @@ else
|
|||||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||||
lt_status=$lt_dlunknown
|
lt_status=$lt_dlunknown
|
||||||
cat > conftest.$ac_ext <<_LT_EOF
|
cat > conftest.$ac_ext <<_LT_EOF
|
||||||
#line 11103 "configure"
|
#line 11104 "configure"
|
||||||
#include "confdefs.h"
|
#include "confdefs.h"
|
||||||
|
|
||||||
#if HAVE_DLFCN_H
|
#if HAVE_DLFCN_H
|
||||||
@ -11206,7 +11207,7 @@ else
|
|||||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||||
lt_status=$lt_dlunknown
|
lt_status=$lt_dlunknown
|
||||||
cat > conftest.$ac_ext <<_LT_EOF
|
cat > conftest.$ac_ext <<_LT_EOF
|
||||||
#line 11209 "configure"
|
#line 11210 "configure"
|
||||||
#include "confdefs.h"
|
#include "confdefs.h"
|
||||||
|
|
||||||
#if HAVE_DLFCN_H
|
#if HAVE_DLFCN_H
|
||||||
@ -14408,6 +14409,12 @@ $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h
|
|||||||
presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;;
|
presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
case $ac_cv_c_bigendian in
|
||||||
|
yes) GO_BIGENDIAN=true ;;
|
||||||
|
no) GO_BIGENDIAN=false ;;
|
||||||
|
*) as_fn_error "unknown endianness" "$LINENO" 5 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -400,6 +400,12 @@ dnl Test if -lrt is required for sched_yield.
|
|||||||
AC_SEARCH_LIBS([sched_yield], [rt])
|
AC_SEARCH_LIBS([sched_yield], [rt])
|
||||||
|
|
||||||
AC_C_BIGENDIAN
|
AC_C_BIGENDIAN
|
||||||
|
case $ac_cv_c_bigendian in
|
||||||
|
yes) GO_BIGENDIAN=true ;;
|
||||||
|
no) GO_BIGENDIAN=false ;;
|
||||||
|
*) AC_MSG_ERROR([unknown endianness]) ;;
|
||||||
|
esac
|
||||||
|
AC_SUBST(GO_BIGENDIAN)
|
||||||
|
|
||||||
GCC_CHECK_UNWIND_GETIPINFO
|
GCC_CHECK_UNWIND_GETIPINFO
|
||||||
|
|
||||||
|
@ -64,7 +64,11 @@ func newLink(ifim *syscall.IfInfomsg, attrs []syscall.NetlinkRouteAttr) Interfac
|
|||||||
case syscall.IFLA_IFNAME:
|
case syscall.IFLA_IFNAME:
|
||||||
ifi.Name = string(a.Value[:len(a.Value)-1])
|
ifi.Name = string(a.Value[:len(a.Value)-1])
|
||||||
case syscall.IFLA_MTU:
|
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
|
return ifi
|
||||||
@ -196,7 +200,12 @@ func parseProcNetIGMP(path string, ifi *Interface) []Addr {
|
|||||||
for i := 0; i+1 < len(f[0]); i += 2 {
|
for i := 0; i+1 < len(f[0]); i += 2 {
|
||||||
b[i/2], _ = xtoi2(f[0][i:i+2], 0)
|
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())
|
ifmat = append(ifmat, ifma.toAddr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,23 +30,43 @@ type NetlinkRouteRequest struct {
|
|||||||
|
|
||||||
func (rr *NetlinkRouteRequest) toWireFormat() []byte {
|
func (rr *NetlinkRouteRequest) toWireFormat() []byte {
|
||||||
b := make([]byte, rr.Header.Len)
|
b := make([]byte, rr.Header.Len)
|
||||||
b[0] = byte(rr.Header.Len)
|
if BigEndian {
|
||||||
b[1] = byte(rr.Header.Len >> 8)
|
b[0] = byte(rr.Header.Len >> 24)
|
||||||
b[2] = byte(rr.Header.Len >> 16)
|
b[1] = byte(rr.Header.Len >> 16)
|
||||||
b[3] = byte(rr.Header.Len >> 24)
|
b[2] = byte(rr.Header.Len >> 8)
|
||||||
b[4] = byte(rr.Header.Type)
|
b[3] = byte(rr.Header.Len)
|
||||||
b[5] = byte(rr.Header.Type >> 8)
|
b[4] = byte(rr.Header.Type >> 8)
|
||||||
b[6] = byte(rr.Header.Flags)
|
b[5] = byte(rr.Header.Type)
|
||||||
b[7] = byte(rr.Header.Flags >> 8)
|
b[6] = byte(rr.Header.Flags >> 8)
|
||||||
b[8] = byte(rr.Header.Seq)
|
b[7] = byte(rr.Header.Flags)
|
||||||
b[9] = byte(rr.Header.Seq >> 8)
|
b[8] = byte(rr.Header.Seq >> 24)
|
||||||
b[10] = byte(rr.Header.Seq >> 16)
|
b[9] = byte(rr.Header.Seq >> 16)
|
||||||
b[11] = byte(rr.Header.Seq >> 24)
|
b[10] = byte(rr.Header.Seq >> 8)
|
||||||
b[12] = byte(rr.Header.Pid)
|
b[11] = byte(rr.Header.Seq)
|
||||||
b[13] = byte(rr.Header.Pid >> 8)
|
b[12] = byte(rr.Header.Pid >> 24)
|
||||||
b[14] = byte(rr.Header.Pid >> 16)
|
b[13] = byte(rr.Header.Pid >> 16)
|
||||||
b[15] = byte(rr.Header.Pid >> 24)
|
b[14] = byte(rr.Header.Pid >> 8)
|
||||||
b[16] = byte(rr.Data.Family)
|
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
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +86,7 @@ GOARCH = @GOARCH@
|
|||||||
GOC = @GOC@
|
GOC = @GOC@
|
||||||
GOCFLAGS = @GOCFLAGS@
|
GOCFLAGS = @GOCFLAGS@
|
||||||
GOOS = @GOOS@
|
GOOS = @GOOS@
|
||||||
|
GO_BIGENDIAN = @GO_BIGENDIAN@
|
||||||
GO_LIBCALL_OS_ARCH_FILE = @GO_LIBCALL_OS_ARCH_FILE@
|
GO_LIBCALL_OS_ARCH_FILE = @GO_LIBCALL_OS_ARCH_FILE@
|
||||||
GO_LIBCALL_OS_FILE = @GO_LIBCALL_OS_FILE@
|
GO_LIBCALL_OS_FILE = @GO_LIBCALL_OS_FILE@
|
||||||
GO_SYSCALL_OS_ARCH_FILE = @GO_SYSCALL_OS_ARCH_FILE@
|
GO_SYSCALL_OS_ARCH_FILE = @GO_SYSCALL_OS_ARCH_FILE@
|
||||||
|
Loading…
Reference in New Issue
Block a user