<h1 id="theory">Theory</h1>
<p>In this episode I decided to take a slight diversion into networking fundamentals. As before, if you want to learn more about installing the ONICS tool suite, go back and listen to HPR 2882.</p>
<p>There are three key concepts to understand about modern networks. They are:</p>
<ul>
<li><p>digital - the networks carry bits and bytes (binary digits)</p></li>
<li><p>packet switched - devices break data into blobs of data called &quot;packets&quot; and take turns sending and receiving those packets to/from other devices attached to the network</p></li>
<li><p>internetworked -- machines communicate using a protocol that allows traffic to traverse across multiple, independently-managed networks in a uniform way</p></li>
</ul>
<h1 id="my-setup">My Setup</h1>
<ul>
<li><p>2 laptops connected to a home wifi network that has Internet connectivity.</p></li>
<li><p>Practicing sending data from a source machine to a destination machine. Both are running Linux.</p></li>
<li><p>Source machine:</p>
<ul>
<li>Wifi interface: wlan0</li>
<li>Ethernet address: 00:22:fa:a7:69:90</li>
<li>IP address: 192.168.0.4</li>
</ul></li>
<li><p>Destination machine</p>
<ul>
<li>Wifi interface: wlo1</li>
<li>Ethernet address: 6c:88:14:7c:2e:14</li>
<li>IP address: 192.168.0.248</li>
</ul></li>
<li><p>Internet Router:</p>
<ul>
<li>Ethernet address: 00:0d:b9:23:f2:51</li>
<li>IP address: 192.168.0.1</li>
</ul></li>
</ul>
<h1 id="more-terminology">More Terminology</h1>
<ul>
<li><p>Address - a number that identifies a machine's interface in a network</p></li>
<li><p>Packet - a blob of binary data sent as a unit over a network</p></li>
<li><p>Route - a rule that specifies how to forward traffic to a given address</p></li>
<li><p>Router / Gateway - a machine that uses the IP protocol and forwards traffic between multiple networks that it connects to</p></li>
<li><p>Network Protocol - a set of rules and data formats for exchanging information over a network</p></li>
</ul>
<h1 id="standard-unix-commands">Standard UNIX Commands</h1>
<ul>
<li>ifconfig (no arguments or '-a')
<ul>
<li>list interfaces on a machine</li>
</ul></li>
<li>ifconfig IFNAME
<ul>
<li>list properites about a given interface</li>
</ul></li>
<li>ping -c 1 IPADDRESS
<ul>
<li>send an echo request to machine IPADDRESS</li>
</ul></li>
<li>arp -na
<ul>
<li>Dump the Ethernet addresses of known nearby machines</li>
</ul></li>
<li>netstat -nr
<ul>
<li>Dump the routes in a system</li>
</ul></li>
<li>netstat -nr | grep &quot;^0.0.0.0&quot;
<ul>
<li>Find the route (and thus IP address) of the default gateway</li>
</ul></li>
</ul>
<h1 id="onics-commands-in-this-episode">ONICS Commands in this Episode</h1>
<ul>
<li><p>rawpkt - take a blob of data and wrap it in an XPKT format (so other ONICS tools can understand what it is)</p></li>
<li><p>ethwrap - take an XPKT and prepend an Ethernet header to it</p></li>
<li><p>ipwrap - take an XPKT and prepend an IP header to it</p></li>
<li><p>pktin - read a stream of packets from a network interface</p></li>
<li><p>pflt - filter a stream of packets so that only those matching a pattern get through</p></li>
<li><p>pktout - send a stream of packets to a network interface</p></li>
<li><p>x2hpkt - convert XPKTs into a hex dump</p></li>
<li><p>xpktdump - like x2hpkt, but send the output to a pager like 'less' for easy reading</p></li>
</ul>
<h1 id="sending-an-ethernet-packet-to-the-destination">Sending an Ethernet Packet to the Destination</h1>
<ul>
<li>On the receiver:</li>
</ul>
<pre><code>    $ sudo pktin wlo1 |
      pflt &quot;not ip and eth.dst == 6c:88:14:7c:2e:14&quot; |
      x2hpkt
</code></pre>
<ul>
<li>On the sender:</li>
</ul>
<pre><code>    $ echo &quot;hello world&quot; |
      rawpkt |
      ethwrap &quot;eth.dst = 6c:88:14:7c:2e:14; &quot;
              &quot;eth.src = 00:22:fa:a7:69:90; &quot;
              &quot;eth.ethtype = 12;&quot; |
      sudo pktout wlan0
</code></pre>
<p>Note that while I broke up the field setting commands into multiple lines in ethwrap, they can all be part of a single quoted string if desired. To store the packet to a file rather than send it instead do something</p>
<pre><code>$ echo ... | rawpkt | ethwrap ... &gt; outfile.xpkt
</code></pre>
<p>One can then dump the packet by running:</p>
<pre><code>$ xpktdump outfile.xpkt
</code></pre>
<p>or send the packet by running:</p>
<pre><code>$ sudo pktout outfile.xpkt wlan0
</code></pre>
<h1 id="sending-an-ip-packet-to-the-destination-over-the-local-network">Sending an IP Packet to the Destination over the Local Network</h1>
<ul>
<li>On the reciever:</li>
</ul>
<pre><code>    $ sudo pktin wlo1 |
      pflt &quot;ip and ip.proto == 255&quot; |
      x2hpkt
</code></pre>
<ul>
<li>On the sender:</li>
</ul>
<pre><code>    $ echo &quot;hello world&quot; |
      rawpkt |
      ipwrap &quot;ip.saddr = 192.168.0.4;&quot;
             &quot;ip.daddr = 192.168.0.248;&quot;
             &quot;ip.len = 32;&quot;
             &quot;ip.ttl = 64;&quot;
             &quot;ip.proto = 255;&quot; |
      ethwrap &quot;eth.dst = 6c:88:14:7c:2e:14; &quot;
              &quot;eth.src = 00:22:fa:a7:69:90; &quot;
              &quot;eth.ethtype = 0x800;&quot; |
      sudo pktout wlan0
</code></pre>
<p>Note that while I broke up the field setting commands into multiple lines in ipwrap and ethwrap, they can all be part of a single quoted string if desired. Also note that it is not actually necessary to set the 'ip.len' and 'eth.ethtype' fields: the tools will do that automatically.</p>
<h1 id="sending-an-ip-packet-to-the-destination-via-ip">Sending an IP Packet to the Destination via IP</h1>
<ul>
<li>On the receiver:</li>
</ul>
<pre><code>    $ sudo pktin wlo1 |
      pflt &quot;ip and ip.proto == 255&quot; |
      x2hpkt
</code></pre>
<ul>
<li>One the sender:</li>
</ul>
<pre><code>    $ echo &quot;hello world&quot; |
      rawpkt |
      ipwrap &quot;ip.saddr = 192.168.0.4;&quot;
             &quot;ip.daddr = 192.168.0.248;&quot;
             &quot;ip.ttl = 64;&quot;
             &quot;ip.proto = 255;&quot; |
      ethwrap &quot;eth.dst = 00:0d:b9:23:f2:51; &quot;
              &quot;eth.src = 00:22:fa:a7:69:90; &quot; |
      sudo pktout wlan0
</code></pre>
<h1 id="challenge">Challenge</h1>
<p>There are several differences between the packets that arrive at the destination machine when sending directly over the local network versus sending via an IP gateway (router). I've mentioned how the Ethernet header is different. Can you find the other differences? What causes these differences?</p>
<p>TIP: instead of sending the <code>pktin</code> command to x2hpkt, send it to a file. Do this for both local network send and for sending via the router saving each to different files. Then run <code>pdiff</code> on the two files to highlight the differences.</p>
