csum_partial() feeds more uint16_t words into the checksummer;
csum_finish() does the final condensation down to uint16_t, and
conversion to network order.
[dwmw2: Note this still doesn't cope with odd-sized packets but
we don't care for now.]
Signed-off-by: Daniel Lenski <dlenski@gmail.com>
}
#ifdef HAVE_ESP
-static uint16_t csum(uint16_t *buf, int nwords)
+static inline uint32_t csum_partial(uint16_t *buf, int nwords)
{
uint32_t sum = 0;
for(sum=0; nwords>0; nwords--)
sum += ntohs(*buf++);
+ return sum;
+}
+
+static inline uint16_t csum_finish(uint32_t sum)
+{
sum = (sum >> 16) + (sum &0xffff);
sum += (sum >> 16);
return htons((uint16_t)(~sum));
}
+static inline uint16_t csum(uint16_t *buf, int nwords)
+{
+ return csum_finish(csum_partial(buf, nwords));
+}
+
static char magic_ping_payload[16] = "monitor\x00\x00pan ha ";
int gpst_esp_send_probes(struct openconnect_info *vpninfo)