1

The RFP for TFTP says that TID's in most circumstances:

should be randomly chosen, so that the probability that the same number is chosen twice in immediate succession is very low.

The thing is, these "TID"s are also used as UDP port numbers. But a typical network interface cannot just be dedicated for TFTP use. Some ports are liable to be in use, and others should essentially be "reserved" for specific applications. I'm not even sure where a program could go to look up this information at runtime.

So how is a TFTP implementation supposed to deal with this?

T.E.D.
  • 44,016
  • 10
  • 73
  • 134

1 Answers1

2

Since the host selecting the TID/port is the one opening it and telling the other party which one it's opened, you can simply try to open the port; if it's already in use or otherwise unavailable, this will fail, and you can re-try with a different port. (Note that since UDP and TCP are difference protocols, a TCP application and a UDP application can both be using the "same" port, since they are not, in fact, the same at all!) Do this in a simple loop until you find a "good" one. (Probably best to define a maximum number of tries and simply fail the connection if that's met before a good port is found, as this could be a sign of other issues that prohibit this from working at all.)

Stick to the ephemeral port range to play nice with best practices, although note that different systems define different ranges for this purpose. You could pick the range suitable to your system, or simply try to use a port above the "well-known" port range (i.e. above 1024); this may not give you an "ephemeral port" per se for your system, but so long as you can open it it should work fine.

Kromey
  • 1,202
  • 1
  • 10
  • 13
  • OK, now that you mention this, it looks like the Wikipedia [page for TFTP](http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol#Overview) does say the ephemeral ports are typically used. I've never mucked with those kinds of dynamic ports before. I take it the typical algorithm for that is, like you said, try to open it and see if it fails until you get a good one? – T.E.D. Mar 25 '14 at 19:25
  • That would be both my assumption, and how I would implement such a system myself were I to do so. – Kromey Mar 25 '14 at 19:27