Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
InetStruct.cpp
Package: SwordOnline.rar [view]
Upload User: dzyhzl
Upload Date: 2019-04-29
Package Size: 56270k
Code Size: 1k
Category:
Game Server Simulator
Development Platform:
C/C++
- ////////////////////////////////////////////////////////////////////////////////
- //
- // FileName : InetStruct.h
- // Version : 1.0
- // Creater : Linsuyi
- // Date : 2002-01-09 15:50:32
- // Comment : Internet structure used tcp/ip, source file (from RFC)
- //
- ////////////////////////////////////////////////////////////////////////////////
- #include "Stdafx.h"
- #include "InetStruct.h"
- unsigned short inet_chksum(unsigned short *data, int len)
- {
- register int nleft = len;
- register int sum = 0;
- register unsigned short *w = data;
- register unsigned short answer;
- /*
- * Our algorithm is simple, using a 32 bit accumulator (sum),
- * we add sequential 16 bit words to it, and at the end, fold
- * back all the carry bits from the top 16 bits into the lower
- * 16 bits.
- */
- while (nleft > 1)
- {
- sum += *w++;
- nleft -= 2;
- }
- /* mop up an odd byte, if necessary */
- if (nleft == 1)
- {
- unsigned short u = 0;
- *(unsigned char *)(&u) = *(unsigned char *)w ;
- sum += u;
- }
- /*
- * add back carry outs from top 16 bits to low 16 bits
- */
- sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
- sum += (sum >> 16); /* add carry */
- answer = ~sum; /* truncate to 16 bits */
- return (answer);
- }