mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-29 08:46:31 +00:00
107 lines
9.1 KiB
HTML
Executable file
107 lines
9.1 KiB
HTML
Executable file
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
|
|
<meta name="generator" content="ZealOS V1.07">
|
|
<style type="text/css">
|
|
body {background-color:#1f1f1f;}
|
|
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
|
|
.cF1{color:#4f84a6;background-color:#1f1f1f;}
|
|
.cF2{color:#73a255;background-color:#1f1f1f;}
|
|
.cF3{color:#297582;background-color:#1f1f1f;}
|
|
.cF4{color:#b34f4b;background-color:#1f1f1f;}
|
|
.cF5{color:#8a52c3;background-color:#1f1f1f;}
|
|
.cF6{color:#b7822f;background-color:#1f1f1f;}
|
|
.cF7{color:#444444;background-color:#1f1f1f;}
|
|
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
|
|
.cF9{color:#94bfde;background-color:#1f1f1f;}
|
|
.cFA{color:#a1ce97;background-color:#1f1f1f;}
|
|
.cFB{color:#6db4be;background-color:#1f1f1f;}
|
|
.cFC{color:#e88e88;background-color:#1f1f1f;}
|
|
.cFD{color:#ca94e8;background-color:#1f1f1f;}
|
|
.cFE{color:#d4b475;background-color:#1f1f1f;}
|
|
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<pre style="font-family:monospace;font-size:12pt">
|
|
<a name="l1"></a><span class=cF9>I64</span><span class=cF0> Ping(</span><span class=cF1>U8</span><span class=cF0> *hostname, </span><span class=cF9>I64</span><span class=cF0> timeout=</span><span class=cF3>JIFFY_FREQ</span><span class=cF0>)
|
|
<a name="l2"></a>{
|
|
<a name="l3"></a> </span><span class=cF9>U32</span><span class=cF0> addr;
|
|
<a name="l4"></a> CAddressInfo *current;
|
|
<a name="l5"></a> CAddressInfo *result = </span><span class=cF3>NULL</span><span class=cF0>;
|
|
<a name="l6"></a> </span><span class=cF9>I64</span><span class=cF0> error;
|
|
<a name="l7"></a> </span><span class=cF9>I64</span><span class=cF0> i = </span><span class=cFE>0</span><span class=cF0>, t, delay, sent = </span><span class=cFE>0</span><span class=cF0>, min_delay = </span><span class=cF3>I64_MAX</span><span class=cF0>, max_delay = </span><span class=cF3>I64_MIN</span><span class=cF0>, sum_delay = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l8"></a> CSocketAddressIPV4 *ipv4_address;
|
|
<a name="l9"></a> </span><span class=cF9>U16</span><span class=cF0> sequence_number = </span><span class=cFE>1</span><span class=cF0>, identifier = </span><span class=cF5>RandU16</span><span class=cF0>, count = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l10"></a> </span><span class=cF1>U8</span><span class=cF0> *payload;
|
|
<a name="l11"></a>
|
|
<a name="l12"></a> </span><span class=cF1>if</span><span class=cF0> (!IPV4AddressParse</span><span class=cF7>(</span><span class=cF0>hostname, &addr</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l13"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l14"></a> error = DNSAddressInfoGet(hostname, </span><span class=cF3>NULL</span><span class=cF0>, &result);
|
|
<a name="l15"></a> </span><span class=cF1>if</span><span class=cF0> (error < </span><span class=cFE>0</span><span class=cF0>)
|
|
<a name="l16"></a> {
|
|
<a name="l17"></a> NetErr(</span><span class=cF6>"Ping: Failed at DNS Get Address Info."</span><span class=cF0>);
|
|
<a name="l18"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
|
|
<a name="l19"></a> }
|
|
<a name="l20"></a> current = result;
|
|
<a name="l21"></a> </span><span class=cF1>while</span><span class=cF0> (current)
|
|
<a name="l22"></a> {
|
|
<a name="l23"></a> </span><span class=cF1>if</span><span class=cF0> (current->family == AF_INET)
|
|
<a name="l24"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l25"></a> ipv4_address = current->address;
|
|
<a name="l26"></a> addr = </span><span class=cF5>EndianU32</span><span class=cF0>(ipv4_address->address); </span><span class=cF2>// why does it need EndianU32</span><span class=cF0>
|
|
<a name="l27"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l28"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l29"></a> current = current->next;
|
|
<a name="l30"></a> }
|
|
<a name="l31"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l32"></a>
|
|
<a name="l33"></a> </span><span class=cF1>if</span><span class=cF0> (!current)
|
|
<a name="l34"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l35"></a> NetErr(</span><span class=cF6>"Ping: Failed to resolve address."</span><span class=cF0>);
|
|
<a name="l36"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
|
|
<a name="l37"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l38"></a>
|
|
<a name="l39"></a> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cF5>CharScan</span><span class=cF0>)
|
|
<a name="l40"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l41"></a> payload = </span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cFE>64</span><span class=cF0>);
|
|
<a name="l42"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < </span><span class=cFE>64</span><span class=cF0>; i++)
|
|
<a name="l43"></a> payload[i] = </span><span class=cF5>RandU8</span><span class=cF0>;
|
|
<a name="l44"></a>
|
|
<a name="l45"></a> </span><span class=cF6>"Sending Ping request #%d\n"</span><span class=cF0>, sequence_number;
|
|
<a name="l46"></a> ICMPRequestSend(addr, identifier, </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>sequence_number</span><span class=cF7>)</span><span class=cF0>, payload, </span><span class=cFE>64</span><span class=cF0>);
|
|
<a name="l47"></a> sent++;
|
|
<a name="l48"></a>
|
|
<a name="l49"></a> t = </span><span class=cFB>counts</span><span class=cF0>.jiffies;
|
|
<a name="l50"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cFB>counts</span><span class=cF0>.jiffies < t + timeout)
|
|
<a name="l51"></a> {
|
|
<a name="l52"></a> </span><span class=cF1>if</span><span class=cF0> (icmp_reply.identifier == identifier && icmp_reply.sequence_number == </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>sequence_number</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l53"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l54"></a> delay = </span><span class=cFB>counts</span><span class=cF0>.jiffies - t;
|
|
<a name="l55"></a> min_delay = </span><span class=cF5>MinI64</span><span class=cF0>(min_delay, delay);
|
|
<a name="l56"></a> max_delay = </span><span class=cF5>MaxI64</span><span class=cF0>(max_delay, delay);
|
|
<a name="l57"></a> sum_delay += delay; </span><span class=cF2>// sum up delays, divide through by count during stat report to get average</span><span class=cF0>
|
|
<a name="l58"></a> count++;
|
|
<a name="l59"></a> </span><span class=cF6>"\tReceived reply, delay: %dms\n"</span><span class=cF0>, delay;
|
|
<a name="l60"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l61"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l62"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0>);
|
|
<a name="l63"></a> }
|
|
<a name="l64"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cFB>counts</span><span class=cF0>.jiffies < t + </span><span class=cF3>JIFFY_FREQ</span><span class=cF0>)
|
|
<a name="l65"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0>);
|
|
<a name="l66"></a>
|
|
<a name="l67"></a> sequence_number++;
|
|
<a name="l68"></a> </span><span class=cF5>Free</span><span class=cF0>(payload);
|
|
<a name="l69"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l70"></a>
|
|
<a name="l71"></a> </span><span class=cF6>"\nPing Statistics:\n"</span><span class=cF0>;
|
|
<a name="l72"></a> </span><span class=cF6>"\tSent: %d, Received: %d, Lost: %d (%0.02f %%)\n"</span><span class=cF0>, sent, count, sent - count, </span><span class=cFE>100</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0> - </span><span class=cFE>100</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0> * count / sent;
|
|
<a name="l73"></a> </span><span class=cF1>if</span><span class=cF0> (min_delay != </span><span class=cF3>I64_MAX</span><span class=cF0> && max_delay != </span><span class=cF3>I64_MIN</span><span class=cF0> && sum_delay != </span><span class=cFE>0</span><span class=cF0>)
|
|
<a name="l74"></a> </span><span class=cF6>"\tMin: %dms, Max: %dms, Avg: %dms\n"</span><span class=cF0>, min_delay, max_delay, sum_delay / count;
|
|
<a name="l75"></a> </span><span class=cF6>"\n"</span><span class=cF0>;
|
|
<a name="l76"></a>
|
|
<a name="l77"></a> </span><span class=cF1>return</span><span class=cF0> count;
|
|
<a name="l78"></a>
|
|
<a name="l79"></a>}</span></pre></body>
|
|
</html>
|