diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-06-03 23:52:17 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-06-03 23:52:59 +0200 |
commit | a4a65093d1eab6f2f14c0d4657a364d8610f3ead (patch) | |
tree | c60c396887f003c9f4f0d1b2ff8232b513a553e8 | |
parent | c221087f91aa75bcc0a5c1b286d8a9eb652d24f3 (diff) | |
download | slirp-a4a65093d1eab6f2f14c0d4657a364d8610f3ead.zip slirp-a4a65093d1eab6f2f14c0d4657a364d8610f3ead.tar.gz slirp-a4a65093d1eab6f2f14c0d4657a364d8610f3ead.tar.bz2 |
ncsi: make ncsi_calculate_checksum work with unaligned data
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
-rw-r--r-- | src/ncsi.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -38,7 +38,7 @@ #include "ncsi-pkt.h" -static uint32_t ncsi_calculate_checksum(uint16_t *data, int len) +static uint32_t ncsi_calculate_checksum(uint8_t *data, int len) { uint32_t checksum = 0; int i; @@ -47,8 +47,8 @@ static uint32_t ncsi_calculate_checksum(uint16_t *data, int len) * 32-bit unsigned sum of the NC-SI packet header and NC-SI packet * payload interpreted as a series of 16-bit unsigned integer values. */ - for (i = 0; i < len / 2; i++) { - checksum += htons(data[i]); + for (i = 0; i < len; i += 2) { + checksum += (((uint16_t) data[i]) << 8) + data[i+1]; } checksum = (~checksum + 1); @@ -188,7 +188,7 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) } /* Add the optional checksum at the end of the frame. */ - checksum = ncsi_calculate_checksum((uint16_t *)rnh, ncsi_rsp_len); + checksum = ncsi_calculate_checksum((uint8_t *)rnh, ncsi_rsp_len); pchecksum = (uint32_t *)((void *)rnh + ncsi_rsp_len); *pchecksum = htonl(checksum); ncsi_rsp_len += 4; |