如何在软件中可靠地生成以太网帧错误? [英] How to reliably generate Ethernet frame errors in software?

查看:29
本文介绍了如何在软件中可靠地生成以太网帧错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试部分电缆故障查找软件,我希望能够可靠且可重现地在 Cat5 电缆上生成电缆故障.

I'm testing a section of cable-fault finding software, and I'd like to reliably and reproducibly generate cable faults on a cat5 cable.

目前我正在使用一米长的未绞合电缆,并在电源旁边手动扭动电缆,但我无法检测到应用程序中的任何故障(我正在从以太网 ASIC 读取以太网故障计数器.) 到底是没有产生故障,还是软件/硬件检测有问题,我不知道.

At the moment I'm using a meter length of untwisted cable, and wriggle the cable manually next to a power supply, but I cannot detect any faults in the application (I'm reading the Ethernet fault counters off the Ethernet ASIC.) Whether this is because no faults are generated, or because the software/hardware detection is faulty, I cannot tell.

有没有办法在软件中做到这一点?

Is there a way to do this in software?

我愿意用更高级的语言编写一些东西,比如 Java 或 python,作为最后的手段,我愿意将它放在 C 中,但我真的不想纯粹地重新编写以太网驱动程序修复一个可能的错误.

I'd settle for writing something in a higher level language, like Java or python, and as a last resort would be willing to put it together in C, but I'd really rather not re-write an Ethernet driver purely to fix a possible bug.

:我想创建电缆故障 - 不检测它们.

: I want to create cable faults - not detect them.

:我已经通过 FTP 和 SCP 传输了大文件,并且使用经过篡改的电缆没有问题,并且在使用 wireshark 检查流量时没有发现任何错误

: I've transferred large files through FTP and SCP without problems with the doctored cable, and I see no errors coming up while inspecting the traffic with wireshark

:另见python 中的类似问题.

好吧,在与 C 进行了一天多的斗争之后,这就是 Python 解决方案.

Well, after spending over a day fighting with C, this is the python solution.

首先禁用以太网卡的自动校验和:

First disable automatic checksumming of the ethernet card:

sudo ethtool -K eth1 tx off

然后,从 python 发送你的狡猾框架:

Then, send your dodgy frame from python:

#!/usr/bin/env python

from socket import *

#
# Ethernet Frame:
# [
#   [ Destination address, 6 bytes ]
#   [ Source address, 6 bytes      ]
#   [ Ethertype, 2 bytes           ]
#   [ Payload, 40 to 1500 bytes    ]
#   [ 32 bit CRC chcksum, 4 bytes  ]
# ]
#

s = socket(AF_PACKET, SOCK_RAW)
s.bind(("eth1", 0))
src_addr = "x01x02x03x04x05x06"
dst_addr = "x01x02x03x04x05x06"
payload = ("["*30)+"PAYLOAD"+("]"*30)
checksum = "x00x00x00x00"
ethertype = "x08x01"
s.send(dst_addr+src_addr+ethertype+payload+checksum)

谁说它必须很复杂...

Who said it had to be complicated...

PS:我喜欢 Python.

推荐答案

如果您使用 C 语言,您可以使用 socket(AF_PACKET, SOCK_RAW, ...) 发送原始以太网帧,并将其传递给您自己生成的原始缓冲区的指针(例如,通过遵循 wikipedia 上的框架布局).

If you're working in C, you can send a raw Ethernet frame using socket(AF_PACKET, SOCK_RAW, ...), and passing it a pointer to a raw buffer that you've generated yourself (e.g. by following the frame layout at wikipedia ).

我已经很久没有这样做了,所以我不打算尝试写一个有代表性的代码片段......

It's been a long time since I've done this, so I'm not going to attempt to write a representative code snippet...

这篇关于如何在软件中可靠地生成以太网帧错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆