From e4217ff8685b940b8f995523f2e9755b8953b0d7 Mon Sep 17 00:00:00 2001 From: Ondrej Kosta Date: Thu, 31 Mar 2022 14:51:40 +0200 Subject: [PATCH] esp_eth/test_apps: fixed byte order of EthType during raw socket creation --- components/esp_eth/test_apps/pytest_esp_eth.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/esp_eth/test_apps/pytest_esp_eth.py b/components/esp_eth/test_apps/pytest_esp_eth.py index 3b7e65f3ab..6f9440d505 100644 --- a/components/esp_eth/test_apps/pytest_esp_eth.py +++ b/components/esp_eth/test_apps/pytest_esp_eth.py @@ -12,6 +12,8 @@ import pytest from pytest_embedded import Dut from scapy.all import Ether, raw +ETH_TYPE = 0x2222 + @contextlib.contextmanager def configure_eth_if() -> Iterator[socket.socket]: @@ -28,7 +30,7 @@ def configure_eth_if() -> Iterator[socket.socket]: raise Exception('no network interface found') logging.info('Use %s for testing', target_if) - so = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0x2222) + so = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(ETH_TYPE)) so.bind((target_if, 0)) try: @@ -43,7 +45,7 @@ def send_eth_packet(mac: str) -> None: payload = bytearray(1010) for i, _ in enumerate(payload): payload[i] = i & 0xff - eth_frame = Ether(dst=mac, src=so.getsockname()[4], type=0x2222) / raw(payload) + eth_frame = Ether(dst=mac, src=so.getsockname()[4], type=ETH_TYPE) / raw(payload) try: so.send(raw(eth_frame)) except Exception as e: @@ -56,7 +58,7 @@ def recv_resp_poke(i: int) -> None: try: eth_frame = Ether(so.recv(60)) - if eth_frame.type == 0x2222 and eth_frame.load[0] == 0xfa: + if eth_frame.type == ETH_TYPE and eth_frame.load[0] == 0xfa: if eth_frame.load[1] != i: raise Exception('Missed Poke Packet') eth_frame.dst = eth_frame.src @@ -71,7 +73,7 @@ def traffic_gen(mac: str, pipe_rcv:connection.Connection) -> None: with configure_eth_if() as so: payload = bytes.fromhex('ff') # DUMMY_TRAFFIC code payload += bytes(1485) - eth_frame = Ether(dst=mac, src=so.getsockname()[4], type=0x2222) / raw(payload) + eth_frame = Ether(dst=mac, src=so.getsockname()[4], type=ETH_TYPE) / raw(payload) try: while pipe_rcv.poll() is not True: so.send(raw(eth_frame))