A few days/weeks ago I came across Arp-Chat. After a quick overview, I found the concept intriguing and felt compelled to explore it firsthand. The challenge, however, lay in my limited experience with low-level network layers. Despite this, I viewed it as an opportunity to delve deeper into this fundamental aspect of computer science. While my university studies touched on the topic briefly, the exploration was not in-depth. This is likely because, in practical scenarios, many languages and libraries handle these low-level intricacies. Nevertheless, I embraced the chance to expand my understanding of network layers and enhance my skills in this essential domain.
Sooooo what is the goal? The goal is to create something similar to arp chat probably not as good but the focus is on learning. I want to be able to chat in a local network with others (Also need to find friends for that... probably I will be alone with two laptops...)
How I will try to archive that
The Respository Currently I added some basic way to capture ARP packages and added a lot of comments for myself. Over the Christmas holiday I will try to work on that.
First I need to understand what and wh ARP is used. Also I need some orientation to know in which layer we are when I read about ARP (I said I know 0 about this). The Address Resolution Protocol (ARP) serves as a critical component in networking, acting as a dynamic mapping tool to associate IP addresses with corresponding MAC addresses. This process becomes essential when a packet arrives from Layer 1, carrying only the IP address of its destination. Without knowledge of the specific MAC address, locating the target machine within the local network becomes a challenge. It's important to note that ARP operates exclusively within a network, facilitating communication within the confines of that network.
In practical terms, when a packet enters the network, the gateway leverages ARP to determine the MAC address associated with a given IP address. For instance, the gateway may discover that IP Address xxx.xxx.xxx.xxx corresponds to MAC address xx:xx:xx:xx:xx:xx. This correlation ensures the correct routing of packets within the subnet.
ARP's functionality spans both Layer 2 (Data Link Layer) and Layer 3 (Network Layer). At Layer 2, ARP plays a crucial role in resolving IP addresses to MAC addresses, enabling the creation of Ethernet frames for local communication. Simultaneously, at Layer 3, ARP contributes to the accurate routing of IP packets within the network. In essence, ARP acts as a bridge between these two layers, facilitating seamless communication in local networks.
The little project is using libnet and pcap as dependencies.
The rough structure of the project consists of three parts. We have one part which is responsible to capture arp packages and check if it is supposed to be for our chat. The Second part is responsible to send chat messages which should be received by others. And the third part is the tui (hardest part) it should be as simple as possibl because I am a noob. It should show a chat history of prevoisly send messages and also give the possibility to write a message and after the user hits Enter it sends it.
So how does the current protocol look for our chat. In the Packet Structure of ARP we will abuse some fields.
It is okay to put our message data into those fields because we are sending Gratuitous Arp packets, those kind of packets are sent usually when a new computer enters the network and broadcasts to announce itself to net network and to update IP to MAC mappings
We have also to take care regarding the size of the message because based on the message size we have to set the Target Hardware Address (THA).
We have to add a system to check for replicated messages. Add a system to see usernames. Add a system to signal if users leave the chat or enter the chat Add a system to be sure everything arrives in the right sequence The sequence will be important because at the moment we can only send messages with a max length of 255 chars because Protocol Address Length (PLEN) is a unsigned char
Today I have roughly finished the SandChat, it is possible to set a username for the chat and additionally the chat shows the history (Would be uncool if not). I have only tested the program with one user (me) because currently i have no access to a seperate computer also this is only tested on mac, but it should work on linux too.
Working on refactoring.
I need to extend the chat protcol. I need to add to possibility to extend the message size currently it is restricted to 255 chars because of the unsigned char for the Protocol length(PLEN). I need also to add for that a sequence system, if the user sends longer messages they have to arrive in a correct order in the chat. Currently i have only a prefix of length 6 to check if its a regular message or if a new user has arrived in the chat and it has to be added to the current users to display the name of the user when he sends a message.
The code is a real mess, its full of global variables and loads of code duplications. It is a shame but my main goal is to just finish it and get honestly initially it was just to learn about the layers. I need to get a nice structure in the code.
The tui is very basic first you have to pick a username and then you can start to chat, if the user wants to exit the chat he has to send a interrupt. I want to add some commands to the chat like /help to show what you can do, it should at least have the posibility to quit the program and to change the username.
Some visuals:
Setting username:
Chat preview:
Chat history:
It would be nice if it is possible to send direct messages to specific users instead of broadcasting it to all users in the chat. Also it would be nice to have a functionality to identify when a user leaves the chat. Similar to when a user leaves the chat.