#P10347. [THUSC 2019] 网络层协议数据处理
[THUSC 2019] 网络层协议数据处理
Background
For programmers, Baidu’s biggest use is of course testing network connectivity. After processing the ARP packets, Pengpeng excitedly typed ping baidu.com, but got no result. After consulting Jie, Pengpeng understood how the ping tool works: it uses the ICMP protocol and works at the network layer, which is higher than the data link layer. He also found that there were many ping packets being sent to him on the network. It seems that many people really care about him. To avoid letting them down, you decide to help Pengpeng reply to these requests.
Problem Description
You need to process network-layer protocol data based on the relevant knowledge in the Study Manual. In the given traffic fragments, some are ICMP Echo Request packets sent to you (that is, both the requested IP and MAC addresses belong to you, and match the corresponding relations in the pcap statement). Please reply to them correctly.
You need to construct correct ICMP Echo Reply packets, as well as the outer IP packet header, the Ethernet frame header and trailer, and write these frames into the output file in order of replies.
In this problem, you only respond to ICMP Echo Request packets whose source address and destination address are in the same subnet, and you do not respond to other cases (for example, source and destination are not in the same network, ARP requests).
We guarantee that all ICMP Echo Request packets are unicast at both the data link layer and the network layer (that is, you do not need to consider broadcast addresses, etc.; the definition of broadcast addresses is given in the Study Manual). Please fill in the source and destination addresses correctly at these two layers in the reply packet.
If the received packet contains payload data, then your reply packet also needs to carry these payloads unchanged, but do not carry any extra data in the link-layer frame that goes beyond the IP packet size (please ignore Wireshark’s parsing of that extra part).
In particular, this problem has additional requirements for the timestamps of fragments in the output data. Let the timestamp of an ICMP Echo Request be . Then the timestamp of the ICMP Echo Response you send should satisfy $\sec \times 10^6 + \text{us} = \sec_0 \times 10^6 + \text{us}_0 + 1$ and . The data guarantees that and , and it does not guarantee that the addition above will not overflow a 32-bit unsigned integer. Note that the time shown in the upper part of the Wireshark interface is an offset relative to the timestamp of the first Ethernet frame.
Input Format
The input contains at most traffic fragments, with total size at most bytes.
Output Format
Your output will be compared with the answer file byte by byte. Please do not output any extra information, to avoid unnecessary loss of points.
Hint
[Subtasks]
The size of each subtask is the same as in the previous problem.
[Sample 1]
See the attachments 1.in/ans.
[Sample Explanation 1]
In the sample, the input data consists of three ICMP Echo Request packets, and the output data consists of the corresponding three ICMP Echo Reply packets.
[Notes]
Please do not forget the content related to this problem in the statements of the first three problems, and pay attention to the computation of FCS and IP checksum, as well as the Ethernet frame length requirements.
Translated by ChatGPT 5