<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kognise</title>
    <description>The latest articles on Forem by Kognise (@kognise).</description>
    <link>https://forem.com/kognise</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F131661%2F9516814b-9567-428a-94f3-c5eade20c0ea.png</url>
      <title>Forem: Kognise</title>
      <link>https://forem.com/kognise</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kognise"/>
    <language>en</language>
    <item>
      <title>Building a Transport Protocol on ARP</title>
      <dc:creator>Kognise</dc:creator>
      <pubDate>Tue, 29 Mar 2022 19:32:07 +0000</pubDate>
      <link>https://forem.com/kognise/building-a-transport-protocol-on-arp-2pj4</link>
      <guid>https://forem.com/kognise/building-a-transport-protocol-on-arp-2pj4</guid>
      <description>&lt;p&gt;The other day I was sick and bored. With nothing better to do, I spent a day building &lt;a href="https://github.com/kognise/arpchat"&gt;ArpChat&lt;/a&gt;, a slightly-cursed chat app entirely running on ARP.&lt;/p&gt;

&lt;p&gt;Several people have asked me how ArpChat works behind the scenes, so I thought I would write a quick post. While building it wasn't particularly novel for me, you might learn something new if you're new to networking!&lt;/p&gt;

&lt;p&gt;A quick note: when I say "IP" throughout this article, I'm referring to IPv4. Near the end, I'll go over IPv6 and its position in the networking stack.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Primer: The OSI Model &amp;amp; Why We Need ARP
&lt;/h2&gt;

&lt;p&gt;Computer-to-computer communication is &lt;em&gt;tremendously&lt;/em&gt; complicated; you can get a degree in this stuff! HTTP, the protocol you're using to access this website, runs on another protocol called TCP. TCP, in turn, builds upon IP, the general standard for sending data over the internet. IP itself is many layers of abstraction above the 1s and 0s transmitted over a physical medium.&lt;/p&gt;

&lt;p&gt;Historically, computer scientists have organized all these "layers" of communication using a system known as the &lt;em&gt;&lt;a href="https://en.wikipedia.org/wiki/OSI_model#Layer_architecture"&gt;OSI model&lt;/a&gt;&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;At the lowest level is the &lt;em&gt;physical layer&lt;/em&gt;; computers need to transmit binary data in the real world somehow! Typically, a chip in your computer will send electricity over an ethernet cable or transmit radio waves through the air.&lt;/li&gt;
&lt;li&gt;Above this is the &lt;em&gt;data link layer&lt;/em&gt;, which makes sure that the signals that network cards send to each other will reach the right physical destination.

&lt;ul&gt;
&lt;li&gt;On wired connections, &lt;a href="https://en.wikipedia.org/wiki/Network_switch"&gt;ethernet switches&lt;/a&gt; work on the data link layer to retransmit incoming signals on the right output cable. If you have a home router, it probably has a built-in switch.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/Wireless_access_point"&gt;Wireless access points&lt;/a&gt; serve to allow devices to connect to a wired network through radio waves.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;One abstraction up from the data link layer is the &lt;em&gt;network layer&lt;/em&gt;. This creates a conceptual "network" of nodes (devices) by providing a convenient way to route messages. &lt;em&gt;IP&lt;/em&gt;, the internet protocol, is by far the most common standard for the network layer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main identifier for nodes on the network layer is an &lt;em&gt;IP address&lt;/em&gt;. IP addresses can change, and aren't assigned to any specific piece of hardware— if you switch the network your computer is on, your IP address will probably change as well. Meanwhile, &lt;em&gt;&lt;a href="https://en.wikipedia.org/wiki/MAC_address"&gt;MAC addresses&lt;/a&gt;&lt;/em&gt; are the main identifier on the data link layer. They're assigned to a specific network chip in a computer and don't change.&lt;/p&gt;

&lt;p&gt;When sending a message on the network layer, your computer needs to drop down to the data link layer to make sure packets reach the right device. That means there must be a way to find a MAC address for a given IP address— we call this protocol &lt;em&gt;ARP&lt;/em&gt;, an initialism for address resolution protocol.&lt;/p&gt;

&lt;p&gt;With ARP, Computer A can send a request to every computer in the area with an IP address. If another computer recognizes the IP as its own, it can respond with the corresponding MAC address. When Computer A receives the response, it knows how to send its original message along the data link layer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7BmTlyOx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://doggo.ninja/2nFU8H.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7BmTlyOx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://doggo.ninja/2nFU8H.png" alt="ARP exchange example" width="880" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, what if we sent nonsense instead? Well, the packet will still go through but every computer on the network will ignore it. Imagine the things one could do...&lt;/p&gt;

&lt;h2&gt;
  
  
  How Does ArpChat Abuse ARP?
&lt;/h2&gt;

&lt;p&gt;ARP is a "layer 3" protocol. This means a layer 2 (physical layer) packet has to wrap every ARP packet; we'll include our data in an "ethernet" packet format designed for both Wi-Fi and wired ethernet.&lt;/p&gt;

&lt;p&gt;Our ethernet packet will be super simple. First, we include the destination MAC address— since we want to send our packet to everyone, this will be a special value called the broadcast address, &lt;code&gt;ff:ff:ff:ff:ff:ff&lt;/code&gt;. Switches should forward broadcast packets to every device they know about.&lt;/p&gt;

&lt;p&gt;For the remaining fields, we include our source MAC address and specify that the packet contained is of the ARP &lt;a href="https://en.wikipedia.org/wiki/EtherType"&gt;EtherType&lt;/a&gt;. At the end, we append our ARP data. We can leave the remaining optional fields empty.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dZM4tEz4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://doggo.ninja/iCwber.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dZM4tEz4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://doggo.ninja/iCwber.png" alt="Ethernet packet diagram" width="688" height="615"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ARP Packet
&lt;/h3&gt;

&lt;p&gt;We'll be sending what's known as a &lt;em&gt;gratuitous ARP&lt;/em&gt; packet. When changing IPs or joining a new network, devices will often announce their presence to other devices on the network; due to their nature as good-faith announcements, gratuitous ARP packets tend to have high deliverability.&lt;/p&gt;

&lt;p&gt;The standard requires that ARP packets have the following fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hardware and Protocol Type: the kind of data link and network layer our ARP message relates to. In our case, these are ethernet and IPv4 respectively.&lt;/li&gt;
&lt;li&gt;Hardware Address Length: we're complying with this aspect of ARP so we'll specify the length of a MAC address, 6 bytes.&lt;/li&gt;
&lt;li&gt;Protocol Address Length: this would normally be 4 bytes, the length of an IP address. Instead, we're going to deviate from "proper" ARP— since we want to send more information than just an IP address, we'll specify the length of our data instead.&lt;/li&gt;
&lt;li&gt;Operation: this designates the packet as either request or a reply. According to one convention, gratuitous ARP packets are requests.&lt;/li&gt;
&lt;li&gt;We'll fill the Sender Hardware Address with our MAC address, and the Sender Protocol Address with our data.&lt;/li&gt;
&lt;li&gt;For the Target Hardware Address we'll specify an all-zero MAC address, &lt;code&gt;00:00:00:00:00:00&lt;/code&gt;, and we'll include a duplicate of our data in the last field, Target Protocol Address. These are both conventions of gratuitous ARP messages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we can pull out the good ol' Rust compiler and write &lt;a href="https://github.com/kognise/arpchat/blob/main/src/net.rs#L215-L238"&gt;a bit of networking code&lt;/a&gt; to send arbitrary data over ARP!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fcUeeExA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://doggo.ninja/HPvMK4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fcUeeExA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://doggo.ninja/HPvMK4.png" alt="ARP packet diagram" width="688" height="811"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Building a Layer on Top of ARP
&lt;/h2&gt;

&lt;p&gt;Now that we can send stuff to other devices on the network, how do we make something useful? The first limitation is that the Protocol Address Length has to fit in one byte. Since the largest number that can fit in a byte is 255, this restricts the length of our messages.&lt;/p&gt;

&lt;p&gt;Any grade-schooler would know that creating a rudimentary transport protocol on top of ARP is the necessary next step, so that's exactly what I did!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z4tICJQE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://doggo.ninja/o3EuXa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z4tICJQE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://doggo.ninja/o3EuXa.png" alt="Me, insane" width="369" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  "Protocol" &amp;amp; Chunking
&lt;/h3&gt;

&lt;p&gt;Every packet we send over ARP first consists of a prefix— in ArpChat, this is &lt;code&gt;uwu&lt;/code&gt;. This is convenient for ArpChat receivers, as they can cheaply discard ARP data that doesn't start with this prefix.&lt;/p&gt;

&lt;p&gt;Next, we'll include three bytes: a tag, a sequence number, and a total count. The tag identifies the kind of data; in a chat app, this could be a text message or a status update.&lt;/p&gt;

&lt;p&gt;To enable sending messages longer than 255 bytes, we can split them up into smaller chunks. The count field specifies the total number of chunks, and the sequence contains the position of one chunk within the total number of chunks. Receivers can use these two fields to reconstruct a full message from its separately transmitted parts.&lt;/p&gt;

&lt;p&gt;Right before passing the chunk data, we include a unique identifier that varies between each message. The first of two purposes is for deduplication: we ignore a packet if it's received twice by maintaining a &lt;a href="https://en.wikipedia.org/wiki/Circular_buffer#Overview"&gt;ringbuffer&lt;/a&gt; of recently received identifiers. The second purpose is to provide a simple key for identifying message chunks as part of a group.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N_Dd3c25--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://doggo.ninja/rpG07u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N_Dd3c25--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://doggo.ninja/rpG07u.png" alt="ArpChat packet diagram" width="688" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Internet Fame™
&lt;/h3&gt;

&lt;p&gt;With a bit more Rust code, I created a nice abstraction over this system that automatically chunks messages and deduplicates and gathers them on the receiving side.&lt;/p&gt;

&lt;p&gt;Using &lt;a href="https://crates.io/crates/cursive"&gt;Cursive&lt;/a&gt;, I built a terminal user interface and implemented a small chat app over ARP. On the second day that I was sick, I did some polishing and implemented a presence system for requesting who's online and gratuitously broadcasting when you connect or disconnect. This is, in an ironic fashion, close to ARP itself— one could run ARP &lt;em&gt;on top of ARP&lt;/em&gt; for some true ARPception!&lt;/p&gt;

&lt;p&gt;The internet somehow found ArpChat's GitHub repository and it gained some popularity, reaching the top 6 on GitHub Trending with 300 stars in one day! I never expected that a tiny project I made while I was sick would garner so much attention, but here we are. With the exposure that comes from 1.1k new GitHub stars, I even ended up making a couple of new friends.&lt;/p&gt;

&lt;p&gt;I'm basically done with this project, but you may &lt;a href="https://github.com/kognise/arpchat/releases/latest"&gt;try out the latest release&lt;/a&gt; if you feel so inclined.&lt;/p&gt;

&lt;h2&gt;
  
  
  Security with ARP, IPv6, and NDP
&lt;/h2&gt;

&lt;p&gt;As you might've noticed, ARP feels a bit flimsy. Any device can claim association with a certain IP address and everyone else on the network will believe them. When done maliciously, this is well-known in the security world as an &lt;a href="https://en.wikipedia.org/wiki/ARP_spoofing"&gt;ARP spoofing&lt;/a&gt; attack. The potential for danger is partially shown by how trivial running ArpChat is!&lt;/p&gt;

&lt;p&gt;Meanwhile, the number of devices on the public internet continues to increase as we grow closer and closer to reaching the limit of used IP addresses— there are only so many possible combinations.&lt;/p&gt;

&lt;p&gt;The answer to these and other problems is IPv6, a new version of IP with longer addresses, more sophisticated routing, and more modern protocols than IPv4. IPv6 also replaces ARP with a new protocol. &lt;a href="https://en.wikipedia.org/wiki/Neighbor_Discovery_Protocol"&gt;NDP&lt;/a&gt;, which stands for neighbor discovery protocol, features security-conscious features such as cryptographic message verification, rendering it much better than ARP.&lt;/p&gt;

&lt;p&gt;While the world gradually migrates to IPv6 and NDP, ARP is here to stay for years to come. ArpChat and ARP spoofing attacks are staying as well. Maybe an unseen benefit of IPv4 is that you can text your friends or coworkers on even a heavily restricted network! I await the day Verizon rolls out IPv6 to my home.&lt;/p&gt;

&lt;h2&gt;
  
  
  Technicalities
&lt;/h2&gt;

&lt;p&gt;I simplified a couple of things for the sake of practicality. I believe in accuracy as well, so I'd like to provide some small clarifications. You can also click on linked words throughout the article for in-depth information on the technology I've brought up.&lt;/p&gt;

&lt;p&gt;Saying that MAC addresses don't change was a bit of a white lie. Your computer can simulate ("spoof")  a different address, and modern operating systems such as macOS are introducing features to randomize your MAC address every time you connect to a new network. These features can help prevent fingerprinting but don't practically change how ARP and the rest of the networking stack works.&lt;/p&gt;

&lt;p&gt;I mentioned specifying IPv4 as the Protocol Type for our ARP packets. It turns out that IANA &lt;a href="https://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml"&gt;designates&lt;/a&gt; two alternate types for "experimental" use, which ArpChat now defaults to for the sake of being nicer to other networking equipment. IPv4 is still a configurable option.&lt;/p&gt;

&lt;p&gt;I also described ARP as a layer 3 protocol. There's some contention on this— while I think this is the most accurate and easiest explanation, networking is more nuanced than the OSI model might convey. Some would describe ARP as a level 2 or even level 2.5 protocol. For our purposes, I believe calling it level 3 makes the most sense.&lt;/p&gt;

&lt;p&gt;Two minor self-nitpicks: I claimed you're using HTTP on top of TCP to access this website. If your browser (and my server) supports HTTP/3, you might be using QUIC over UDP instead! I also left out a field of the ethernet packet containing a &lt;a href="https://en.wikipedia.org/wiki/Checksum"&gt;checksum&lt;/a&gt;. The networking library I used autogenerates this, and I don't think it's important in an explanation of ARP.&lt;/p&gt;

&lt;p&gt;Feel free to &lt;a href="//mailto:hi@kognise.dev"&gt;email hi@kognise.dev&lt;/a&gt; with any questions or corrections, and you're welcome to &lt;a href="https://github.com/kognise/arpchat/blob/main/src/net.rs"&gt;check out ArpChat's Rust networking code&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nvLQ614_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://doggo.ninja/fH9GKt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nvLQ614_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://doggo.ninja/fH9GKt.png" alt="ArpChat's banner image, drawn in a cartoonish style. In the center is large text saying ArpChat, and in the bottom right is text set in Comic Sans reading &amp;quot;routers love him!&amp;quot; In the top left is a scrawled ARP packet diagram." width="880" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rust</category>
      <category>security</category>
      <category>networking</category>
      <category>arp</category>
    </item>
    <item>
      <title>Rapidly find, prototype, and share new fonts with FontKey</title>
      <dc:creator>Kognise</dc:creator>
      <pubDate>Fri, 30 Aug 2019 13:03:20 +0000</pubDate>
      <link>https://forem.com/kognise/rapidly-find-prototype-and-share-new-fonts-with-fontkey-4d5d</link>
      <guid>https://forem.com/kognise/rapidly-find-prototype-and-share-new-fonts-with-fontkey-4d5d</guid>
      <description>&lt;p&gt;Hey all! I just launched &lt;a href="https://www.producthunt.com/posts/fontkey"&gt;FontKey on Product Hunt&lt;/a&gt;. It was my winning submission to a &lt;a href="https://repl.it/"&gt;Repl.it&lt;/a&gt; contest a few weeks ago, and can help you spice up your websites and designs with better fonts. &lt;/p&gt;

&lt;p&gt;Sites like &lt;a href="https://fonts.google.com/"&gt;Google Fonts&lt;/a&gt; make it harder than it needs to be to find quality fonts that aren't the most popular. Fonts like Roboto are all over the web, and I'm not saying they're an eyesore. But sometimes you want your site to be different or stick out. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simply press the space bar to cycle through new font styles&lt;/li&gt;
&lt;li&gt;Lock a font in place if you like it to see how it goes with other choices&lt;/li&gt;
&lt;li&gt;Change things like font weight and size easily&lt;/li&gt;
&lt;li&gt;Preview and prototype your selection in realistic website pages&lt;/li&gt;
&lt;li&gt;Get HTML and CSS to put on your website in a single click&lt;/li&gt;
&lt;li&gt;Share a link with friends, coworkers, and anyone else&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Anyways, I just wanted to share my work with the Dev.to community and &lt;strong&gt;I would love if you could &lt;a href="https://www.producthunt.com/posts/fontkey"&gt;go check it out&lt;/a&gt;&lt;/strong&gt;!&lt;/p&gt;

</description>
      <category>design</category>
      <category>webdev</category>
      <category>css</category>
    </item>
    <item>
      <title>Offline Survival Kit</title>
      <dc:creator>Kognise</dc:creator>
      <pubDate>Fri, 28 Jun 2019 00:21:03 +0000</pubDate>
      <link>https://forem.com/kognise/offline-survival-kit-3fpp</link>
      <guid>https://forem.com/kognise/offline-survival-kit-3fpp</guid>
      <description>&lt;p&gt;Tomorrow, I'm going offline for 5 weeks. I'll only have access to my laptop and no internet. It'll be very fun, but what kinds of things should I bring with me on my computer?&lt;/p&gt;

&lt;p&gt;So far...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Yarn with some cached packages&lt;/li&gt;
&lt;li&gt;Go and its offline documentation&lt;/li&gt;
&lt;li&gt;Every single XKCD comic&lt;/li&gt;
&lt;li&gt;Spotify music&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>discuss</category>
      <category>help</category>
    </item>
    <item>
      <title>API Documentation Tools</title>
      <dc:creator>Kognise</dc:creator>
      <pubDate>Wed, 12 Jun 2019 19:29:08 +0000</pubDate>
      <link>https://forem.com/kognise/api-documentation-tools-579o</link>
      <guid>https://forem.com/kognise/api-documentation-tools-579o</guid>
      <description>&lt;p&gt;I'm going to be writing documentation for an API. It spans across multiple subdomains and is a split between REST and GraphQL based. &lt;/p&gt;

&lt;p&gt;Do any of you have recommendations for a tool I could use to format, organize, and write this? Or is it best to just use markdown, and if so is there a good collection of guidelines door formatting?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>graphql</category>
      <category>writing</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
