Merge pull request #2975 from cesanta/ipsum

Fix IP csum calculation on 8-bit platforms
This commit is contained in:
Sergio R. Caprile 2024-11-26 17:36:43 -03:00 committed by GitHub
commit 74f77c9ded
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View File

@ -4216,7 +4216,7 @@ static void mkpay(struct pkt *pkt, void *p) {
static uint32_t csumup(uint32_t sum, const void *buf, size_t len) {
size_t i;
const uint8_t *p = (const uint8_t *) buf;
for (i = 0; i < len; i++) sum += i & 1 ? p[i] : (uint32_t) (p[i] << 8);
for (i = 0; i < len; i++) sum += i & 1 ? p[i] : ((uint32_t) p[i]) << 8;
return sum;
}

View File

@ -152,7 +152,7 @@ static void mkpay(struct pkt *pkt, void *p) {
static uint32_t csumup(uint32_t sum, const void *buf, size_t len) {
size_t i;
const uint8_t *p = (const uint8_t *) buf;
for (i = 0; i < len; i++) sum += i & 1 ? p[i] : (uint32_t) (p[i] << 8);
for (i = 0; i < len; i++) sum += i & 1 ? p[i] : ((uint32_t) p[i]) << 8;
return sum;
}