diff --git a/configure.ac b/configure.ac index 92dc01b..42cb20b 100644 --- a/configure.ac +++ b/configure.ac @@ -71,6 +71,16 @@ AC_FUNC_MBRTOWC AC_FUNC_REALLOC AC_CHECK_FUNCS([clock_gettime gettimeofday inet_ntoa iswprint memchr memset nl_langinfo setenv setlocale socket strchr strdup strerror strtol wcwidth]) +AC_CHECK_DECL([htobe64], + [AC_DEFINE([HAVE_HTOBE64], [1], + [Define if htobe64 and friends exist.])], + [AC_CHECK_DECL([OSSwapHostToBigInt64], + [AC_DEFINE([HAVE_OSX_SWAP], [1], + [Define if OSSwapHostToBigInt64 and friends exist.])], + [AC_MSG_ERROR([Unable to find byte swapping functions])], + [[#include ]])], + [[#include ]]) + # Checks for protobuf PKG_CHECK_MODULES([protobuf], [protobuf]) diff --git a/src/crypto/Makefile.am b/src/crypto/Makefile.am index e55a647..c239b43 100644 --- a/src/crypto/Makefile.am +++ b/src/crypto/Makefile.am @@ -2,4 +2,13 @@ AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) -fno-default-inline -pipe noinst_LIBRARIES = libmoshcrypto.a -libmoshcrypto_a_SOURCES = ae.h base64.cc base64.h crypto.cc crypto.h ocb.cc rijndael-alg-fst.cc rijndael-alg-fst.h \ No newline at end of file +libmoshcrypto_a_SOURCES = \ + ae.h \ + base64.cc \ + base64.h \ + byteorder.h \ + crypto.cc \ + crypto.h \ + ocb.cc \ + rijndael-alg-fst.cc \ + rijndael-alg-fst.h diff --git a/src/crypto/base64.h b/src/crypto/base64.h index 8efa678..7593e59 100644 --- a/src/crypto/base64.h +++ b/src/crypto/base64.h @@ -1,7 +1,5 @@ /* Taken from GNU coreutils */ -#define restrict - /* base64.h -- Encode binary data using printable characters. Copyright (C) 2004-2006, 2009-2011 Free Software Foundation, Inc. Written by Simon Josefsson. @@ -23,6 +21,8 @@ #ifndef BASE64_H # define BASE64_H +# include "config.h" + /* Get size_t. */ # include diff --git a/src/crypto/byteorder.h b/src/crypto/byteorder.h new file mode 100644 index 0000000..f0c7f06 --- /dev/null +++ b/src/crypto/byteorder.h @@ -0,0 +1,34 @@ +/* + Mosh: the mobile shell + Copyright 2012 Keith Winstein + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef BYTEORDER_HPP +#define BYTEORDER_HPP + +#include "config.h" + +#ifdef HAVE_HTOBE64 +# include +#elif HAVE_OSX_SWAP +# include +# define htobe64 OSSwapHostToBigInt64 +# define be64toh OSSwapBigToHostInt64 +# define htobe16 OSSwapHostToBigInt16 +# define be16toh OSSwapBigToHostInt16 +#endif + +#endif diff --git a/src/crypto/crypto.cc b/src/crypto/crypto.cc index e5ee202..2e90ca8 100644 --- a/src/crypto/crypto.cc +++ b/src/crypto/crypto.cc @@ -21,6 +21,7 @@ #include #include +#include "byteorder.h" #include "crypto.h" #include "base64.h" diff --git a/src/network/network.cc b/src/network/network.cc index b424158..089a587 100644 --- a/src/network/network.cc +++ b/src/network/network.cc @@ -21,10 +21,10 @@ #include #include #include -#include #include #include "dos_assert.h" +#include "byteorder.h" #include "network.h" #include "crypto.h" diff --git a/src/network/transportfragment.cc b/src/network/transportfragment.cc index 3a7be02..04a6884 100644 --- a/src/network/transportfragment.cc +++ b/src/network/transportfragment.cc @@ -16,9 +16,9 @@ along with this program. If not, see . */ -#include #include +#include "byteorder.h" #include "transportfragment.h" #include "transportinstruction.pb.h" #include "compressor.h"