青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

小默

【轉(zhuǎn)】IP checksum definition

IP checksum definition

The IP checksum is the 16 bit one's complement of the one's complement sum of all 16 bit words in the header.

One question many people may ask is "What is the 1's complement sum ?". This is because all computers utilize the 2's complement representation and the 1's complement is not used. The following gives a short introduction.

2's complement fixed point integers (8-bit)

BinaryDecimalHex
0000 0000000
0000 0001101
0000 0010202
0000 0011303
1111 1111-1FF
1111 1110-2FE
1111 1101-3FD

Let's add two intergers: 
-3 + 5 = 2 
FD + 05 = 01 02
Discarding the carry (01) gives the correct result.

1's complement fixed point integers (8-bit)

BinaryDecimalHex
0000 0000000
0000 0001101
0000 0010202
0000 0011303
1111 1111-0FF
1111 1110-1FE
1111 1101-2FD
1111 1100-3FC

Add the same numbers: 
-3 + 5 = 2
FC + 05 = 01 01
Adding the carry (01) to the LSB (01) gives the correct result:
01 + 01 = 02

So, the 1's complement sum is done by summing the numbers and adding the carry (or carries) to the result..

Simple Internet checksum example

Suppose we have an 8-bit, 2's complement, machine and send the packet

FE 05 00

where 00 is the checksum field.

Let's calculate and verify the Internet checksum.

 FE + 05  =  01 03

This is the result of the normal (2's complement) addition. The 1's complement sum requires the addition of the carry to the 8-bit word (even though we will not get the same result)

 03 + 01 = 04  

so the 1's complement sum of FE + 05 is 04.

The 1's complement of the 1's complement sum (Internet checksum) will be 

~04  = FB

and the packet will be sent as

FE 05 FB 

Now, at the receiving end we add all the received bytes, including the checksum (again using the 2's complement representation)

FE + 05 + FB  = 01 FE  

The 1's complement sum is  

 FE + 01 = FF = -0  

which checks that the transmission was OK (see below).

A more complex example (32-bit machine)

As shown in RFC 1071, the checksum calculation is done in the following way:

(1) Adjacent octets to be checksummed are paired to form 16-bit integers, and the 1's complement sum of these 16-bit integers is formed.

(2) To generate a checksum, the checksum field itself is cleared, the 16-bit 1's complement sum is computed over the octets concerned, and the 1's complement of this sum is placed in the checksum field.

(3) To check a checksum, the 1's complement sum is computed over the same set of octets, including the checksum field. If the result is all 1 bits (-0 in 1's complement arithmetic), the check succeeds.

Packet

01 00 F2 03 F4 F5 F6 F7 00 00

(00 00 is the checksum field)

Form the 16-bit words

0100 F203 F4F5 F6F7

Calculate 2's complement sum

0100 + F203 + F4F5 + F6F7 = 0002 DEEF (store the sum in a 32-bit word)

Add the carries (0002) to get the 16-bit 1's complement sum

DEEF + 002 = DEF1

Calculate 1's complement of the 1's complement sum

~DEF1 = 210E

We send the packet including the checksum 21 0E

01 00 F2 03 F4 F5 F6 F7 21 0E

At the receiving

0100 + F203 + F4F5 + F6F7 + 210E = 0002 FFFD
FFFD + 0002 = FFFF

which checks OK.

Comments
It may look awkword to use a 1's complement addition on 2's complement machines. This method however has its own benefits.

Probably the most important is that it is endian independent. Little Endian computers store hex numbers with the LSB last (Intel processors for example). Big Endian computers put the LSB first (IBM mainframes for example). When carry is added to the LSB to form the 1's complement sum (see the example) it doesn't matter if we add 03 + 01 or 01 + 03. The result is the same.

Other benefits include the easiness of checking the transmission and the checksum calculation plus a variety of ways to speed up the calculation by updating only IP fields that have changed.


The IP Header Checksum is computed on the header fields only. 
Before starting the calculation, the checksum fields (octets 11 and 12) 
are made equal to zero. 

In the example code, 
u16 buff[] is an array containing all octets in the header with octets 11 and 12 equal to zero. 
u16 len_ip_header is the length (number of octets) of the header.


/*
**************************************************************************
Function: ip_sum_calc
Description: Calculate the 16 bit IP sum.
***************************************************************************
*/
typedef unsigned short u16;
typedef unsigned long u32;

u16 ip_sum_calc(u16 len_ip_header, u16 buff[])
{
        u16 word16;
        u32 sum=0;
        u16 i;
    
        // make 16 bit words out of every two adjacent 8 bit words in the packet
        // and add them up
        for (i=0;i<len_ip_header;i=i+2){
                word16 =((buff[i]<<8)&0xFF00)+(buff[i+1]&0xFF);
                sum = sum + (u32) word16;
        }

        // take only 16 bits out of the 32 bit sum and add up the carries
        while (sum>>16)
                sum = (sum & 0xFFFF)+(sum >> 16);

        // one's complement the result
        sum = ~sum;

        return ((u16) sum);
}

posted on 2010-10-20 17:05 小默 閱讀(739) 評論(0)  編輯 收藏 引用 所屬分類: Network

導(dǎo)航

統(tǒng)計

留言簿(13)

隨筆分類(287)

隨筆檔案(289)

漏洞

搜索

積分與排名

最新評論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲欧美不卡| 玖玖视频精品| 久久人人爽爽爽人久久久| 亚洲校园激情| 亚洲欧美中文在线视频| 香蕉成人伊视频在线观看| 久久se精品一区精品二区| 久久久久久色| 亚洲大片免费看| 亚洲人在线视频| 在线亚洲一区观看| 欧美一区二区三区久久精品茉莉花 | 久热精品视频在线| 欧美精品久久久久久久久久| 欧美特黄一级大片| 国内精品久久久久久| 狠狠综合久久| 一区二区三区导航| 欧美资源在线观看| 亚洲第一福利视频| 亚洲一区二区久久| 欧美成人免费va影院高清| 国产精品久久久久免费a∨大胸 | 久久一二三国产| 亚洲精品久久久一区二区三区| 亚洲视频播放| 欧美成人在线免费观看| 91久久精品视频| 日韩一级在线| 久久久久久久性| 国产精品你懂得| 亚洲久久一区| 另类尿喷潮videofree| 夜夜爽99久久国产综合精品女不卡| 午夜精品久久久久久久 | 国产精品综合网站| 亚洲激情中文1区| 久久久久九九九九| 一本一道久久综合狠狠老精东影业| 久久精品毛片| 国产伦精品一区二区三区照片91| 亚洲乱码国产乱码精品精可以看| 久久精品国产亚洲5555| 亚洲免费大片| 欧美激情欧美激情在线五月| 在线观看日韩一区| 狂野欧美一区| 久久久久久日产精品| 国产午夜精品视频免费不卡69堂| 亚洲视频网在线直播| 亚洲人成精品久久久久| 久久夜色精品国产亚洲aⅴ | 欧美日本一道本| 亚洲品质自拍| 欧美激情一区二区三区成人| 久久美女性网| 亚洲国产精品美女| 欧美成人一区二区在线 | 玖玖玖免费嫩草在线影院一区| 国产日韩欧美一区二区| 欧美一级理论性理论a| 亚洲一二三四区| 国产精品久久久久久久久免费樱桃| 夜夜躁日日躁狠狠久久88av| 亚洲欧洲一区二区三区在线观看| 男女视频一区二区| 亚洲久久一区| 日韩亚洲欧美中文三级| 欧美色欧美亚洲高清在线视频| 制服诱惑一区二区| 亚洲香蕉网站| 国产在线欧美| 亚洲高清自拍| 欧美婷婷六月丁香综合色| 午夜亚洲性色视频| 久久激情综合| 91久久精品国产91性色tv| 亚洲国产日本| 国产精品美女久久久| 久久久久久一区| 免费亚洲网站| 亚洲男人第一网站| 久久精品免视看| 国产精品大全| 亚洲一区二区三区四区五区午夜| 亚洲最快最全在线视频| 国产精品久久久久永久免费观看| 欧美在线网站| 欧美第十八页| 亚洲综合日韩中文字幕v在线| 亚洲中午字幕| 亚洲欧洲精品一区二区| 亚洲深夜av| 亚洲国产成人av| 亚洲欧美成人一区二区在线电影| 狠狠做深爱婷婷久久综合一区| 亚洲国产aⅴ天堂久久| 欧美日韩在线精品一区二区三区| 午夜精品久久久99热福利| 久久久亚洲欧洲日产国码αv| 一本色道久久精品| 久久久噜噜噜久久中文字幕色伊伊 | 欧美激情片在线观看| 欧美日产在线观看| 久久午夜电影| 国产精品久久久久久久免费软件 | 亚洲尤物视频网| 亚洲日本在线观看| 欧美一区二区三区免费视| 日韩一级精品视频在线观看| 欧美在线高清| 亚洲欧美伊人| 欧美日韩欧美一区二区| 欧美福利小视频| 黄色日韩网站| 亚洲欧美在线高清| 亚洲一区999| 欧美高清hd18日本| 蜜臀91精品一区二区三区| 国产精品一区二区三区观看| 99re6这里只有精品视频在线观看| 136国产福利精品导航网址| 午夜视频久久久| 亚洲欧美日本伦理| 欧美日韩在线播放三区| 欧美激情女人20p| 亚洲激情第一区| 欧美xart系列高清| 欧美激情一区二区三区在线视频观看 | 亚洲夜间福利| 亚洲一区二区三区中文字幕在线| 免费欧美在线| 亚洲国产精品精华液2区45| 国产精品色婷婷| 亚洲精华国产欧美| 亚洲国产另类 国产精品国产免费| 亚洲欧美日韩在线播放| 午夜精品在线看| 国产无遮挡一区二区三区毛片日本| 夜夜嗨av一区二区三区中文字幕 | 伊人成年综合电影网| 欧美亚洲一区二区三区| 性8sex亚洲区入口| 国产精品一区免费视频| 亚洲视频一区在线| 亚洲一区二区在线免费观看视频| 欧美理论大片| 一本大道久久精品懂色aⅴ| 亚洲视频在线一区| 国产精品午夜av在线| 欧美影院在线播放| 蜜桃av一区二区三区| 亚洲国产精品久久人人爱蜜臀| 乱中年女人伦av一区二区| 亚洲国产欧洲综合997久久| 99精品欧美一区二区三区综合在线| 欧美激情在线狂野欧美精品| 亚洲精品国久久99热| 亚洲免费网址| 国产午夜一区二区三区| 久久久国产亚洲精品| 亚洲第一黄色| 一区二区三区高清不卡| 国产伦一区二区三区色一情| 久久久精品欧美丰满| 91久久视频| 久久精品国产2020观看福利| 亚洲国产欧美久久| 国产精品qvod| 久久一区精品| 亚洲一本视频| 亚洲国产综合在线| 久久精品国产清高在天天线 | 欧美精品久久久久久久久老牛影院| 一区二区三区国产在线| 久久综合久久久久88| 一区二区三区四区五区精品视频| 国产欧美一二三区| 欧美国产日产韩国视频| 亚洲视频狠狠| 亚洲高清一区二区三区| 久久不见久久见免费视频1| 亚洲人成网在线播放| 国产香蕉97碰碰久久人人| 欧美日韩性视频在线| 久久男人av资源网站| 亚洲欧美日韩视频二区| 亚洲精品色图| 亚洲电影自拍| 蜜臀91精品一区二区三区| 欧美在线观看视频| 亚洲伊人伊色伊影伊综合网| 亚洲欧洲日本一区二区三区| 国内一区二区三区| 国产三区精品| 国产精品三上| 欧美日韩小视频| 欧美视频亚洲视频| 欧美成人69av| 美女精品网站|