发送固定长度的帧TCP [英] Sending TCP frames of fixed length

查看:275
本文介绍了发送固定长度的帧TCP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用TCP在子网发送一些数据具有固定非标准的MTU(例如,1560)。
所有通过该子网转移以太网帧应与0的手动填充,如果帧的长度小于MTU。

I need to send some data over the subnet with fixed non-standard MTU (for example, 1560) using TCP. All the Ethernet frames transfered through this subnet should be manually padded with 0's, if the frame's length is less than MTU.

因此​​,数据大小应
(1560 - 的sizeof(IP报头) - 的sizeof(TCP报头))。

So, the data size should be (1560 - sizeof( IP header ) - sizeof( TCP header ) ).

这是我要做到这一点:


  1. 我设置了​​TCP_CORK选项来减少数据的碎片。这是不可靠的,因为有200毫秒的天花板上,但它的作品。

  1. I set the TCP_CORK option to decrease the fragmenting of data. It is not reliable, because there is 200 millisecond ceiling, but it works.

我知道IP报头(20字节)的大小,所以数据长度应该等于(1540 - 的sizeof(TCP报头))

I know size of IP header (20 bytes), so data length should be equal to (1540 - sizeof( TCP header )).

这就是问题所在。我不知道TCP报头大小。它的大小的选项栏是浮动的。

That's the problem. I don't know the TCP header size. The size of it's "Options" field is floating.

所以,问题是:如何让TCP报头的大小?或者,也许有一些方法来发送TCP固定长度的帧的头?

So, the question is: how to get the size of TCP header? Or maybe there is some way to send TCP frames with headers of fixed length?

推荐答案

试图控制帧的大小使用TCP从用户应用程序的时候是错误的。你是在错误的抽象级别工作。这也是不可能的。

Trying to control the size of frames when using TCP from the user application is wrong. You are working at the wrong abstraction level. It's also impossible.

你应该做的是不是考虑用别的东西代替TCP(UDP?),或者不太可能,但可能的,重写你的以太网驱动程序设置非标准MTU和你需要的填充。

What you should be doing is either consider replacing TCP with something else (UDP?) or, less likely, but possible, rewrite your Ethernet driver to set the non standard MTU and do the padding you need.

这篇关于发送固定长度的帧TCP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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