12

是否可以在单个 ip 数据包上发送多个 tcp 或 udp 数据包?协议中是否有任何规范不允许这样做。

如果协议允许但 tcp/udp 实现通常不这样做,您能否指出我在 linux 源代码中证明这一点的相关部分。

在某些操作系统上是否有任何 tcp/udp 实现在单个 ip 数据包上发送多个数据包。(如果允许)。

4

6 回答 6

9

这是不可能的

TCP 序列头没有描述它的长度。TCP 有效负载的长度是从 IP 数据包的长度减去 IP 和 TCP 标头的长度得出的。所以每个 IP 数据包只有一个 TCP 段。

然而,相反,单个 TCP 段可以通过 IP 分段在多个 IP 数据包上分段。

于 2010-02-08T10:05:50.527 回答
3

Tcp 不发送数据包:它是一个连续的流。你发送消息。
udp 是基于数据包的,一次只会发送一个数据包。

协议本身不允许这样做。它不会破裂,它只是不会发生。

使用隧道的建议是有效的,但警告也是如此。

于 2010-02-08T10:06:35.297 回答
2

您可能想尝试通过 tcp 建立隧道 tcp,尽管这通常被认为是个坏主意。根据您的需要,您的里程可能会有所不同。

于 2010-02-08T10:07:30.820 回答
2

您可能想查看流控制传输协议,它允许通过单个 TCP 连接的多个数据流。

EDIT - I wasn't aware that TCP doesn't have it's own header field so there would be no way of doing this without writing a custom TCP equivalent that contains this info. SCTP may still be of use though so I'll leave that link.

于 2010-02-08T10:18:42.153 回答
2

TCP is a public specification, why not just read it?

RFC4164 is the roadmap document, RFC793 is TCP itself, and RFC1122 contains some errata and shows how it fits together with the rest of the (IPv4) universe.

But in short, because the TCP header (RFC793 section 3.1) does not have a length field, TCP data extends from the end of the header padding to the end of the IP packet. There is nowhere to put another data segment in the packet.

于 2010-02-08T10:19:40.137 回答
1

You cannot pack several TCP packets into one IP packet - that is a restriction of specification as mentioned above. TCP is the closest API which is application-oriented. Or you want to program sending of raw IP messages? Just tell us, what problem do you want to solve. Think about how you organize the delivery of the messages from one application to another, or mention that you want to hook into TCP/IP stack. What I can suggest you:

  1. Consider packing whatever you like into UDP packet. I am not sure, how easy is to initiate routing of "unpacked" TCP packages on remote side.
  2. Consider using PPTP or similar tunnelling protocol.
于 2010-02-08T10:48:10.050 回答