ICMP
主要功能:
- 確認IP包是否成功送達目標地址
- 通知在發送過程當中IP包被廢棄的具體原因
- 改善網絡設置等
在IP通信中如果某個IP包因為某種原因未到達目標地址,那么這個原因由ICMP通知。
過程(圖解TCP/IP)
ICMP類型
常見的:
ICMP不可達
ICMP重定向
ping
校驗和算法
unsigned short chksum(unsigned short *addr,int len)
{unsigned int ret = 0;while(len >1){ret += *addr++;len -= 2;}if(len == 1){ret += *(unsigned char *)addr;}ret = (ret>>16) + (ret&0xffff);ret += (ret>>16);return (unsigned short)~ret;
}
TYPE | CODE | Description | Query | Error |
---|---|---|---|---|
0 | 0 | Echo Reply——回顯應答(Ping應答) | x | ? |
3 | 0 | Network Unreachable——網絡不可達 | ? | x |
3 | 1 | Host Unreachable——主機不可達 | ? | x |
3 | 2 | Protocol Unreachable——協議不可達 | ? | x |
3 | 3 | Port Unreachable——端口不可達 | ? | x |
3 | 4 | Fragmentation needed but no frag. bit set——需要進行分片但設置不分片比特 | ? | x |
3 | 5 | Source routing failed——源站選路失敗 | ? | x |
3 | 6 | Destination network unknown——目的網絡未知 | ? | x |
3 | 7 | Destination host unknown——目的主機未知 | ? | x |
3 | 8 | Source host isolated (obsolete)——源主機被隔離(作廢不用) | ? | x |
3 | 9 | Destination network administratively prohibited——目的網絡被強制禁止 | ? | x |
3 | 10 | Destination host administratively prohibited——目的主機被強制禁止 | ? | x |
3 | 11 | Network unreachable for TOS——由于服務類型TOS,網絡不可達 | ? | x |
3 | 12 | Host unreachable for TOS——由于服務類型TOS,主機不可達 | ? | x |
3 | 13 | Communication administratively prohibited by filtering——由于過濾,通信被強制禁止 | ? | x |
3 | 14 | Host precedence violation——主機越權 | ? | x |
3 | 15 | Precedence cutoff in effect——優先中止生效 | ? | x |
4 | 0 | Source quench——源端被關閉(基本流控制) | ? | ? |
5 | 0 | Redirect for network——對網絡重定向 | ? | ? |
5 | 1 | Redirect for host——對主機重定向 | ? | ? |
5 | 2 | Redirect for TOS and network——對服務類型和網絡重定向 | ? | ? |
5 | 3 | Redirect for TOS and host——對服務類型和主機重定向 | ? | ? |
8 | 0 | Echo request——回顯請求(Ping請求) | x | ? |
9 | 0 | Router advertisement——路由器通告 | ? | ? |
10 | 0 | Route solicitation——路由器請求 | ? | ? |
11 | 0 | TTL equals 0 during transit——傳輸期間生存時間為0 | ? | x |
11 | 1 | TTL equals 0 during reassembly——在數據報組裝期間生存時間為0 | ? | x |
12 | 0 | IP header bad (catchall error)——壞的IP首部(包括各種差錯) | ? | x |
12 | 1 | Required options missing——缺少必需的選項 | ? | x |
13 | 0 | Timestamp request (obsolete)——時間戳請求(作廢不用) | x | ? |
14 | ? | Timestamp reply (obsolete)——時間戳應答(作廢不用) | x | ? |
15 | 0 | Information request (obsolete)——信息請求(作廢不用) | x | ? |
16 | 0 | Information reply (obsolete)——信息應答(作廢不用) | x | ? |
17 | 0 | Address mask request——地址掩碼請求 | x | ? |
18 | 0 | Address mask reply——地址掩碼應答 |