如何可靠地生成软件以太网帧错误? [英] How to reliably generate Ethernet frame errors in software?
问题描述
我测试的电缆故障的查找软件的一部分,我想在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
:又见A <一个href=\"http://stackoverflow.com/questions/723635/how-do-you-send-an-ethernet-frame-with-a-corrupt-fcs\">similar问题在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
然后,从蟒蛇发送您的狡猾框架:
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 = "\x01\x02\x03\x04\x05\x06"
dst_addr = "\x01\x02\x03\x04\x05\x06"
payload = ("["*30)+"PAYLOAD"+("]"*30)
checksum = "\x00\x00\x00\x00"
ethertype = "\x08\x01"
s.send(dst_addr+src_addr+ethertype+payload+checksum)
谁说它必须是复杂的...
Who said it had to be complicated...
PS:我爱的Python 的
推荐答案
如果您是在C工作,则可以使用插座(AF_PACKET,SOCK_RAW,...)发送原始的以太网帧
,并传递一个指针,你自己产生原始缓冲区(如通过的维基百科)。
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 ).
这是一个很长的时间,因为我已经做到了这一点,所以我不打算尝试写一重presentative code片段...
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屋!