Use endian.h naming instead of inet.h

Make it explicit that network order is big endian and that short, long
and long long are 16, 32 and 64-bit values, respectively.

Change-Id: I52f23e43d16111852dc691a3e7d89659e0ada233
diff --git a/inc/std.h b/inc/std.h
index d2438a2..caed9dd 100644
--- a/inc/std.h
+++ b/inc/std.h
@@ -12,12 +12,12 @@
 size_t strlen(const char *str);
 int strcmp(const char *a, const char *b);
 
-static inline uint16_t ntohs(uint16_t v)
+static inline uint16_t be16toh(uint16_t v)
 {
 	return v << 8 | v >> 8;
 }
 
-static inline uint32_t ntohl(uint32_t v)
+static inline uint32_t be32toh(uint32_t v)
 {
 	/* TODO: no conversion needed if native is big endian. */
 	return (v << 24) |
@@ -26,7 +26,7 @@
 	       ((v & 0xff0000) >> 8);
 }
 
-static inline uint64_t ntohll(uint64_t v)
+static inline uint64_t be64toh(uint64_t v)
 {
 	/* TODO: no conversion needed if native is big endian. */
 	return (v << 56) |
@@ -39,14 +39,14 @@
 	       ((v & 0xff00000000) >> 8);
 }
 
-static inline uint32_t htonl(uint32_t v)
+static inline uint32_t htobe32(uint32_t v)
 {
-	return ntohl(v);
+	return be32toh(v);
 }
 
-static inline uint64_t htonll(uint64_t v)
+static inline uint64_t htobe64(uint64_t v)
 {
-	return ntohll(v);
+	return be64toh(v);
 }
 
 #endif  /* STD_H */
diff --git a/src/fdt.c b/src/fdt.c
index da26178..d5b1e16 100644
--- a/src/fdt.c
+++ b/src/fdt.c
@@ -59,7 +59,7 @@
 	if (next > t->end)
 		return false;
 
-	*res = ntohl(*(uint32_t *)t->cur);
+	*res = be32toh(*(uint32_t *)t->cur);
 	t->cur = next;
 
 	return true;
@@ -112,18 +112,18 @@
 {
 	uint32_t max_ver;
 	uint32_t min_ver;
-	uint32_t begin = ntohl(hdr->off_dt_struct);
-	uint32_t size = ntohl(hdr->size_dt_struct);
+	uint32_t begin = be32toh(hdr->off_dt_struct);
+	uint32_t size = be32toh(hdr->size_dt_struct);
 
 	memset(node, 0, sizeof(*node));
 
 	/* Check the magic number before anything else. */
-	if (hdr->magic != ntohl(FDT_MAGIC))
+	if (hdr->magic != be32toh(FDT_MAGIC))
 		return;
 
 	/* Check the version. */
-	max_ver = ntohl(hdr->version);
-	min_ver = ntohl(hdr->last_comp_version);
+	max_ver = be32toh(hdr->version);
+	min_ver = be32toh(hdr->last_comp_version);
 	if (FDT_VERSION < min_ver || FDT_VERSION > max_ver)
 		return;
 
@@ -132,7 +132,7 @@
 	node->end = node->begin + size;
 
 	/* TODO: Verify strings as well. */
-	node->strs = (char *)hdr + ntohl(hdr->off_dt_strings);
+	node->strs = (char *)hdr + be32toh(hdr->off_dt_strings);
 }
 
 static bool fdt_next_property(struct fdt_tokenizer *t, const char **name,
@@ -336,11 +336,11 @@
 		depth--;
 	} while (depth);
 
-	dlog("fdt: off_mem_rsvmap=%u\n", ntohl(hdr->off_mem_rsvmap));
+	dlog("fdt: off_mem_rsvmap=%u\n", be32toh(hdr->off_mem_rsvmap));
 	{
-		struct fdt_reserve_entry *e = (struct fdt_reserve_entry *)((size_t)hdr + ntohl(hdr->off_mem_rsvmap));
+		struct fdt_reserve_entry *e = (struct fdt_reserve_entry *)((size_t)hdr + be32toh(hdr->off_mem_rsvmap));
 		while (e->address || e->size) {
-			dlog("Entry: %p (0x%x bytes)\n", ntohll(e->address), ntohll(e->size));
+			dlog("Entry: %p (0x%x bytes)\n", be64toh(e->address), be64toh(e->size));
 			e++;
 		}
 	}
@@ -349,12 +349,12 @@
 void fdt_add_mem_reservation(struct fdt_header *hdr, size_t addr, size_t len)
 {
 	/* TODO: Clean this up. */
-	char *begin = (char *)hdr + ntohl(hdr->off_mem_rsvmap);
+	char *begin = (char *)hdr + be32toh(hdr->off_mem_rsvmap);
 	struct fdt_reserve_entry *e = (struct fdt_reserve_entry *)begin;
-	hdr->totalsize = htonl(ntohl(hdr->totalsize) + sizeof(struct fdt_reserve_entry));
-	hdr->off_dt_struct = htonl(ntohl(hdr->off_dt_struct) + sizeof(struct fdt_reserve_entry));
-	hdr->off_dt_strings = htonl(ntohl(hdr->off_dt_strings) + sizeof(struct fdt_reserve_entry));
-	memmove(begin + sizeof(struct fdt_reserve_entry), begin, ntohl(hdr->totalsize) - ntohl(hdr->off_mem_rsvmap));
-	e->address = htonll(addr);
-	e->size = htonll(len);
+	hdr->totalsize = htobe32(be32toh(hdr->totalsize) + sizeof(struct fdt_reserve_entry));
+	hdr->off_dt_struct = htobe32(be32toh(hdr->off_dt_struct) + sizeof(struct fdt_reserve_entry));
+	hdr->off_dt_strings = htobe32(be32toh(hdr->off_dt_strings) + sizeof(struct fdt_reserve_entry));
+	memmove(begin + sizeof(struct fdt_reserve_entry), begin, be32toh(hdr->totalsize) - be32toh(hdr->off_mem_rsvmap));
+	e->address = htobe64(addr);
+	e->size = htobe64(len);
 }
diff --git a/src/main.c b/src/main.c
index 946dceb..d5c2c22 100644
--- a/src/main.c
+++ b/src/main.c
@@ -31,10 +31,10 @@
 
 	switch (size) {
 	case sizeof(uint32_t):
-		return ntohl(*(uint32_t *)data);
+		return be32toh(*(uint32_t *)data);
 	case sizeof(uint64_t):
 		memcpy(t.a, data, sizeof(uint64_t));
-		return ntohll(t.v);
+		return be64toh(t.v);
 	default:
 		return 0;
 	}
@@ -76,11 +76,11 @@
 
 	switch (size) {
 	case sizeof(uint32_t):
-		*(uint32_t *)data = ntohl(value);
+		*(uint32_t *)data = be32toh(value);
 		break;
 
 	case sizeof(uint64_t):
-		t.v = ntohll(value);
+		t.v = be64toh(value);
 		memcpy((void *)data, t.a, sizeof(uint64_t));
 		break;