<p>Finding distance by time taken would be inaccurate with WiFi due to the fact that it uses Csma Ca (Inet/linklayer/csmaca). Its is technically a queue for the host to wait for it's time to send to the AP and for the AP to broadcast the message.
This report has a great write up on the Impact of csmaca <a href="https://arxiv.org/pdf/1609.04604.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/1609.04604.pdf</a></p>

<p>You would have to create your own linklayer if you want to calculate the distance by speed. </p>
How do i calculate the distance between two nodes using time taken for the packet to be sent across?
<p>Let's say I have two nodes, one sends a packet across to the other node. How do i calculate the distance between them using the time taken? I'm pretty sure I have to use the distance = speed*time formula, which I am. My code is as follows</p>

<p><strong>Node1.cc</strong></p>

<pre><code>socket.sendTo(payload, destAddr, destPort);
    auto const result = SEND_TIME_HISTORY.insert(std::make_pair(numSent, simTime().dbl()));
            if (not result.second) {
                result.first-&gt;second = simTime().dbl();
            }
</code></pre>

<p>What that does is basically each time it sends a packet it stores its current simTime and sequence number inside a map, so im sure that im calculating from the correct sequence of packets</p>

<p><strong>Node2.cc</strong></p>

<pre><code>map&lt;int, double&gt; SENT_TIME_HISTORY =
                Node1-&gt;returnTimeHistory(); //basicaly retrieve the map
        for (std::map&lt;int, double&gt;::iterator iter = SENT_TIME_HISTORY.begin();
                iter != SENT_TIME_HISTORY.end(); iter++) {

            //iterate through and check if the received sequence number matches the sent sequence number
            if (rcvseq == iter-&gt;first){

                //host_currenttime is simTime().dbl() as soon as the packet is received
                timediff = host_currenttime - iter-&gt;second; 
                cout &lt;&lt; "Time received: " &lt;&lt; host_currenttime &lt;&lt; "\tTime sent: " &lt;&lt; iter-&gt;second &lt;&lt;"\tActual time taken" &lt;&lt; timediff &lt;&lt; endl;
            }
        }
cout &lt;&lt; "Calculated distance: " &lt;&lt; timediff*299792458 &lt;&lt; endl;
</code></pre>

<p>Basically the output is rubbish. Right now I am taking the time taken for the packet to be sent across multiplied by the speed of light to determine the distance. Am I doing something wrong here? </p>

<p>If more source code is necessary please do inform me. Thanks in advance!</p>