# IPv4 - ICMPv4 [TOC] ## 課程影片 除了影片之外可以看 [`icmp(7)`](https://www.man7.org/linux/man-pages/man7/icmp.7.html) 這個 `man` 中的條目。 ### 第 7LMN 講 路由器運作原理以及網路互連技術 L07 12 13 14 {%youtube 4aRXm4ujh7g %} ### Lec38 計算機網路 第四章 Internet Protocol Layer (12/19) {%youtube 1fa8UF0je5c %} ### Enhancing Ping And Traceroute (Netdev 0x15) {%youtube g7nETFruu8o %} ### [Python Network Packet Sniffer Tutorial - 5 - Unpacking ICMP and TCP Data](https://youtu.be/3zwuOo7U1YQ) {%youtube 3zwuOo7U1YQ %} ## 目標:回報丟棄封包的原因 ## ICMPv4 封包格式 規格在 [RFC792](https://datatracker.ietf.org/doc/html/rfc792): ```c 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Type | Code | Checksum | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | unused | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Internet Header + 64 bits of Original Data Datagram | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ``` Linux 核心定義在 [`include/uapi/linux/icmp.h`](https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/icmp.h#L89): ```c struct icmphdr { __u8 type; __u8 code; __sum16 checksum; union { struct { __be16 id; __be16 sequence; } echo; __be32 gateway; struct { __be16 __unused; __be16 mtu; } frag; __u8 reserved[4]; } un; }; ``` ### `type` 與 `code` --- 封包失敗的理由 參考 [*Internet Control Message Protocol (ICMP) Parameters*](https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml):
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up