It just sends an ARP request.
- the method for sending data is specified on net.c@send_packet, it goes like this
- Opens a socket with socket():
-Domain: PF_PACKET
-Type: SOCK_RAW
-Proto: ETH_P_ALL
- Creates an address struct (sockaddr_ll) to specify our interface:
-sll_family: AF_PACKET
-sll_ifindex: (the index of our network interface calculated at net.c@get_if_info)
-sll_protocol: ETH_P_ALL
- Binds the socket to the network card with bind():
-Socket: sockfd
-Address: sll
-Addrlen: sizeof(sll)
- Writes data to the socket with write():
-Descriptor: sockfd
-Data: payload to send
-Length: len of payload
s = socket()
sockaddr_ll sll
sll. [] = stuff
bind(s, sll, sizeof(sll))
write(s, payload, len)
close(s)
ARP packets are handcrafted in arp.c
ETH frames are also handcrafted in ether.c CRC calculations were boring so i stole the code from somewhere i cannot recall crc.c
- Edit the call to rawrp in main.c with your interface name and the ip to request MAC for.
- save changes and compile with gcc *.c
- execute with ./a.out
- Improve the ether interface to fit arp model (we create the header and then we calculate the packet from it)
- Implement Ethernet fragmentation
- Improve file structure (probably a folder per OSI layer) and create a makefile
- Expand functionality, maybe start building layer 3?