How Fast Does Claude, Acting as a User Space IP Stack, Respond to Pings?

How Fast Does Claude, Acting as a User Space IP Stack, Respond to Pings?

当 Claude 化身为用户空间 IP 协议栈时,它响应 Ping 的速度有多快?

Here is a fun thought: if we ask Claude Code to act as a user space IP stack, how quickly will it be able to respond to a ping? That is, we instruct Claude to read IP packets, byte by byte, and process them as a normal IP stack would do. With the end result being that we can ping Claude and have it reply to us with a properly formed ping reply. 这是一个有趣的设想:如果我们要求 Claude Code 充当用户空间(User Space)的 IP 协议栈,它响应 Ping 的速度会有多快?也就是说,我们指示 Claude 逐字节读取 IP 数据包,并像常规 IP 协议栈那样处理它们。最终目标是让我们能够 Ping 通 Claude,并让它以格式正确的 Ping 回复来响应我们。

Ridiculous? Yes. Wasteful of tokens? Sure. Fun? Oh yeah! And interesting to see how far we can push the idea that Markdown is code and an LLM is the processor that executes that code. In this case, pretty low-level code. 荒谬吗?是的。浪费 Token 吗?当然。有趣吗?太有趣了!而且,看看我们能将“Markdown 即代码,LLM 即执行代码的处理器”这一理念推向何种程度,也是一件很有意思的事。在这种情况下,这可是相当底层的代码。

I asked Claude to develop a command, ping-respond.md, that would act as such a native LLM IP stack, and this is what it came up with: 我要求 Claude 开发一个名为 ping-respond.md 的命令,使其充当这样一个原生的 LLM IP 协议栈,以下是它的成果:


ping-respond.md (click to expand)

ping-respond.md(点击展开)

# Ping Respond — Process one ICMP echo request from tun0 # Ping 响应 — 处理来自 tun0 的一个 ICMP 回显请求

You are acting as a userspace IP stack. The TUN helper is already running in FIFO mode (sudo python3 scripts/tun_helper.py --fifo). Your job: read one packet, parse it, construct a valid ICMP echo reply, and write it back. All IP logic happens in your reasoning — no libraries, no scripts. 你现在充当一个用户空间 IP 协议栈。TUN 辅助程序已在 FIFO 模式下运行 (sudo python3 scripts/tun_helper.py --fifo)。你的任务是:读取一个数据包,解析它,构建一个有效的 ICMP 回显回复,并将其写回。所有的 IP 逻辑都在你的推理过程中完成——不使用任何库,也不使用任何脚本。

## Step 1: Read a packet ## 第一步:读取数据包

Run this bash command to read one packet from the TUN device: 运行此 bash 命令从 TUN 设备读取一个数据包: echo "READ" > /tmp/tun_cmd && timeout 35 cat /tmp/tun_resp

You will get back a hex string (or “TIMEOUT”). If TIMEOUT, report it and stop. Save the hex string — this is the raw IPv4 packet. 你将得到一个十六进制字符串(或“TIMEOUT”)。如果超时,请报告并停止。保存该十六进制字符串——这就是原始的 IPv4 数据包。

## Step 2: Parse the IPv4 header ## 第二步:解析 IPv4 头部

The packet is a sequence of hex bytes (2 hex chars = 1 byte). Parse these fields: 数据包是一串十六进制字节(2 个十六进制字符 = 1 字节)。解析以下字段:

Offset (bytes)LengthField
01Version (high nibble) + IHL (low nibble, in 32-bit words)
11DSCP/ECN
2–32Total length
4–52Identification
6–72Flags (3 bits) + Fragment offset (13 bits)
81TTL
91Protocol (must be 0x01 = ICMP)
10–112Header checksum
12–154Source IP
16–194Destination IP
偏移量 (字节)长度字段
01版本 (高 4 位) + IHL (低 4 位,以 32 位字为单位)
11DSCP/ECN
2–32总长度
4–52标识
6–72标志 (3 位) + 片偏移 (13 位)
81TTL
91协议 (必须为 0x01 = ICMP)
10–112头部校验和
12–154源 IP
16–194目的 IP

IHL tells you the header length: IHL × 4 bytes. Standard is IHL=5 → 20 bytes. If protocol is not 0x01, report “not ICMP, ignoring” and stop. IHL 告诉你头部长度:IHL × 4 字节。标准情况是 IHL=5 → 20 字节。如果协议不是 0x01,请报告“非 ICMP,忽略”并停止。

## Step 3: Parse the ICMP header ## 第三步:解析 ICMP 头部

The ICMP header starts right after the IP header (at byte offset IHL×4): ICMP 头部紧接在 IP 头部之后(在字节偏移量 IHL×4 处):

Offset (from ICMP start)LengthField
01Type (must be 0x08 = echo request)
11Code (must be 0x00)
2–32ICMP checksum
4–52Identifier
6–72Sequence number
8+variablePayload (copy unchanged)
偏移量 (从 ICMP 开始)长度字段
01类型 (必须为 0x08 = 回显请求)
11代码 (必须为 0x00)
2–32ICMP 校验和
4–52标识符
6–72序列号
8+可变载荷 (原样复制)

If type is not 0x08, report “not echo request, ignoring” and stop. 如果类型不是 0x08,请报告“非回显请求,忽略”并停止。

## Step 4: Construct the echo reply ## 第四步:构建回显回复

Build the reply packet by modifying specific fields. Work in hex throughout. 通过修改特定字段来构建回复数据包。全程使用十六进制进行计算。

4a: IP header for the reply

4a:回复的 IP 头部

Start with the original IP header bytes and change: 从原始 IP 头部字节开始,进行以下更改:

  • Byte 8 (TTL): set to 40 (decimal 64)

  • Bytes 10–11 (header checksum): set to 0000 temporarily

  • Bytes 12–15 (source IP): set to the original destination IP

  • Bytes 16–19 (destination IP): set to the original source IP

  • 第 8 字节 (TTL): 设置为 40 (十进制 64)

  • 第 10–11 字节 (头部校验和): 暂时设置为 0000

  • 第 12–15 字节 (源 IP): 设置为原始的 目的 IP

  • 第 16–19 字节 (目的 IP): 设置为原始的 IP

Now compute the IP header checksum… (omitted for brevity) 现在计算 IP 头部校验和……(为简洁起见,此处省略计算步骤)


The command reads bytes from a /dev/tun0 device, with a thin Python helper to get all the stty options right, then computes the IP checksum and, if it sees an ICMP echo message, it responds with an ICMP echo reply message, with all the checksums computed correctly. 该命令从 /dev/tun0 设备读取字节,并配合一个轻量级的 Python 辅助程序来正确设置所有 stty 选项,然后计算 IP 校验和。如果它检测到 ICMP 回显消息,它就会以正确计算出所有校验和的 ICMP 回显回复消息进行响应。

Running this will make Claude produce output like this: 运行此程序将使 Claude 输出如下内容:

Received packet: 45000054812840004001615dac100001ac100002080054f5000d0001a1fb006a0000000041c4000000000000101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637 Parsing the IP header (first 40 hex chars = 20 bytes): - 45 → version=4, IHL=5 (20 bytes) - 0054 → total length = 84 - TTL=40 (64), Protocol=01 (ICMP) - Source: ac100001 = 172.16.0.1 - Dest: ac100002 = 172.16.0.2 ICMP: type=08 (echo request), code=00, id=000d, seq=0001 Now constructing the reply. IP header: swap src/dst, TTL=64, recompute checksum. ICMP: type=00 (echo reply)