ESP32 × Rust × W5500 — Sending Raw ARP Packets in MACRAW Mode with smoltc
ESP32 + W5500 MACRAW in Rust. smoltcp builds raw ARP frames sent over Ethernet, verified by Wireshark. First step toward a dual-W5500 network loop detector.
[English Version]
ESP32 × Rust × W5500 — Sending Raw ARP Packets in MACRAW Mode with smoltcp
#ESP32 #W5500 #Rust #MACRAW #smoltcp #ARP #Wireshark #EmbeddedRust #NetworkDiagnostics
📄 Source: Qiita article by t13801206 (亮 馬), published May 2, 2026 🔗 https://qiita.com/t13801206/items/0f7a0fde785f5898e214 ⚠️ GitHub repository not yet published. Code is included in the article itself.
01 — What is this project?
Most embedded networking projects treat the network stack as a black box — configure DHCP, open a socket, send data. This project does the opposite: it builds a raw Ethernet frame from scratch, byte by byte, in Rust, and watches it arrive on the other side using Wireshark.
The goal is to prove that an ESP32 + W5500, programmed entirely in Rust, can put a specific packet onto the wire exactly as intended. The packet chosen is ARP — the protocol that asks "who has this IP address?" — because it is the simplest real network packet and its arrival is immediately visible in Wireshark.
This is the first step in a larger project: a dual-W5500 network loop detector that will use two W5500 modules on the same ESP32 to detect Ethernet cable loops — a practical network diagnostic tool for field use.
02 — Why MACRAW mode?
W5500 supports two operating modes:
Hardware socket mode (TOE): W5500 manages TCP/IP internally. The host MCU just reads and writes data — no knowledge of packets needed.
MACRAW mode: W5500 acts only as a MAC layer interface. Raw Ethernet frames flow in and out. The host MCU is responsible for building every byte of every packet.
This project explicitly chooses MACRAW mode. The reason, stated directly in the article:
"W5500をMACRAWモードで動作させる。これにより、Rust側でパケットの中身を1ビット単位で制御できるようになる。" ("W5500 operates in MACRAW mode. This allows Rust to control every bit of the packet content.")
For a loop detector that needs to inspect raw frames on two ports simultaneously, MACRAW is the only viable approach. Hardware socket mode abstracts away exactly the frame-level data the application needs to see.
03 — System architecture
[ESP32]
esp-idf-hal (SPI driver)
↓ SPI (10MHz, GPIO 5/17/18/19/23)
[W5500 — MACRAW mode]
↓ Ethernet
[LAN / PC]
↑
Wireshark captures ARP frameThe Rust stack:
smoltcp
└─ ArpRepr + EthernetRepr (packet construction)
cotton-w5500
└─ W5500Device (smoltcp Device trait for W5500 MACRAW)
esp-idf-hal
└─ SpiDeviceDriver (SPI to W5500)smoltcp provides the packet construction layer. cotton-w5500 wraps W5500 MACRAW into a smoltcp-compatible Device trait. esp-idf-hal drives the SPI bus.
04 — Why W5500 in MACRAW + smoltcp?
🔷 smoltcp needs a raw frame interface
smoltcp is a software TCP/IP stack for embedded Rust. It does not use W5500's hardware socket abstraction — instead, it constructs and parses complete Ethernet frames itself, and expects the hardware to simply transmit and receive raw frames. MACRAW mode provides exactly that interface.
🔷 Full packet control — for diagnostics
A network loop detector needs to inspect raw Ethernet frames to detect duplicates. Hardware socket mode cannot expose individual MAC frames — it only exposes TCP/UDP payloads. MACRAW mode exposes every frame, making loop detection possible.
🔷 Rust's type system prevents packet construction errors
The article draws an explicit comparison with C:
| C | Rust (smoltcp) | |
|---|---|---|
| Safety | Array bounds errors crash silently | Compiler rejects buffer overflows |
| Readability | 0x08, 0x06... hex bytes | ArpOperation::Request named types |
| Maintainability | Manual memory management | Ownership system enforces correctness |
For network packet construction — where a single wrong byte breaks communication — Rust's type system is described as "the strongest guardrail."
05 — The ARP packet — what was sent
ARP (Address Resolution Protocol) is the protocol that maps IP addresses to MAC addresses. When a device wants to communicate with 10.0.0.254, it broadcasts: "Who has 10.0.0.254? Tell 10.0.0.200."
The packet sent in this project:
Source MAC: 02:AD:BE:EF:FE:ED (manually set in code)
Source IP: 10.0.0.200
Target IP: 10.0.0.254
Operation: ARP Request (broadcast)Wireshark on the PC captured the frame and the PC responded with an ARP Reply — confirming the packet was correctly constructed and transmitted over the physical Ethernet link.
06 — What comes next: dual-W5500 loop detector
The article ends with the next phase: connecting two W5500 modules to the same ESP32.
[ESP32]
W5500 #1 ──── Port A (send)
W5500 #2 ──── Port B (receive)
Loop detected: packet sent from A arrives at B
LED indicator: Red = loop detected / Green = healthyIn a looped network, a packet sent from one port will arrive back at another port. The ESP32 sends a probe packet from W5500 #1 and listens on W5500 #2 — if the probe arrives, a loop exists. This is a practical tool for network field diagnostics.
07 — Application scenarios
01. Network loop detection — field diagnostic tool
A compact ESP32 + 2× W5500 device that detects Ethernet cable loops on-site with a simple LED indicator. No laptop or complex software needed. #NetworkDiagnostics #LoopDetector #FieldTool
02. Embedded Rust + W5500 MACRAW reference implementation
A working code example of W5500 MACRAW mode with smoltcp in esp-idf Rust. Useful as a starting point for any project that needs raw Ethernet frame access on ESP32. #EmbeddedRust #MACRAW #smoltcp
03. Custom protocol implementation
MACRAW mode allows implementing any protocol on top of raw Ethernet — not just TCP/UDP. Custom industrial protocols, proprietary frame formats, or experimental networking can all be built on this foundation. #CustomProtocol #RawEthernet #Industrial
04. Network security research
Raw frame access enables passive monitoring, packet injection, and protocol analysis — tools used in network security research and penetration testing on embedded platforms. #NetworkSecurity #PacketAnalysis #Embedded
Conclusion
Rust builds the packet. W5500 puts it on the wire. Wireshark catches it. The loop detector is coming.
This project establishes the foundation: ESP32 + W5500 in MACRAW mode, programmed in Rust, can construct and transmit raw Ethernet frames with full byte-level control. smoltcp handles ARP frame construction cleanly through its type-safe API, and cotton-w5500 bridges smoltcp to the W5500 hardware.
The immediate goal — verified ARP packet transmission — is complete. The next goal — dual-W5500 loop detection — is the practical application that makes this foundation meaningful.
- ✅ W5500 MACRAW mode — raw Ethernet frame access
- ✅ smoltcp ARP packet construction in Rust
- ✅ cotton-w5500 smoltcp Device trait integration
- ✅ esp-idf-hal SPI driver (10MHz, GPIO 5/17/18/19/23)
- ✅ ARP request/reply verified via Wireshark
- ✅ Dual-W5500 loop detector — in progress
Q&A
Q. What is MACRAW mode? A W5500 operating mode where the chip acts only as a MAC layer interface — it transmits and receives raw Ethernet frames without any TCP/IP processing. The host MCU is responsible for all network protocol logic. The alternative is hardware socket mode (TOE), where W5500 manages TCP/IP internally.
Q. What is smoltcp? A software TCP/IP stack for embedded Rust. Unlike lwIP (C-based), smoltcp is written entirely in Rust with no unsafe code in the core library. It constructs and parses complete Ethernet frames and integrates with hardware via a Device trait — which cotton-w5500 implements for W5500 MACRAW mode.
Q. What is ARP? Address Resolution Protocol. When a device wants to communicate with an IP address on the local network, it broadcasts an ARP request: "Who has IP x.x.x.x? Tell me your MAC address." The device with that IP responds with its MAC address. ARP is the foundation of local Ethernet communication.
Q. Why use MACRAW instead of W5500's hardware sockets? Hardware sockets abstract away the Ethernet frame — you only see TCP/UDP payloads. For applications that need to inspect or construct raw frames (loop detection, custom protocols, packet capture), MACRAW is required. smoltcp also requires MACRAW because it implements its own TCP/IP stack rather than delegating to W5500's hardware.
Q. What is a network loop? When Ethernet cables are connected in a loop (Port A → Switch → Port B → Port A), broadcast packets circulate endlessly, flooding the network and causing severe performance degradation or complete outage. Loop detection devices identify this condition before it causes damage.
[한글 버전]
ESP32 × Rust × W5500 — smoltcp로 MACRAW ARP 패킷 직접 만들어 전송하기
#ESP32 #W5500 #Rust #MACRAW #smoltcp #ARP #Wireshark #임베디드Rust #네트워크진단
📄 출처: Qiita 기사, t13801206(亮 馬), 2026년 5월 2일 🔗 https://qiita.com/t13801206/items/0f7a0fde785f5898e214 ⚠️ GitHub 레포지토리는 아직 미공개. 코드는 기사 본문에 포함되어 있음.
01 — 이 프로젝트는 무엇인가?
대부분의 임베디드 네트워킹 프로젝트는 네트워크 스택을 블랙박스로 취급합니다 — DHCP 설정, 소켓 열기, 데이터 전송. 이 프로젝트는 반대입니다. Rust로 이더넷 프레임을 바이트 단위로 직접 만들고, Wireshark로 반대편에 도착하는 것을 확인합니다.
목표는 Rust로 프로그래밍된 ESP32 + W5500이 의도한 정확한 패킷을 전선에 올릴 수 있음을 증명하는 것입니다. 선택한 패킷은 ARP — "이 IP 주소를 가진 사람이 누구야?"라고 묻는 프로토콜 — 가장 단순한 실제 네트워크 패킷이라 Wireshark에서 즉시 확인할 수 있습니다.
이것은 더 큰 프로젝트의 첫 단계입니다: 이중 W5500 네트워크 루프 감지기 — 같은 ESP32에 두 개의 W5500을 연결해 이더넷 케이블 루프를 감지하는 현장 진단 도구.
02 — 왜 MACRAW 모드인가?
W5500은 두 가지 동작 모드를 지원합니다:
하드웨어 소켓 모드(TOE): W5500이 내부에서 TCP/IP를 처리합니다. 호스트 MCU는 데이터를 읽고 쓰기만 하면 됩니다.
MACRAW 모드: W5500이 MAC 레이어 인터페이스로만 동작합니다. 원시 이더넷 프레임이 그대로 오고 갑니다. 호스트 MCU가 모든 패킷의 모든 바이트를 직접 만들어야 합니다.
이 프로젝트는 명시적으로 MACRAW 모드를 선택합니다. 기사에 직접 나와 있습니다:
"W5500をMACRAWモードで動作させる。これにより、Rust側でパケットの中身を1ビット単位で制御できるようになる。" (W5500을 MACRAW 모드로 동작시킨다. 이로 인해 Rust 쪽에서 패킷 내용을 1비트 단위로 제어할 수 있게 된다.)
두 포트에서 동시에 원시 프레임을 검사해야 하는 루프 감지기에는 MACRAW가 유일한 선택입니다.
03 — 시스템 구조
[ESP32]
esp-idf-hal (SPI 드라이버)
↓ SPI (10MHz, GPIO 5/17/18/19/23)
[W5500 — MACRAW 모드]
↓ 이더넷
[LAN / PC]
↑
Wireshark가 ARP 프레임 캡처Rust 스택:
smoltcp
└─ ArpRepr + EthernetRepr (패킷 구성)
cotton-w5500
└─ W5500Device (W5500 MACRAW용 smoltcp Device 트레이트)
esp-idf-hal
└─ SpiDeviceDriver (W5500으로 SPI)smoltcp가 패킷 구성 레이어를 담당합니다. cotton-w5500이 W5500 MACRAW를 smoltcp 호환 Device 트레이트로 감쌉니다. esp-idf-hal이 SPI 버스를 구동합니다.
04 — 왜 W5500 MACRAW + smoltcp인가?
🔷 smoltcp는 원시 프레임 인터페이스가 필요하다
smoltcp는 임베디드 Rust용 소프트웨어 TCP/IP 스택입니다. W5500의 하드웨어 소켓 추상화를 사용하지 않고 — 완전한 이더넷 프레임을 직접 구성하고 파싱하며, 하드웨어가 원시 프레임을 단순히 송수신하기를 기대합니다. MACRAW 모드가 정확히 그 인터페이스를 제공합니다.
🔷 완전한 패킷 제어 — 진단용
네트워크 루프 감지기는 중복을 감지하기 위해 원시 이더넷 프레임을 검사해야 합니다. 하드웨어 소켓 모드는 개별 MAC 프레임을 노출할 수 없고 TCP/UDP 페이로드만 노출합니다. MACRAW 모드가 모든 프레임을 노출해 루프 감지를 가능하게 합니다.
🔷 Rust의 타입 시스템이 패킷 구성 오류를 방지한다
기사에서 C와 Rust를 명시적으로 비교합니다:
| 비교 항목 | C | Rust (smoltcp) |
|---|---|---|
| 안전성 | 배열 경계 오류로 즉시 크래시 | 컴파일러가 버퍼 오버플로를 허용하지 않음 |
| 가독성 | 0x08, 0x06... 16진수 나열 | ArpOperation::Request 이름으로 작성 |
| 유지보수성 | 메모리 관리에 항상 신경 써야 함 | 소유권 시스템이 자동으로 보호 |
한 바이트만 틀려도 통신이 무너지는 네트워크 패킷에서 Rust의 타입 시스템은 "최강의 가드레일"이라고 표현합니다.
05 — ARP 패킷 — 무엇을 보냈나
ARP(주소 결정 프로토콜)는 IP 주소를 MAC 주소에 매핑하는 프로토콜입니다. 기기가 10.0.0.254와 통신하려면 브로드캐스트합니다: "10.0.0.254를 가진 사람이 누구야? 10.0.0.200에게 알려줘."
이 프로젝트에서 전송한 패킷:
출발지 MAC: 02:AD:BE:EF:FE:ED (코드에서 수동 설정)
출발지 IP: 10.0.0.200
목적지 IP: 10.0.0.254
동작: ARP 요청 (브로드캐스트)PC의 Wireshark가 프레임을 캡처했고 PC가 ARP 응답으로 답했습니다 — 패킷이 올바르게 구성되어 물리적 이더넷 링크로 전송된 것을 확인했습니다.
06 — 다음 단계: 이중 W5500 루프 감지기
기사는 다음 단계로 마무리됩니다: 같은 ESP32에 두 개의 W5500 모듈 연결.
[ESP32]
W5500 #1 ──── 포트 A (송신)
W5500 #2 ──── 포트 B (수신)
루프 감지: A에서 보낸 패킷이 B에 도착하면 루프
LED 표시: 빨강 = 루프 감지 / 초록 = 정상루프된 네트워크에서 한 포트에서 보낸 패킷이 다른 포트로 돌아옵니다. ESP32가 W5500 #1에서 프로브 패킷을 보내고 W5500 #2에서 수신을 대기합니다 — 프로브가 도착하면 루프가 존재합니다.
07 — 응용 시나리오
01. 네트워크 루프 감지 — 현장 진단 도구
간단한 LED 표시로 이더넷 케이블 루프를 현장에서 감지하는 소형 ESP32 + 2× W5500 기기. 노트북이나 복잡한 소프트웨어가 필요 없습니다. #네트워크진단 #루프감지기 #현장도구
02. 임베디드 Rust + W5500 MACRAW 레퍼런스 구현
esp-idf Rust에서 W5500 MACRAW 모드와 smoltcp의 동작하는 코드 예제. ESP32에서 원시 이더넷 프레임 접근이 필요한 모든 프로젝트의 시작점으로 유용합니다. #임베디드Rust #MACRAW #smoltcp
03. 커스텀 프로토콜 구현
MACRAW 모드로 원시 이더넷 위에 어떤 프로토콜이든 구현할 수 있습니다. 커스텀 산업 프로토콜, 독점 프레임 형식, 실험적 네트워킹 모두 이 기반 위에 구축할 수 있습니다. #커스텀프로토콜 #원시이더넷 #산업
04. 네트워크 보안 연구
원시 프레임 접근으로 패시브 모니터링, 패킷 주입, 프로토콜 분석이 가능합니다. 임베디드 플랫폼에서의 네트워크 보안 연구와 침투 테스팅에 활용됩니다. #네트워크보안 #패킷분석 #임베디드
결론
Rust가 패킷을 만든다. W5500이 전선에 올린다. Wireshark가 잡는다. 루프 감지기가 온다.
이 프로젝트는 기반을 확립합니다: Rust로 프로그래밍된 ESP32 + W5500 MACRAW가 완전한 바이트 수준 제어로 원시 이더넷 프레임을 구성하고 전송할 수 있습니다. smoltcp가 타입 안전 API로 ARP 프레임 구성을 깔끔하게 처리하고, cotton-w5500이 smoltcp를 W5500 하드웨어에 연결합니다.
즉각적인 목표 — 검증된 ARP 패킷 전송 — 는 완료됐습니다. 다음 목표 — 이중 W5500 루프 감지 — 가 이 기반을 의미 있게 만드는 실용적 응용입니다.
- ✅ W5500 MACRAW 모드 — 원시 이더넷 프레임 접근
- ✅ Rust로 smoltcp ARP 패킷 구성
- ✅ cotton-w5500 smoltcp Device 트레이트 통합
- ✅ esp-idf-hal SPI 드라이버 (10MHz, GPIO 5/17/18/19/23)
- ✅ Wireshark로 ARP 요청/응답 확인
- ✅ 이중 W5500 루프 감지기 — 개발 중
Q&A
Q. MACRAW 모드란 무엇인가요? W5500이 MAC 레이어 인터페이스로만 동작하는 모드입니다 — TCP/IP 처리 없이 원시 이더넷 프레임을 송수신합니다. 호스트 MCU가 모든 네트워크 프로토콜 로직을 담당합니다. 대안은 W5500이 내부에서 TCP/IP를 처리하는 하드웨어 소켓 모드(TOE)입니다.
Q. smoltcp란 무엇인가요? 임베디드 Rust용 소프트웨어 TCP/IP 스택입니다. C 기반의 lwIP와 달리 smoltcp는 전적으로 Rust로 작성되어 있습니다. 완전한 이더넷 프레임을 구성하고 파싱하며, Device 트레이트를 통해 하드웨어와 통합됩니다 — cotton-w5500이 W5500 MACRAW 모드용으로 이를 구현합니다.
Q. ARP란 무엇인가요? 주소 결정 프로토콜(Address Resolution Protocol). 기기가 로컬 네트워크의 IP 주소와 통신하려면 ARP 요청을 브로드캐스트합니다: "x.x.x.x IP를 가진 사람의 MAC 주소를 알려줘." 그 IP를 가진 기기가 MAC 주소로 응답합니다. ARP는 로컬 이더넷 통신의 기반입니다.
Q. W5500 하드웨어 소켓 대신 MACRAW를 쓰는 이유는? 하드웨어 소켓은 이더넷 프레임을 추상화합니다 — TCP/UDP 페이로드만 볼 수 있습니다. 원시 프레임을 검사하거나 구성해야 하는 애플리케이션(루프 감지, 커스텀 프로토콜, 패킷 캡처)에는 MACRAW가 필요합니다. smoltcp도 W5500의 하드웨어에 위임하지 않고 자체 TCP/IP 스택을 구현하기 때문에 MACRAW가 필요합니다.
Q. 네트워크 루프란 무엇인가요? 이더넷 케이블이 루프로 연결되면(포트 A → 스위치 → 포트 B → 포트 A) 브로드캐스트 패킷이 끝없이 순환해 네트워크가 심각하게 저하되거나 완전히 마비됩니다. 루프 감지 기기는 피해가 발생하기 전에 이 상태를 식별합니다.
