libosmogb: Convert to use new endian conversion helpers

Change-Id: I5ed17702cd9487e1cab6bae39802aa11fb6a37b0
diff --git a/src/gb/gprs_ns.c b/src/gb/gprs_ns.c
index 9a2a114..d0c5a17 100644
--- a/src/gb/gprs_ns.c
+++ b/src/gb/gprs_ns.c
@@ -71,6 +71,7 @@
 #include <arpa/inet.h>
 
 #include <osmocom/core/msgb.h>
+#include <osmocom/core/byteswap.h>
 #include <osmocom/gsm/tlv.h>
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/select.h>
@@ -404,8 +405,8 @@
 {
 	struct msgb *msg = gprs_ns_msgb_alloc();
 	struct gprs_ns_hdr *nsh;
-	uint16_t nsvci = htons(nsvc->nsvci);
-	uint16_t nsei = htons(nsvc->nsei);
+	uint16_t nsvci = osmo_htons(nsvc->nsvci);
+	uint16_t nsei = osmo_htons(nsvc->nsei);
 
 	log_set_context(LOG_CTX_GB_NSVC, nsvc);
 
@@ -437,11 +438,11 @@
 {
 	struct msgb *msg = gprs_ns_msgb_alloc();
 	struct gprs_ns_hdr *nsh;
-	uint16_t nsvci = htons(nsvc->nsvci);
+	uint16_t nsvci = osmo_htons(nsvc->nsvci);
 
 	log_set_context(LOG_CTX_GB_NSVC, nsvc);
 
-	bvci = htons(bvci);
+	bvci = osmo_htons(bvci);
 
 	if (!msg)
 		return -ENOMEM;
@@ -490,7 +491,7 @@
 {
 	struct msgb *msg = gprs_ns_msgb_alloc();
 	struct gprs_ns_hdr *nsh;
-	uint16_t nsvci = htons(nsvc->nsvci);
+	uint16_t nsvci = osmo_htons(nsvc->nsvci);
 
 	log_set_context(LOG_CTX_GB_NSVC, nsvc);
 
@@ -665,8 +666,8 @@
 	if (!msg)
 		return -ENOMEM;
 
-	nsvci = htons(nsvc->nsvci);
-	nsei = htons(nsvc->nsei);
+	nsvci = osmo_htons(nsvc->nsvci);
+	nsei = osmo_htons(nsvc->nsei);
 
 	msg->l2h = msgb_put(msg, sizeof(*nsh));
 	nsh = (struct gprs_ns_hdr *) msg->l2h;
@@ -849,8 +850,8 @@
 	}
 
 	cause = *(uint8_t  *) TLVP_VAL(&tp, NS_IE_CAUSE);
-	nsvci = ntohs(*(uint16_t *) TLVP_VAL(&tp, NS_IE_VCI));
-	nsei  = ntohs(*(uint16_t *) TLVP_VAL(&tp, NS_IE_NSEI));
+	nsvci = tlvp_val16be(&tp, NS_IE_VCI);
+	nsei  = tlvp_val16be(&tp, NS_IE_NSEI);
 
 	LOGP(DNS, LOGL_INFO, "NSVCI=%u%s Rx NS RESET (NSEI=%u, NSVCI=%u, cause=%s)\n",
 	     (*nsvc)->nsvci, (*nsvc)->nsvci_is_valid ? "" : "(invalid)",
@@ -957,8 +958,8 @@
 		return -EINVAL;
 	}
 
-	nsvci = ntohs(tlvp_val16_unal(&tp, NS_IE_VCI));
-	nsei  = ntohs(tlvp_val16_unal(&tp, NS_IE_NSEI));
+	nsvci = tlvp_val16be(&tp, NS_IE_VCI);
+	nsei  = tlvp_val16be(&tp, NS_IE_NSEI);
 
 	LOGP(DNS, LOGL_INFO, "NSVCI=%u%s Rx NS RESET ACK (NSEI=%u, NSVCI=%u)\n",
 	     (*nsvc)->nsvci, (*nsvc)->nsvci_is_valid ? "" : "(invalid)",
@@ -1145,7 +1146,7 @@
 	static char buf[80];
 	snprintf(buf, sizeof(buf), "%s:%u",
 		 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
-		 ntohs(nsvc->ip.bts_addr.sin_port));
+		 osmo_ntohs(nsvc->ip.bts_addr.sin_port));
 	buf[sizeof(buf) - 1] = '\0';
 
 	return buf;
@@ -1271,8 +1272,8 @@
 		CHECK_TX_RC(rc, fallback_nsvc);
 		return -EINVAL;
 	}
-	nsvci = ntohs(*(uint16_t *) TLVP_VAL(&tp, NS_IE_VCI));
-	nsei  = ntohs(*(uint16_t *) TLVP_VAL(&tp, NS_IE_NSEI));
+	nsvci = tlvp_val16be(&tp, NS_IE_VCI);
+	nsei  = tlvp_val16be(&tp, NS_IE_NSEI);
 	/* Check if we already know this NSVCI, the remote end might
 	 * simply have changed addresses, or it is a SGSN */
 	existing_nsvc = gprs_nsvc_by_nsvci(nsi, nsvci);
@@ -1554,7 +1555,7 @@
 	struct in_addr in;
 	int ret;
 
-	in.s_addr = htonl(nsi->nsip.local_ip);
+	in.s_addr = osmo_htonl(nsi->nsip.local_ip);
 
 	nsi->nsip.fd.cb = nsip_fd_cb;
 	nsi->nsip.fd.data = nsi;