• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

RFC1141 - Incremental updating of the Internet checksum

发布: 2007-6-23 14:09 | 作者:   | 来源:   | 查看: 22次 | 进入软件测试论坛讨论

领测软件测试网

   
  Network Working Group T. Mallory
Request for Comments: 1141 A. Kullberg
Obsoletes: RFC1071 BBN Communications
January 1990

Incremental Updating of the Internet Checksum

Status of this Memo

This memo correctly describes the incremental update procedure for
use with the standard Internet checksum. It is intended to replace
the description of Incremental Update in RFC1071. This is not a
standard but rather, an implementation technique. Distribution of
this memo is unlimited.

Description

In RFC1071 on pages 4 and 5, there is a description of a method to
update the IP checksum in the IP header without having to completely
recompute the checksum. In particular, the RFCrecommends the
following equation for computing the update checksum C' from the
original checksum C, and the old and new values of byte m:

C' = C + (-m) + m' = C + (m' - m)

While the equation above is correct, it is not very useful for
incremental updates since the equation above updates the checksum C,
rather than the 1's complement of the checksum, ~C, which is the
value stored in the checksum field. In addition, it suffers because
the notation does not clearly specify that all arithmetic, including
the unary negation, must be performed one's complement, and so is
difficult to use to build working code. The useful calculation for
2's complement machines is:

~C' = ~(C + (-m) + m') = ~C + (m - m') = ~C + m + ~m'

In the oft-mentioned case of updating the IP TTL field, subtracting
one from the TTL means ADDING 1 or 256 as appropriate to the checksum
field in the packet, using one's complement addition. One big-endian
non-portable implementation in C looks like:

unsigned long sum;
ipptr->ttl--; /* decrement ttl */
sum = ipptr->Checksum + 0x100; /* increment checksum high byte*/
ipptr->Checksum = (sum + (sum>>16)) /* add carry */

This special case can be optimized in many ways: for instance, you

can bundle updating and checking the ttl. Compiler mileage may vary.
Here is a more general and possibly more helpful example which
updates the ttl by n seconds:

UpdateTTL(iph,n)
struct ip_hdr *ipptr;
unsigned char n;
{
unsigned long sum;
unsigned short old;

old = ntohs(*(unsigned short *)&ipptr->ttl);
ipptr->ttl -= n;
sum = old + (~ntohs(*(unsigned short *)&ipptr->ttl) & 0xffff);
sum += ntohs(ipptr->Checksum);
sum = (sum & 0xffff) + (sum>>16);
ipptr->Checksum = htons(sum + (sum>>16));
}

Security Considerations

Security issues are not addressed in this memo.

Authors' Addresses

Tracy Mallory
BBN Communications Corporation
50 Moulton Street
Cambridge, MA 02238

Phone: (617) 873-3193

EMail: tmallory@CCV.BBN.COM

A. Kullberg
BBN Communications Corporation
50 Moulton Street
Cambridge, MA 02238

Phone: (617) 873-4000

EMail: akullberg@BBN.COM

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网