Harald Welte has submitted this change and it was merged.

Change subject: use osmo_{htonl,htons,ntohl,ntohs}() functions all over 
libosmocore
......................................................................


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

This gets us one step closer to fixing the embedded build

Change-Id: I3fc2639b6ade9ab138766987eceab7ec9498fdc7
---
M src/gsm/gsm0341.c
M src/gsm/gsm0808.c
M src/gsm/gsm0808_utils.c
M src/gsm/gsm48.c
M src/gsm/ipa.c
M src/gsm/lapd_core.c
M src/gsm/lapdm.c
M src/gsmtap_util.c
M src/logging_gsmtap.c
M src/stats.c
10 files changed, 31 insertions(+), 34 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



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,12 +18,11 @@
  *
  */
 
+#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>
diff --git a/src/gsmtap_util.c b/src/gsmtap_util.c
index ab4a28e..74f3b48 100644
--- a/src/gsmtap_util.c
+++ b/src/gsmtap_util.c
@@ -29,12 +29,11 @@
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/select.h>
 #include <osmocom/core/socket.h>
+#include <osmocom/core/byteswap.h>
 #include <osmocom/gsm/protocol/gsm_04_08.h>
 #include <osmocom/gsm/rsl.h>
 
 #include <sys/types.h>
-
-#include <arpa/inet.h>
 
 #include <stdio.h>
 #include <unistd.h>
@@ -123,10 +122,10 @@
        gh->type = type;
        gh->timeslot = ts;
        gh->sub_slot = ss;
-       gh->arfcn = htons(arfcn);
+       gh->arfcn = osmo_htons(arfcn);
        gh->snr_db = snr;
        gh->signal_dbm = signal_dbm;
-       gh->frame_number = htonl(fn);
+       gh->frame_number = osmo_htonl(fn);
        gh->sub_type = chan_type;
        gh->antenna_nr = 0;
 
diff --git a/src/logging_gsmtap.c b/src/logging_gsmtap.c
index 85f8c28..f37f8e7 100644
--- a/src/logging_gsmtap.c
+++ b/src/logging_gsmtap.c
@@ -32,7 +32,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdbool.h>
-#include <arpa/inet.h>
 
 #ifdef HAVE_STRINGS_H
 #include <strings.h>
@@ -44,6 +43,7 @@
 #include <osmocom/core/gsmtap_util.h>
 #include <osmocom/core/logging.h>
 #include <osmocom/core/timer.h>
+#include <osmocom/core/byteswap.h>
 
 #define        GSMTAP_LOG_MAX_SIZE 4096
 
@@ -81,12 +81,12 @@
        else
                golh->subsys[0] = '\0';
        osmo_strlcpy(golh->src_file.name, file, sizeof(golh->src_file.name));
-       golh->src_file.line_nr = htonl(line);
+       golh->src_file.line_nr = osmo_htonl(line);
        golh->level = level;
        /* we always store the timestamp in the message, irrespective
         * of hat prrint_[ext_]timestamp say */
-       golh->ts.sec = htonl(tv.tv_sec);
-       golh->ts.usec = htonl(tv.tv_usec);
+       golh->ts.sec = osmo_htonl(tv.tv_sec);
+       golh->ts.usec = osmo_htonl(tv.tv_usec);
 
        rc = vsnprintf((char *) msg->tail, msgb_tailroom(msg), format, ap);
        if (rc < 0)
diff --git a/src/stats.c b/src/stats.c
index dee5d81..9c826cc 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -21,6 +21,7 @@
  *
  */
 
+#include <osmocom/core/byteswap.h>
 #include <osmocom/core/stats.h>
 
 #include <unistd.h>
@@ -195,7 +196,7 @@
                return -ENOTSUP;
 
        srep->dest_port = port;
-       sock_addr->sin_port = htons(port);
+       sock_addr->sin_port = osmo_htons(port);
 
        return update_srep_config(srep);
 }

-- 
To view, visit https://gerrit.osmocom.org/2624
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3fc2639b6ade9ab138766987eceab7ec9498fdc7
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder

Reply via email to