#P10346. ARP Reply PCAP Generator

    ID: 12350 Type: Default 1000ms 256MiB

ARP Reply PCAP Generator

ARP Reply PCAP Generator

Problem Description

You are given a series of Ethernet frames captured in a PCAP-format stream. Some of these frames contain ARP requests. Your task is to parse the frames and respond only to valid ARP requests whose target IP address matches your own. The PCAP file may also include frames with checksum (FCS) errors – these frames must be discarded immediately.

The ARP request frames might be sent to a broadcast MAC address (for example, FF:FF:FF:FF:FF:FF) or to another MAC address; as long as the target protocol address (TPA) in the ARP packet equals your IP, you must generate a proper ARP reply.

For each valid ARP request received:

  1. Verify the Ethernet frame’s FCS (the last 4 bytes). Compute the CRC32 (in LaTeX, use \(\mathrm{CRC32}\)) of the frame data (all bytes except the last 4) using the standard algorithm. Only process frames where the computed \(\mathrm{CRC32}\) equals the provided FCS. Otherwise, discard the frame.
  2. Ensure the EtherType in the Ethernet header is \(0x0806\) (indicating an ARP packet), and that the ARP opcode equals \(1\) (request).
  3. Check that the target protocol address (TPA) in the ARP packet (located at bytes 38–41, zero‐indexed from the start of the frame) matches your IP address. (Your IP and MAC address are provided in the first line of input.)
  4. If so, construct an ARP reply frame as follows:
    • The Ethernet header: set the destination MAC to the sender MAC from the request (bytes 6–11) and the source MAC to your own MAC. EtherType remains \(0x0806\).
    • The ARP packet: copy the hardware type, protocol type, hardware length, and protocol length from the request. Set the opcode to \(2\) (reply). For the ARP packet body, set the sender hardware address to your MAC and sender protocol address to your IP. The target hardware address and target protocol address must be copied from the sender fields of the request.
    • If the constructed frame (Ethernet header + ARP payload) is less than 60 bytes (excluding the FCS), pad it with zeros to meet the minimum Ethernet frame length requirement.
    • Compute the \(\mathrm{CRC32}\) for the reply (over all bytes except the FCS) and append the resulting 4-byte FCS at the end.
  5. Output each generated reply frame as a hexadecimal string (all in lowercase) on its own line, preserving the order in which the ARP requests appeared in the input.

Note: In all frames (including those in other problems), if any frame fails the FCS validation, discard it immediately, and do not make any assumptions about data consistency.

inputFormat

Input Format

The first line contains two tokens: your IP address and your MAC address separated by a space. The MAC address is provided in colon-separated hexadecimal format (e.g. 00:11:22:33:44:55), and the IP address is in dotted decimal notation.

The second line contains an integer \(N\) representing the number of Ethernet frames.

Each of the following \(N\) lines contains one hexadecimal string representing an Ethernet frame in the PCAP file. Each frame includes both the payload and a 4-byte FCS at the end. Frames may include padding so that the total frame (without the FCS) is at least 60 bytes.

outputFormat

Output Format

For every valid ARP request (i.e. one that passes the FCS check, has EtherType 0x0806, opcode 1, and a target protocol address matching your IP), output a single line containing the corresponding ARP reply frame represented as a lowercase hexadecimal string. The ARP reply must be constructed as described, including a proper Ethernet header, ARP payload, required padding (if needed to reach 60 bytes before FCS), and an appended 4-byte FCS.

If no ARP reply is generated, output nothing.

sample

192.168.0.10 00:11:22:33:44:55
1
ffffffffffffaabbccddeeff08060001080006040001aabbccddeeffc0a800010000000000000000000000000000000000b1e2c6d4
aabbccddeeff00112233445508060001080006040002001122334455c0a8000aaabbccddeeffc0a800010000000000000000000000000000000000e3f4a1b2