use osmo_{htonl,htons,ntohl,ntohs}() functions all over libosmocore

This gets us one step closer to fixing the embedded build

Change-Id: I3fc2639b6ade9ab138766987eceab7ec9498fdc7
diff --git a/src/gsm/gsm0341.c b/src/gsm/gsm0341.c
index cc77382..1c14d3e 100644
--- a/src/gsm/gsm0341.c
+++ b/src/gsm/gsm0341.c
@@ -23,8 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <arpa/inet.h>
-
+#include <osmocom/core/byteswap.h>
 #include <osmocom/core/talloc.h>
 #include <osmocom/gsm/protocol/gsm_03_41.h>
 
@@ -36,7 +35,7 @@
 {
 	struct gsm341_ms_message *cbmsg;
 
-	msg_id = htons(msg_id);
+	msg_id = osmo_htons(msg_id);
 
 	if (len > 88)
 		return NULL;
diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c
index be58939..04c2f01 100644
--- a/src/gsm/gsm0808.c
+++ b/src/gsm/gsm0808.c
@@ -18,13 +18,12 @@
  *
  */
 
+#include <osmocom/core/byteswap.h>
 #include <osmocom/gsm/gsm0808.h>
 #include <osmocom/gsm/gsm0808_utils.h>
 #include <osmocom/gsm/protocol/gsm_08_08.h>
 #include <osmocom/gsm/gsm48.h>
 
-#include <arpa/inet.h>
-
 #define BSSMAP_MSG_SIZE 512
 #define BSSMAP_MSG_HEADROOM 128
 
@@ -51,7 +50,7 @@
 	/* create the cell header */
 	lai_ci.ident = CELL_IDENT_WHOLE_GLOBAL;
 	gsm48_generate_lai(&lai_ci.lai, cc, nc, lac);
-	lai_ci.ci = htons(_ci);
+	lai_ci.ci = osmo_htons(_ci);
 	msgb_tlv_put(msg, GSM0808_IE_CELL_IDENTIFIER, sizeof(lai_ci),
 		     (uint8_t *) &lai_ci);
 
@@ -266,7 +265,7 @@
 
 	/* Circuit Identity Code 3.2.2.2  */
 	if (cic) {
-		cic_sw = htons(*cic);
+		cic_sw = osmo_htons(*cic);
 		msgb_tv_fixed_put(msg, GSM0808_IE_CIRCUIT_IDENTITY_CODE,
 				  sizeof(cic_sw), (uint8_t *) & cic_sw);
 	}
@@ -282,7 +281,7 @@
 
 	/* AoIP: Call Identifier 3.2.2.105 */
 	if (ci) {
-		ci_sw = htonl(*ci);
+		ci_sw = osmo_htonl(*ci);
 		msgb_tv_fixed_put(msg, GSM0808_IE_CALL_ID, sizeof(ci_sw),
 				  (uint8_t *) & ci_sw);
 	}
@@ -433,7 +432,7 @@
 
 	/* TMSI 3.2.2.7 */
 	if (tmsi) {
-		tmsi_sw = htonl(*tmsi);
+		tmsi_sw = osmo_htonl(*tmsi);
 		msgb_tlv_put(msg, GSM0808_IE_TMSI, sizeof(*tmsi),
 			     (uint8_t *) & tmsi_sw);
 	}
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index b4bb878..2fa265a 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -20,10 +20,10 @@
 
 #include <osmocom/core/utils.h>
 #include <osmocom/core/msgb.h>
+#include <osmocom/core/byteswap.h>
 #include <string.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <arpa/inet.h>
 #include <errno.h>
 #include <osmocom/gsm/protocol/gsm_08_08.h>
 
@@ -58,13 +58,13 @@
 	switch (ss->ss_family) {
 	case AF_INET:
 		sin = (struct sockaddr_in *)ss;
-		port = ntohs(sin->sin_port);
+		port = osmo_ntohs(sin->sin_port);
 		ptr = msgb_put(msg, IP_V4_ADDR_LEN);
 		memcpy(ptr, &sin->sin_addr.s_addr, IP_V4_ADDR_LEN);
 		break;
 	case AF_INET6:
 		sin6 = (struct sockaddr_in6 *)ss;
-		port = ntohs(sin6->sin6_port);
+		port = osmo_ntohs(sin6->sin6_port);
 		ptr = msgb_put(msg, IP_V6_ADDR_LEN);
 		memcpy(ptr, sin6->sin6_addr.s6_addr, IP_V6_ADDR_LEN);
 		break;
diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c
index 757a855..543c9c0 100644
--- a/src/gsm/gsm48.c
+++ b/src/gsm/gsm48.c
@@ -26,9 +26,11 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdbool.h>
-#include <arpa/inet.h>
 
 #include <osmocom/core/utils.h>
+#include <osmocom/core/byteswap.h>
+#include <osmocom/core/bit16gen.h>
+#include <osmocom/core/bit32gen.h>
 #include <osmocom/gsm/tlv.h>
 #include <osmocom/gsm/gsm48.h>
 #include <osmocom/gsm/gsm0502.h>
@@ -479,7 +481,7 @@
 			uint16_t mnc, uint16_t lac)
 {
 	gsm48_mcc_mnc_to_bcd(&lai48->digits[0], mcc, mnc);
-	lai48->lac = htons(lac);
+	lai48->lac = osmo_htons(lac);
 }
 
 /* Attention: this function returns true integers, not hex! */
@@ -487,7 +489,7 @@
 		     uint16_t *mnc, uint16_t *lac)
 {
 	gsm48_mcc_mnc_from_bcd(&lai->digits[0], mcc, mnc);
-	*lac = ntohs(lai->lac);
+	*lac = osmo_ntohs(lai->lac);
 	return 0;
 }
 
@@ -537,7 +539,7 @@
 
 int gsm48_generate_mid_from_tmsi(uint8_t *buf, uint32_t tmsi)
 {
-	uint32_t tmsi_be = htonl(tmsi);
+	uint32_t tmsi_be = osmo_htonl(tmsi);
 
 	buf[0] = GSM48_IE_MOBILE_ID;
 	buf[1] = GSM48_TMSI_LEN;
@@ -593,8 +595,7 @@
 	case GSM_MI_TYPE_TMSI:
 		/* Table 10.5.4.3, reverse generate_mid_from_tmsi */
 		if (mi_len == GSM48_TMSI_LEN && mi[0] == (0xf0 | GSM_MI_TYPE_TMSI)) {
-			memcpy(&tmsi, &mi[1], 4);
-			tmsi = ntohl(tmsi);
+			tmsi = osmo_load32be(&mi[1]);
 			return snprintf(string, str_len, "%u", tmsi);
 		}
 		break;
@@ -637,7 +638,7 @@
 		raid->mnc += (buf[1] >> 4) * 1;
 	}
 
-	raid->lac = ntohs(*(uint16_t *)(buf + 3));
+	raid->lac = osmo_load16be(buf + 3);
 	raid->rac = buf[5];
 }
 
@@ -660,7 +661,7 @@
 		buf[2] = ((mnc / 100) % 10) | (((mnc / 10) % 10) << 4);
 	}
 
-	_lac = htons(raid->lac);
+	_lac = osmo_htons(raid->lac);
 	memcpy(buf + 3, &_lac, 2);
 
 	buf[5] = raid->rac;
diff --git a/src/gsm/ipa.c b/src/gsm/ipa.c
index 2c0880a..90cf0eb 100644
--- a/src/gsm/ipa.c
+++ b/src/gsm/ipa.c
@@ -26,10 +26,10 @@
 #include <errno.h>
 #include <stdlib.h>
 
-#include <arpa/inet.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 
+#include <osmocom/core/byteswap.h>
 #include <osmocom/core/msgb.h>
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/logging.h>
@@ -431,7 +431,7 @@
 
 	/* prepend the ip.access header */
 	hh = (struct ipaccess_head *) msgb_push(msg, sizeof(*hh));
-	hh->len = htons(msg->len - sizeof(*hh));
+	hh->len = osmo_htons(msg->len - sizeof(*hh));
 	hh->proto = proto;
 }
 
@@ -502,7 +502,7 @@
 	hh = (struct ipaccess_head *) msg->data;
 
 	/* then read the length as specified in header */
-	len = ntohs(hh->len);
+	len = osmo_ntohs(hh->len);
 
 	if (len < 0 || IPA_ALLOC_SIZE < len + sizeof(*hh)) {
 		LOGP(DLINP, LOGL_ERROR, "bad message length of %d bytes, "
diff --git a/src/gsm/lapd_core.c b/src/gsm/lapd_core.c
index c81b2a0..310df65 100644
--- a/src/gsm/lapd_core.c
+++ b/src/gsm/lapd_core.c
@@ -74,7 +74,6 @@
 #include <stdint.h>
 #include <string.h>
 #include <errno.h>
-#include <arpa/inet.h>
 
 #include <osmocom/core/logging.h>
 #include <osmocom/core/timer.h>
diff --git a/src/gsm/lapdm.c b/src/gsm/lapdm.c
index 1fdf311..99099d1 100644
--- a/src/gsm/lapdm.c
+++ b/src/gsm/lapdm.c
@@ -31,7 +31,6 @@
 #include <stdint.h>
 #include <string.h>
 #include <errno.h>
-#include <arpa/inet.h>
 
 #include <osmocom/core/logging.h>
 #include <osmocom/core/timer.h>