ref: ada1920a0e4787d46402dcdc3e9f3ad3ddae7f0e
parent: 892008af7ca37124d61f3833f800675f6aa77f6b
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Sep 18 06:40:46 EDT 2022
devip: less stupid hnputs_csum()
--- a/sys/src/9/ip/ipaux.c
+++ b/sys/src/9/ip/ipaux.c
@@ -556,16 +556,17 @@
hnputs_csum(void *p, ushort v, uchar *pcsum)
{
ulong csum;
+ ushort o;
+ csum = nhgets(pcsum)^0xFFFF;
+ o = nhgets(p);
+ hnputs(p, v);
if(((uchar*)p - pcsum) & 1){
- hnputs_csum((uchar*)p-1, (nhgets((uchar*)p-1) & 0xFF00) | v>>8, pcsum);
- hnputs_csum((uchar*)p+1, (nhgets((uchar*)p+1) & 0x00FF) | v<<8, pcsum);
- return;
+ o = o << 8 | o >> 8;
+ v = v << 8 | v >> 8;
}
- csum = nhgets(pcsum)^0xFFFF;
- csum += nhgets(p)^0xFFFF;
+ csum += o ^ 0xFFFF;
csum += v;
- hnputs(p, v);
while(v = csum >> 16)
csum = (csum & 0xFFFF) + v;
hnputs(pcsum, csum^0xFFFF);