diff --git a/configure b/configure index d178913..f52a1d2 100755 --- a/configure +++ b/configure @@ -665,6 +665,120 @@ EOF fi +# If we cannot run a trivial program, we must be cross compiling. +echo $ac_n "checking whether cross-compiling""... $ac_c" 1>&6 +if eval "test \"`echo '$''{'ac_cv_c_cross'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test "$cross_compiling" = yes; then + ac_cv_c_cross=yes +else +cat > conftest.$ac_ext </dev/null; then + ac_cv_c_cross=no +else + ac_cv_c_cross=yes +fi +fi +rm -fr conftest* +fi +cross_compiling=$ac_cv_c_cross +echo "$ac_t""$ac_cv_c_cross" 1>&6 + +echo $ac_n "checking whether byte ordering is bigendian""... $ac_c" 1>&6 +if eval "test \"`echo '$''{'ac_cv_c_bigendian'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_cv_c_bigendian=unknown +# See if sys/param.h defines the BYTE_ORDER macro. +cat > conftest.$ac_ext < +#include +int main() { return 0; } +int t() { + +#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN + bogus endian macros +#endif +; return 0; } +EOF +if eval $ac_compile; then + rm -rf conftest* + # It does; now see whether it defined to BIG_ENDIAN or not. +cat > conftest.$ac_ext < +#include +int main() { return 0; } +int t() { + +#if BYTE_ORDER != BIG_ENDIAN + not big endian +#endif +; return 0; } +EOF +if eval $ac_compile; then + rm -rf conftest* + ac_cv_c_bigendian=yes +else + rm -rf conftest* + ac_cv_c_bigendian=no +fi +rm -f conftest* + +fi +rm -f conftest* + +if test $ac_cv_c_bigendian = unknown; then +if test "$cross_compiling" = yes; then + { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } +else +cat > conftest.$ac_ext </dev/null; then + ac_cv_c_bigendian=no +else + ac_cv_c_bigendian=yes +fi +fi +rm -fr conftest* +fi +fi +echo "$ac_t""$ac_cv_c_bigendian" 1>&6 +if test $ac_cv_c_bigendian = yes; then + cat >> confdefs.h <<\EOF +#define WORDS_BIGENDIAN 1 +EOF + +fi + +if $ac_cv_c_bigendian = no ; then + ENDIAN=little +else + ENDIAN=big +fi + case "$host" in ## CX/UX @@ -812,7 +926,6 @@ EOF ;; esac -echo machine dir is $srcdir/$dir /bin/rm -f $srcdir/scsh/machine ln -s $srcdir/$dir $srcdir/scsh/machine @@ -823,7 +936,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lm $LIBS" cat > conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext <&6 else cat > conftest.$ac_ext < #include @@ -1142,7 +1255,7 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext < Syntax Error @@ -1156,7 +1269,7 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext < Syntax Error @@ -1189,7 +1302,7 @@ if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF @@ -1224,7 +1337,7 @@ if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&6 else cat > conftest.$ac_ext < conftest.$ac_ext < int main() { return 0; } @@ -1432,7 +1545,7 @@ EOF else cat > conftest.$ac_ext < int main() { return 0; } @@ -1467,7 +1580,7 @@ EOF else cat > conftest.$ac_ext < int main() { return 0; } @@ -1501,7 +1614,7 @@ EOF else cat > conftest.$ac_ext < int main() { return 0; } @@ -1536,7 +1649,7 @@ EOF else cat > conftest.$ac_ext < #include @@ -1573,6 +1686,7 @@ CFLAGS1=${CFLAGS} + trap '' 1 2 15 cat > confcache <<\EOF # This file is a shell script that caches the results of configure @@ -1660,7 +1774,7 @@ done ac_given_srcdir=$srcdir ac_given_INSTALL="$INSTALL" -trap 'rm -fr `echo "Makefile scsh/regexp/Makefile sysdep.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 +trap 'rm -fr `echo "Makefile scsh/regexp/Makefile scsh/network.scm sysdep.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 # Protect against being on the right side of a sed subst in config.status. sed 's/%@/@@/; s/@%/@@/; s/%g$/@g/; /@g$/s/[\\\\&%]/\\\\&/g; @@ -1687,13 +1801,14 @@ s%@INSTALL_DATA@%$INSTALL_DATA%g s%@CPP@%$CPP%g s%@AIX_P@%$AIX_P%g s%@CFLAGS1@%$CFLAGS1%g +s%@ENDIAN@%$ENDIAN%g s%@LDFLAGS_AIX@%$LDFLAGS_AIX%g CEOF EOF cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then diff --git a/configure.in b/configure.in index 9560c09..de21bf1 100644 --- a/configure.in +++ b/configure.in @@ -193,6 +193,13 @@ AC_ISC_POSIX AC_PROG_INSTALL AC_C_CONST +AC_C_BIGENDIAN +if [ $ac_cv_c_bigendian = no ] ; then + ENDIAN=little +else + ENDIAN=big +fi + case "$host" in ## CX/UX @@ -315,7 +322,8 @@ CFLAGS1=${CFLAGS} AC_SUBST(AIX_P) AC_SUBST(CFLAGS) AC_SUBST(CFLAGS1) +AC_SUBST(ENDIAN) AC_SUBST(LDFLAGS) AC_SUBST(LDFLAGS_AIX) -AC_OUTPUT(Makefile scsh/regexp/Makefile) +AC_OUTPUT(Makefile scsh/regexp/Makefile scsh/network.scm) diff --git a/scsh/network.scm b/scsh/network.scm index 3af8b85..64e9222 100644 --- a/scsh/network.scm +++ b/scsh/network.scm @@ -935,6 +935,43 @@ (C char**) ; alias list integer) ; protocol number +;;;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +;;; Endian Conversion routines +;;;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +;; Big Endian - Motorola, Sparc, HPPA, etc +(define (net-to-host-32-big num32) + (and (<= 0 num32 #xffffffff) + num32)) + +(define (net-to-host-16-big num16) + (and (<= 0 num16 #xffffffff) + num16)) + +;; Little Endian - Intel, Vax, Alpha +(define (net-to-host-32-little num32) + (and (<= 0 num32 #xffffffff) + (let* ((num24 (arithmetic-shift num32 -8)) + (num16 (arithmetic-shift num24 -8)) + (num08 (arithmetic-shift num16 -8)) + (byte0 (bitwise-and #b11111111 num08)) + (byte1 (bitwise-and #b11111111 num16)) + (byte2 (bitwise-and #b11111111 num24)) + (byte3 (bitwise-and #b11111111 num32))) + (+ (arithmetic-shift byte3 24) + +(define (net-to-host-16-little num16) + (and (<= 0 num16 #xffffffff) + (let* ((num08 (arithmetic-shift num16 -8)) + (byte0 (bitwise-and #b11111111 num08)) + (byte1 (bitwise-and #b11111111 num16)) + (+ (arithmetic-shift byte1 8) + byte0)))) + +(define net-to-host-32 net-to-host-32-@ENDIAN@) +(define net-to-host-16 net-to-host-16-@ENDIAN@) +(define host-to-net-32 host-to-net-32-@ENDIAN@) +(define host-to-net-16 host-to-net-16-@ENDIAN@) + ;;;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ;;; Lowlevel junk ;;;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- diff --git a/scsh/scsh-interfaces.scm b/scsh/scsh-interfaces.scm index d353430..caede28 100644 --- a/scsh/scsh-interfaces.scm +++ b/scsh/scsh-interfaces.scm @@ -644,6 +644,11 @@ protocol-info:name protocol-info:aliases protocol-info:number + + net-to-host-32 + net-to-host-16 + host-to-net-32 + host-to-net-16 ))