TTL on UDP sockets
-
well, i mentioned TTL for UDP because of portability issues: from what i heard (though i'm no expert in TCP/win), for TCP connections you can't modify the TTL in windows, and thus (if this is true) this feature wouldn't be portable on windows. Sure, if this can be done on raw sockets on windows also (and not only as admin), then why not.
What it's useful for: well, for just about any P2P program that you can think of which needs to traverse NATs: if you need to "break" a NAT, you need to make sure that it first sends a packet and only later receives a reply on a given port (or else you can end up with no connection and, worse, the port may become blocked for N minutes, this depends on the NAT's policy), and you need to do this on both ends of a P2P connection; and the only way to do this is to shoot some pings from one peer towards the other with a short TTL (so that the ping on one side doesn't reach the other side's NAT's port and potentially blocks it)
To rise: no TTL (at least on UDP), no P2P over NATs
CRY FOR HELP to whomever reads this post and considers not being able to write full-fledged P2P/Qt apps important: please rate this post up (the thumbs up icon on the right sidebar on this page) so that we get a chance to be noticed by the Qt developers. I mean, one way or another, P2P apps are the wave of the future, and Qt not supporting such apps out-of-the-box seems pretty much of a big issue to me...
.
-
Oh, i didn't know you need to be root to set TTL on linux. Are you sure about that? You mean 'traceroute' won't work from a non-root account? Or is 'treaceroute' implemented in two layers, with a non-root "client" and a root daemon which does the actual pinging with variable TTL? Maybe you can tell me a bit about what you know about this, or maybe point me to a reference doc which unequivocally specifies that you need to be root?
-
I always like this kind of questions because they make you dig a bit in networking code (and discard what is written in books): I figured out I was wrong.
Linux lets unprivileged users manipulate the TTL field for a socket, using setsockopt(2) with IP_TTL. So just fetch the descriptor from QUdpSocket and call setsockopt on it :)
-
K dude, i love you :-) 10x!
PS
Still, what i said earlier about having a property directly in the Qt socket class (at least for UDP) would definitely be nice, so i'll leave my "cry for help" there, maybe the Qt developers will take notice (yeah, that's a pretty long shot for chasing a short TTL, i know :)