Tracing Connections, Multiplayer Debugging

BlitzMax Forums/BlitzMax Programming/Tracing Connections, Multiplayer Debugging

Banshee(Posted 2006) [#1]
I'd like to build in the ability to trace all the ip's along a route and ping them, in order to build in network play debugging infomation directly into the game.

Looking through the Blitz socket commands I can only see how to resolve the IP of each machine in the game, is it possible to resolve the IP of machines on the route too?

It's multiplatform: PC & OSX, so piping a DOS call to tracert wont work on the Mac :(


Pantheon(Posted 2006) [#2]
You want some technique like Tracert?

This method works by sending repeated ping packets to the host. Each packet has its Time To Live (TTL) field starting at 1 and increasing till the destination host responds.

I will try and draw an ASCII diagram :)

L---->N1---->N2---->D

L - Local Host (Your Computer)
N1/2 - Nodes (Routers)
D - Destination

L sends a ping packet with destination IP (and MAC) address set to that of D. The TTL field of the ping packet is set to 1. When N1 recives the packet it decrements the TTL field by 1 (This happens for any network interface that recives a packet). When it looks at the packet a check is made to the TTL field, seeing that it has a value of 0 it discards the packet and sends a ICMP (Internet Command Protocol?) message back to the original sender (TTL field will be some operating system default like 64 or something large). (I cant remember the type of ICMP packet that is sent back but it basicly says that the packet timed out).

Your app would at this point check for that recived ICMP packet and you can then extract the IP, MAC address, etc from it and that would be N1 in the diagram.

If you set the TTL field to 2 then it will become 0 by the time N2 recives it and you will get an ICMP packet eminating from that host and you can extract the IP, etc once again. After a third time you get a packet (ICMP echo?) that you can see is from the desination host.

So in answer to your question, I dont think you can do this from within BlitzMax without using a new network library. BlitzMax networking library cant generate ICMP packets (especialy with changed fields).

You would need to use RAW sockets or LIBnet. The only drawback of LIBnet is that you would have to import all the functions and im sure that its object orientated. LIBnet is also cross platform compatable :)
http://libnet.sourceforge.net/#download

Raw sockets have also been Excluded/ScaledDown from windows with the introduction of Service Pack 2.

WindowsXP machines also by default will not send out ICMP packets in response to recived ones (windows Firewall). If you did tracert then you see like:

***.***.***.***

Under that nodes heading.

So it should be quite a large problem to solve in terms of effort.

If you get anywhere then I would love to know.


Banshee(Posted 2006) [#3]
I've found on the Mac that there is a similar command to tracert on the PC, 'traceroute' infact it can also pipe out to a file, so:

traceroute www.simtouringcarcup.com >myTrace.txt

will create a file called myTrace.txt with the results of the traceroute, GREAT!

However, I cannot figure out how to call this from the program , i'm using OpenURL at the moment and it just doesn't work at all and I dont really know why. I need it to launch traceroute and then silently exit, does anyone have any ideas please?


xlsior(Posted 2006) [#4]
However, I cannot figure out how to call this from the program , i'm using OpenURL at the moment and it just doesn't work at all and I dont really know why. I need it to launch traceroute and then silently exit, does anyone have any ideas please?


A couple of ways:

system_("traceroute www.simtouringcarcup.com >mytrace.txt")


But that will halt your program until the traceroute finishes.

Check out the pub.mod/freeprocess.mod , it allows you to launch a process while your program keeps running, which is probably better suited to what you want.

See below for a sample of how to use it... Unfortunately I don't remember who posted it to the forums recently, so apologies for the lack of attribution. :-?
You'll need some minor adjustments to run it on the Mac, but it will probably be a good start)




traceroute www.simtouringcarcup.com >myTrace.txt


One downside is that this is an external utility, which may or may not exist, and the current user may or may not have permissions to use the binary if it does exist... Which means you may also need to distribute one along with your program to make sure it 'always' works.

Unfortunately ping (and traceroute, which is nothing but a series of pings with a specified max number of hops, as explained by Pantheon above) uses a specifically crafted type of datapacket which BlitzMax natively does not provide.

Perhaps a good feature request -- some basic PING commands?


Banshee(Posted 2006) [#5]
woohoo, there's a system_ pipe? WOOOOO so much I can do now! Thank you :).

This simpler solution suits perfectly, even though it causes a mommentary hangup, I dont mind as it's only used whilst debugging a connection although I might look at the other method before going final.

Thank you so much. :D

*virtual hug*


xlsior(Posted 2006) [#6]
woohoo, there's a system_ pipe? WOOOOO so much I can do now! Thank you :).


Yeah, I wouldn't have known about it either if I hadn't seen it come by on these forums a while back.

the Blitzmax docs aren't as clear as they could be, unfortunately.


FlameDuck(Posted 2006) [#7]
Historical note. It's only called 'tracert' on the PC because of archaic filesystems. Anyhow:

I'd like to build in the ability to trace all the ip's along a route and ping them, in order to build in network play debugging infomation directly into the game.
Due to the connectionless nature of packet switched networks (as opposed to circuit switched networks) this isn't exactly possible.

uses a specifically crafted type of datapacket which BlitzMax natively does not provide.
Really? I thought BlitzMAX exposed all BSD socket functionality (or possibly WinSock on Windows).