130 likes | 337 Views
Lab-4 ICMP Ping Programming. Speaker : Yi-Fong Lin Date:2007.11.28. IP & ICMP. IP – Internet Protocol ICMP - Internet Control Message Protocol IP & ICMP insert into Ethernet packet. Ethernet 封包. IP 封包. DA MAC. SA MAC. TYPE 0x0800. IP header. ICMP header. ICMP data. ICMP 封包
E N D
Lab-4 ICMP Ping Programming Speaker : Yi-Fong Lin Date:2007.11.28
IP & ICMP • IP – Internet Protocol • ICMP - Internet Control Message Protocol • IP & ICMP insert into Ethernet packet Ethernet 封包 IP 封包 DA MAC SA MAC TYPE 0x0800 IP header ICMP header ICMP data ICMP 封包 (IP data)
IP header 0 8 16 24 31 SERVICE TYPE TOTAL LENGTH VERS HLEN IDENTIFICATION FRAGMENT OFFSET FLAGS 5個4Bytes TIME TO LIVE PROTOCOL HEADER CHECKSUM SOURCE IP DESTINATION IP IP OPTION(IF ANY) PADDING 不使用
IP header • VERS:IP協定的版本號碼,IPv4:0x4 • HLEN:IP表頭長度,4 bytes為單位, no option : 0x05 • SERVICE TYPE: • PRECEDENCE : 優先權 • D : No Delay • H : High Throughput • R : High Reliability • TOTAL LENGTH:IP header跟data的總長度,byte為單位。 • IDENTIFICATION:IP封包的編號。 7 6 5 4 3 0 保留 D T R PRECEDENCE
IP header • FLAGS、FRAGMENTOFFSET • TIME TO LIVE(TTL):定義一封包在網路系統中存活的時間。 • PROTOCOL:UDP:0x11 TCP:0x06 ICMP:0x01 • HEADER CHECKSUM • SOURCE IP、DESTINATION IP
ICMP types TYPE ICMP Message Type 0 Echo Reply 3 Destination Unreachable 4 Source quench 5 Redirect 8 Echo Request (Ping) 11 Time Exceeded for a Datagram 12 Parameter Problem on a Datagram 13 Timestamp Request 14 Timestamp Reply 15 Information Request 16 Information Reply 17 Address Mask Request 18 Address Mask Reply
CheckSum 0 4 8 16 31 0x00 0x04 0x05 0x00 0x0100 0x0050 0x00 0x80 0x01 checksum Destination IP 0x8C.0x7D.0x21.0x01 0x8C.0x7D.0x21.0x02 Source IP IP OPTION(IF ANY) PADDING
CheckSum 計算法 • 每16bit做相加 • Ex: • 0x4 5 0 0 • 0x0 0 0 0 • 0x0 1 0 0 • 0x0 0 5 0 • 0x8 0 0 1 • 0x0 0 0 0 • 0x8 C7 D • 0x2 1 0 1 • 0x8 C7 D • 0x2 1 0 2 CheckSum DE AF + 2 2 1 4 E + 2 1 5 0 =>取1的補數 =>1101 1110 1010 1111(DEAF)
Ping 140.125.33.10 ARP Who is 140.125.33.12 Ping 140.125.33.12 MAC=03:04:05:06:07:08 ICMP Request 140.125.32.18 I am 140.125.33.12 My MAC is 03:04:05:06:07:08 ICMP Reply 140.125.33.12
ICMP • Format 0 8 16 24 31 TYPE(8or0) CHECKSUM CODE(0) IDENTIFIER SEQUENCE NUMBER OPTION DATA… • checksum:ICMP header跟data的checksum • Identifier、sequence是request sender用來檢查reply封包是回應哪一個request封包。 • option data長度是可變動的,reply回的option 必需跟 request一樣。 • command: ping {目地 IP}
Lab Work • 透過 Uart interface 可用下指令的方式ping 至其他連接到網路的裝置,並且顯示分析 ICMP echo request/reply封包。 • 可回覆 ICMP echo request 封包,即接受網路上其他裝置的 ping 要求。