#if defined(VMS)
#include <socket.h>
typedef unsigned int u_int;
-/*
- * Note: VMS DECC has long == int (even on __alpha),
- * so the distinction below doesn't matter
- */
#endif /* VMS */
-#if (SIZEOF_INT == 4)
-# ifndef int32
-# define int32 int
+#ifdef HAVE_UINT32_T
+# ifndef HAVE_INT32
+ typedef int32_t int32;
- # define INT32_MIN INT32_T_MIN
- # define INT32_MAX INT32_T_MAX
+ # ifndef INT32_MIN
-# define INT32_MIN INT_MIN
++# define INT32_MIN INT32_T_MIN
+ # endif
+ # ifndef INT32_MAX
-# define INT32_MAX INT_MAX
++# define INT32_MAX INT32_T_MAX
+ # endif
# endif
-# ifndef u_int32
-# define u_int32 unsigned int
+# ifndef HAVE_U_INT32
+ typedef uint32_t u_int32;
+# define U_INT32_MAX UINT32_T_MAX
+# endif
+#elif (SIZEOF_INT == 4)
+# if !defined(HAVE_INT32) && !defined(int32)
+ typedef int int32;
+# define INT32_MIN INT_MIN
+# define INT32_MAX INT_MAX
+# endif
+# if !defined(HAVE_U_INT32) && !defined(u_int32)
+ typedef unsigned u_int32;
- # define U_INT32_MAX UINT_MAX
+ # ifndef U_INT32_MAX
+ # define U_INT32_MAX UINT_MAX
+ # endif
# endif
-#else /* not sizeof(int) == 4 */
+#else /* SIZEOF_INT != 4 */
# if (SIZEOF_LONG == 4)
-# ifndef int32
-# define int32 long
+# if !defined(HAVE_INT32) && !defined(int32)
+ typedef long int32;
- # define INT32_MIN LONG_MIN
- # define INT32_MAX LONG_MAX
+ # ifndef INT32_MIN
+ # define INT32_MIN LONG_MIN
+ # endif
+ # ifndef INT32_MAX
+ # define INT32_MAX LONG_MAX
+ # endif
# endif
-# ifndef u_int32
-# define u_int32 unsigned long
+# if !defined(HAVE_U_INT32) && !defined(u_int32)
+ typedef unsigned long u_int32;
- # define U_INT32_MAX ULONG_MAX
+ # ifndef U_INT32_MAX
+ # define U_INT32_MAX ULONG_MAX
+ # endif
# endif
-# else /* not sizeof(long) == 4 */
+# else /* SIZEOF_LONG != 4 */
# include "Bletch: what's 32 bits on this machine?"
-# endif /* not sizeof(long) == 4 */
-#endif /* not sizeof(int) == 4 */
+# endif
+#endif /* !HAVE_UINT32_T && SIZEOF_INT != 4 */
+
+#ifndef UINT32_MAX
+#define UINT32_MAX 0xffffffff
+#endif
+
+
+/*
+ * Ugly dance to find out if we have 64bit integer type.
+ */
+#if !defined(HAVE_INT64)
+
+/* assume best for now, fix if frustrated later. */
+# define HAVE_INT64
+# define HAVE_U_INT64
+
+/* now check the cascade. Feel free to add things. */
+# ifdef INT64_MAX
+
+typedef int64_t int64;
+typedef uint64_t u_int64;
+
+# elif SIZEOF_LONG == 8
+
+typedef long int64;
+typedef unsigned long u_int64;
+
+# elif SIZEOF_LONG_LONG == 8
+
+typedef long long int64;
+typedef unsigned long long u_int64;
+
+# else
+
+/* no 64bit scalar, give it up. */
+# undef HAVE_INT64
+# undef HAVE_U_INT64
+
+# endif
+
+#endif
+
+/*
+ * and here the trouble starts: We need a representation with more than
+ * 64 bits. If a scalar of that size is not available, we need a struct
+ * that holds the value in split representation.
+ *
+ * To ease the usage a bit, we alwys use a union that is in processor
+ * byte order and might or might not contain a 64bit scalar.
+ */
+
+#if SIZEOF_SHORT != 2
+# error short is not 2 bytes -- what is 16 bit integer on this target?
+#endif
+
+typedef union {
+# ifdef WORDS_BIGENDIAN
+ struct {
+ short hh; u_short hl; u_short lh; u_short ll;
+ } w_s;
+ struct {
+ u_short hh; u_short hl; u_short lh; u_short ll;
+ } W_s;
+ struct {
+ int32 hi; u_int32 lo;
+ } d_s;
+ struct {
+ u_int32 hi; u_int32 lo;
+ } D_s;
+# else
+ struct {
+ u_short ll; u_short lh; u_short hl; short hh;
+ } w_s;
+ struct {
+ u_short ll; u_short lh; u_short hl; u_short hh;
+ } W_s;
+ struct {
+ u_int32 lo; int32 hi;
+ } d_s;
+ struct {
+ u_int32 lo; u_int32 hi;
+ } D_s;
+# endif
+
+# ifdef HAVE_INT64
+ int64 q_s; /* signed quad scalar */
+ u_int64 Q_s; /* unsigned quad scalar */
+# endif
+} vint64; /* variant int 64 */
+
typedef u_char ntp_u_int8_t;
typedef u_short ntp_u_int16_t;