summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/grc_gruel.m41
-rw-r--r--configure.ac5
-rw-r--r--gruel/src/include/gruel/Makefile.am4
-rw-r--r--gruel/src/include/gruel/inet.h.in63
4 files changed, 72 insertions, 1 deletions
diff --git a/config/grc_gruel.m4 b/config/grc_gruel.m4
index 81f53ce13..0b0dc2c2b 100644
--- a/config/grc_gruel.m4
+++ b/config/grc_gruel.m4
@@ -37,6 +37,7 @@ AC_DEFUN([GRC_GRUEL],[
gruel/src/Makefile \
gruel/src/include/Makefile \
gruel/src/include/gruel/Makefile \
+ gruel/src/include/gruel/inet.h \
gruel/src/lib/Makefile \
])
diff --git a/configure.ac b/configure.ac
index f20ca9e4e..529d91e77 100644
--- a/configure.ac
+++ b/configure.ac
@@ -128,13 +128,16 @@ AC_CHECK_HEADERS(linux/ppdev.h dev/ppbus/ppi.h sys/mman.h sys/select.h sys/types
AC_CHECK_HEADERS(sys/resource.h stdint.h sched.h signal.h sys/syscall.h)
AC_CHECK_HEADERS(netinet/in.h)
AC_CHECK_HEADERS(windows.h)
+AC_CHECK_HEADER(byteswap.h, [GR_HAVE_BYTESWAP=1],[GR_HAVE_BYTESWAP=0])
+AC_SUBST(GR_HAVE_BYTESWAP)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_HEADER_TIME
-AC_C_BIGENDIAN
+AC_C_BIGENDIAN([GR_ARCH_BIGENDIAN=1],[GR_ARCH_BIGENDIAN=0])
+AC_SUBST(GR_ARCH_BIGENDIAN)
AC_STRUCT_TM
dnl Checks for library functions.
diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am
index 8ea484ced..e5970cc49 100644
--- a/gruel/src/include/gruel/Makefile.am
+++ b/gruel/src/include/gruel/Makefile.am
@@ -21,7 +21,11 @@
include $(top_srcdir)/Makefile.common
+BUILT_SOURCES = \
+ inet.h
+
gruelincludedir = $(prefix)/include/gruel
gruelinclude_HEADERS = \
+ $(BUILT_SOURCES) \
realtime.h
diff --git a/gruel/src/include/gruel/inet.h.in b/gruel/src/include/gruel/inet.h.in
new file mode 100644
index 000000000..dd0525708
--- /dev/null
+++ b/gruel/src/include/gruel/inet.h.in
@@ -0,0 +1,63 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INCLUDED_INET_H
+#define INCLUDED_INET_H
+
+#include <stdint.h>
+
+#if @GR_ARCH_BIGENDIAN@ /* GR_ARCH_BIGENDIAN */
+// Nothing to do...
+static inline uint32_t htonl(uint32_t x){ return x; }
+static inline uint16_t htons(uint16_t x){ return x; }
+static inline uint32_t ntohl(uint32_t x){ return x; }
+static inline uint16_t ntohs(uint16_t x){ return x; }
+#else
+#if @GR_HAVE_BYTESWAP@ /* GR_HAVE_BYTESWAP */
+#include <byteswap.h>
+#else
+#warning Using non-portable code (likely wrong other than ILP32).
+
+static inline unsigned short int
+bswap_16 (unsigned short int x)
+{
+ return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8));
+}
+
+static inline unsigned int
+bswap_32 (unsigned int x)
+{
+ return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \
+ | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24));
+}
+#endif /* GR_HAVE_BYTESWAP */
+
+static inline uint32_t htonl(uint32_t x){ return bswap_32(x); }
+static inline uint16_t htons(uint16_t x){ return bswap_16(x); }
+static inline uint32_t ntohl(uint32_t x){ return bswap_32(x); }
+static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); }
+#endif /* GR_ARCH_BIGENDIAN */
+
+static inline uint8_t ntohx(uint8_t x){ return x; }
+static inline uint16_t ntohx(uint16_t x){ return ntohs(x); }
+static inline uint32_t ntohx(uint32_t x){ return ntohl(x); }
+static inline uint8_t htonx(uint8_t x){ return x; }
+static inline uint16_t htonx(uint16_t x){ return htons(x); }
+static inline uint32_t htonx(uint32_t x){ return htonl(x); }
+
+#endif /* INCLUDED_INET_H */