MTU Investigator using Whidbey and the Ping class
I previously posted a TraceRoute utility, this time I figured I'd do a little MTU investigator. In most cases your MTU is going to be throttle by your local box or your DSL/Router unit, so adding this to the TraceRoute utility really isn't that good of an idea since it takes a good deal of time to run an MTU ping. I guess you could have the algorithm start at a high number (say 1500), and then make revisions up or down depending on the result until it finds the *threshhold*. This type of dual direction algorithm would let you find the MTU very quickly. I went the easy route though.
Strangely enough, Whidbey still doesn't have any cool graphing controls built into Windows Forms, else I'd toss something graphical out. I do have one more Ping utility planned though, and it focuses on a common ping scenario, so stay tuned.
class MTUPing {
private static Ping pinger = new Ping();
public static int PingForMTU( int startSize, int incSize, IPAddress endPoint ) {
if ( incSize < 0 ) { incSize = -incSize; }
if ( incSize == 0 ) { incSize = 10; }
bool complete = false;
while ( !complete ) {
PingReply reply = pinger.Send( endPoint, new byte[startSize], 5000, new PingOptions( 128, true ) );
if ( reply.Status == IPStatus.PacketTooBig ) {
int reviseSize = startSize;
startSize -= incSize;
while ( startSize < reviseSize ) {
reply = pinger.Send( endPoint, new byte[startSize + 1], 5000, new PingOptions( 128, true ) );
if ( reply.Status == IPStatus.PacketTooBig ) { break; }
startSize++;
}
break;
}
startSize += incSize;
}
return startSize;
}
}