以 C 语言编程设置 MTU
客户要求MTU限制为1492。
有没有办法在源代码(C语言程序)中做到这一点?
一般情况下还有其他方法吗? (ifconfig?)
为什么有人需要将 MTU 修改为某个限制?有什么好处?而最 重要提示:更改 MTU 是否存在破解代码的风险?
A client requested that the MTU limit should be 1492.
Is there a way to do it in the source code (program in C)?
Is there any other way to do it in general? (ifconfig?)
Why does somebody needs to modify MTU to a certain limit? What is the benefit? And the most
important: By changing the MTU is there any risk to break the code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 C 的编程方式:
它至少可以在 Ubuntu 上运行,请参阅
man netdevice
。Programmaticaly way using C:
It works at least on Ubuntu, see
man netdevice
.这与速度无关;而是与速度有关。通过增加 MTU,您可以减少开销,这些数据负责正确传送包,但最终用户无法使用它;这可以提高速度,但仅限于交通繁忙的情况;
此外,如果增加 MTU,则很容易增加丢弃的数据包数量(因为数据包中有固定的误码概率和更多位),最终导致重发数据包等性能下降。所以这是开销和数据完整性之间的折衷;
我想它更多的是一个界面配置,而不是你用程序控制的东西;因此,最好坚持使用“ifconfig”命令或找到适用于 Windows 的等效解决方案。
It's not about speed directly; By increasing MTU you're reducing overhead, which is data that is responsible for the proper delivery of the package but it's not usable by the end user; This can have a increase in speed but only for heavy traffic;
Also, if you increase MTU, you're prone to increase the number of packets that are dropped (since you have a fixed bit error probability and more bits in a packet), eventually causing a decrease in performance with resent packets, etc... So it's a compromise between overhead and data integrity;
I guess that it is more of a interface configuration than something you control with a program; So it's better to stick with 'ifconfig' command or find the equivalent solution for Windows.
MTU 是定义每个数据包最大传输单元的数字。它越大,发送数据的速度就越快。假设您可以发送
n
个m
大小的数据包/秒,如果m
增长,m*n
也会增长。我认为您的客户需要该 MTU 是因为其网络设备(可能是以太网 802.3)。有些设备的最大框架尺寸比其他设备更大。
您可以将 ifconfig 与选项
mtu 一起使用
更改其值:ifconfig eth0 mtu 1492
。The MTU is a number which defines the maximum transmission unit per packet. The bigger it is, the faster your data will be sent. Assuming you can send
n
packets/s ofm
size, ifm
grows,m*n
grows too.I think your client wants that MTU because of its network equipment (maybe ethernet 802.3). Some equipment handel biggest frames size than others.
You can use ifconfig with the option
mtu
to change its value:ifconfig eth0 mtu 1492
.设置接口参数的现代方法是通过 sysfs
通过 C,只需打开并写入文件
the modern way to set interface parameters is via sysfs
By C, just open and write as files