From f4a6f696b75bf079a05b89e21e58cd24d4230a7d Mon Sep 17 00:00:00 2001
From: Michael Tuexen <tuexen@fh-muenster.de>
Date: Sat, 23 Jun 2018 12:15:15 +0200
Subject: [PATCH] Fix endianess detection.

The names of the constants were wrong and the code wasn't dealing
with the case that none of the constants are defined, like in
the case on PowerPC for FreeBSD.
---
 gtests/net/packetdrill/gre.h                | 4 ++--
 gtests/net/packetdrill/ip.h                 | 4 ++--
 gtests/net/packetdrill/ipv6.h               | 4 ++--
 gtests/net/packetdrill/packet_socket_pcap.c | 4 ++--
 gtests/net/packetdrill/tcp.h                | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/gtests/net/packetdrill/gre.h b/gtests/net/packetdrill/gre.h
index 6ce627fd..87bea60b 100644
--- a/gtests/net/packetdrill/gre.h
+++ b/gtests/net/packetdrill/gre.h
@@ -35,7 +35,7 @@
 
 /* GRE header. See RFC 1701. */
 struct gre {
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
 	__u16	recursion_control:3,
 		strict_route:1,
 		has_seq:1,
@@ -45,7 +45,7 @@ struct gre {
 		version:3,
 		reserved:4,
 		ack:1;
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
 	__u16	has_checksum:1,
 		has_routing:1,
 		has_key:1,
diff --git a/gtests/net/packetdrill/ip.h b/gtests/net/packetdrill/ip.h
index c2bd926a..b9857935 100644
--- a/gtests/net/packetdrill/ip.h
+++ b/gtests/net/packetdrill/ip.h
@@ -30,10 +30,10 @@
 #include "types.h"
 
 struct ipv4 {
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
 	__u8	ihl:4,
 		version:4;
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
 	__u8	version:4,
 		ihl:4;
 #else
diff --git a/gtests/net/packetdrill/ipv6.h b/gtests/net/packetdrill/ipv6.h
index ae9d4724..34e9490d 100644
--- a/gtests/net/packetdrill/ipv6.h
+++ b/gtests/net/packetdrill/ipv6.h
@@ -32,13 +32,13 @@
 #include <netinet/in.h>
 
 struct ipv6 {
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
 	__u8			traffic_class_hi:4,
 				version:4;
 	__u8			flow_label_hi:4,
 				traffic_class_lo:4;
 	__u16			flow_label_lo;
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
 	__u8			version:4,
 				traffic_class_hi:4;
 	__u8			traffic_class_lo:4,
diff --git a/gtests/net/packetdrill/packet_socket_pcap.c b/gtests/net/packetdrill/packet_socket_pcap.c
index cdbba1fc..c349c700 100644
--- a/gtests/net/packetdrill/packet_socket_pcap.c
+++ b/gtests/net/packetdrill/packet_socket_pcap.c
@@ -311,9 +311,9 @@ int packet_socket_receive(struct packet_socket *psock,
 		}
 		break;
 	case DLT_RAW:
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
 		version = (*pkt_data & 0xf0) >> 4;
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
 		version = *pkt_data & 0x0f;
 #else
 #error "Please fix endianness defines"
diff --git a/gtests/net/packetdrill/tcp.h b/gtests/net/packetdrill/tcp.h
index 2c2b882a..779077a0 100644
--- a/gtests/net/packetdrill/tcp.h
+++ b/gtests/net/packetdrill/tcp.h
@@ -94,7 +94,7 @@ struct tcp {
 	__be16	dst_port;
 	__be32	seq;
 	__be32	ack_seq;
-#  if __BYTE_ORDER == __LITTLE_ENDIAN
+#  if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
 	__u16	res1:2,
 		res2:2,
 		doff:4,
@@ -106,7 +106,7 @@ struct tcp {
 		urg:1,
 		ece:1,
 		cwr:1;
-#  elif __BYTE_ORDER == __BIG_ENDIAN
+#  elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
 	__u16	doff:4,
 		res2:2,
 		res1:2,
-- 
GitLab