13

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).

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
Rohit Banga
  • 18,458
  • 31
  • 113
  • 191

6 Answers6

9

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
  • 73,905
  • 40
  • 169
  • 246
3

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.

IAbstract
  • 19,551
  • 15
  • 98
  • 146
  • 1
    but ultimately a tcp segment is sent by extracting data from a byte stream. – Rohit Banga Feb 08 '10 at 10:07
  • 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. – Rohit Banga Feb 08 '10 at 10:09
3

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.

Community
  • 1
  • 1
Andrew McGregor
  • 31,730
  • 2
  • 29
  • 28
2

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
  • 3,483
  • 4
  • 29
  • 50
2

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
  • 22,188
  • 6
  • 42
  • 49
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.
dma_k
  • 10,431
  • 16
  • 76
  • 128
  • 1
    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! – Rohit Banga Feb 08 '10 at 12:47
  • What about UDP, it does have length field in it's header right ? If allowed receiver seems to be having no issue in finding out the individual packets, Isn't it ? – Dhanaraj Durairaj Jul 29 '14 at 09:51
  • @RohitBanga: In that respect indeed TCP header does not have `length` field with the size of of the data. It relies on underlying transport protocol that (AFAIK) always have it. So there is no need to add yet another redundant value. – dma_k Aug 26 '14 at 09:12
  • 1
    @DhanarajDurairaj: Yes, UDP has length, checkout [wikipedia](http://en.wikipedia.org/wiki/User_Datagram_Protocol#Packet_structure). However TCP and UDP serve different matters: they can't be mixed. They are two branches on the top of IP: TCP is for sequential streaming of data, UDP is for short message exchange where order does not matter a lot. – dma_k Aug 26 '14 at 09:15