diff options
author | Dan Williams <dcbw@redhat.com> | 2010-03-31 20:24:12 -0700 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2010-03-31 20:24:12 -0700 |
commit | f39afdd5f7c5d6ed56dd7a00ddb13de12dcda5b8 (patch) | |
tree | 740c047f417ff1463d068cbbeb3c4237e4607523 /libqcdm/src/utils.c | |
parent | 4d89b519b4c889859a84780a18dbb2f12c9a9438 (diff) |
qcdm: fix endian issues for BE platforms
And add a testcase for packet encapsulation to ensure we don't
have further endian issues in the future.
Diffstat (limited to 'libqcdm/src/utils.c')
-rw-r--r-- | libqcdm/src/utils.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/libqcdm/src/utils.c b/libqcdm/src/utils.c index 9b9ac5f0..b5815482 100644 --- a/libqcdm/src/utils.c +++ b/libqcdm/src/utils.c @@ -194,7 +194,8 @@ dm_encapsulate_buffer (char *inbuf, g_return_val_if_fail (inbuf_len >= cmd_len + 2, 0); /* space for CRC */ g_return_val_if_fail (outbuf != NULL, 0); - crc = GUINT16_TO_LE (crc16 (inbuf, cmd_len)); + /* Add the CRC */ + crc = crc16 (inbuf, cmd_len); inbuf[cmd_len++] = crc & 0xFF; inbuf[cmd_len++] = (crc >> 8) & 0xFF; @@ -296,8 +297,9 @@ dm_decapsulate_buffer (const char *inbuf, /* Check the CRC of the packet's data */ crc = crc16 (outbuf, unesc_len - 2); - pkt_crc = *((guint16 *) &outbuf[unesc_len - 2]); - if (crc != GUINT_FROM_LE (pkt_crc)) { + pkt_crc = outbuf[unesc_len - 2] & 0xFF; + pkt_crc |= (outbuf[unesc_len - 1] & 0xFF) << 8; + if (crc != pkt_crc) { *out_used = pkt_len + 1; /* packet + CRC + 0x7E */ return FALSE; } |