views:

355

answers:

6

is it possible to send multiple tcp or udp packets on a single ip packet? are there any specifications in the protocol that do not allow this.

if it is allowed by the protocol but is generally not done by tcp/udp implementations could you point me to the relevant portion in the linux source code that proves this.

are there any implementations of tcp/udp on some os that do send multiple packets on a single ip packet. (if it is allowed).

+3  A: 

It is not possible.

The TCP seqment header does not describe its length. The length of the TCP payload is derived from the length of the IP packet(s) minus the length of the IP and TCP headers. So only one TCP segment per IP packet.

Conversely, however, a single TCP segment can be fragmented over several IP packets by IP fragmentation.

Will
that is where i got this idea from!
iamrohitbanga
wanted to confirm if this is specified in the protocol.
iamrohitbanga
In TCP they're called "segments", not "packets".
caf
@caf changed, but 50/50 if it's more understandable
Will
+1  A: 

Tcp doesn't send packets: it is a continuous stream. You send messages.
Udp, being packet based, will only send one packet at a time.

The protocol itself does not allow it. It won't break, it just won't happen.

The suggestion to use tunneling is valid, but so is the warning.

dboarman
but ultimately a tcp segment is sent by extracting data from a byte stream.
iamrohitbanga
are you basing your answer on the basis of implementations or the protocol does not allow it. would something break if we have an implementation that sends more than one tcp segment inside an ip packet.
iamrohitbanga
+2  A: 

You might want to try tunneling tcp over tcp, although it's generally considered a bad idea. Depending on your needs, your mileage may vary.

lorenzog
+2  A: 

You may want to take a look at the Stream Control Transmission Protocol which allows multiple data streams across a single TCP connection.

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.

Paolo
+1  A: 

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.

Andrew McGregor
+1  A: 

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.
dma_k
this question arose because i noticed that there was no length of TCP segment field in the TCP header. that is why i wanted to confirm. thanks a lot!
iamrohitbanga