📄 sum_xa.c
字号:
/* sum_xa.c
Copyright 2000 by InterNIche Technologies Inc. All rights reserved.
Copyright 1990-1996 by NetPort Software.
*/
#include "ipport.h"
/* cksum(buf, len) performs an Internet type checksum. buf points to where
the checksumming should begin, len is the number of 16 bit words
to be summed.
This version for philips XA CPUs in 16 bit mode
*/
//#pragma optimize 1
#pragma O0
/*typedef union {
unsigned long m_long;
struct {
unsigned int lint;
unsigned int hint;
} m_int;
} LONG_UNION;
*/
typedef union{
unsigned int m_long;
struct{
unsigned short lint;
unsigned short hint;
}m_int;
}LONG_UNION;
unsigned short cksum(void* buf, unsigned short word_count)
{
LONG_UNION sum;
unsigned short *ptr;
ptr = (unsigned short *)buf;
sum.m_long = 0;
for (; word_count > 0; word_count--) {
sum.m_long += *ptr++;
if (sum.m_int.hint > 0) {
sum.m_int.lint += sum.m_int.hint;
sum.m_int.hint = 0;
}
}
return sum.m_int.lint;
}
//#pragma endoptimize
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -