Skip to content

Software implementation of an IPv4 router in C, featuring packet forwarding, ARP handling, and ICMP error messaging using binary search and merge-sorted routing tables

Notifications You must be signed in to change notification settings

marinaa13/ipv4-router-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IPv4 Router in C

A simplified software implementation of an IPv4 router in C, capable of forwarding IP packets, handling ARP requests/replies, and sending ICMP error messages.
The project simulates the essential mechanisms of network routing and packet processing at the data link and network layers.


Overview

This router operates as an intermediary node in a local network, processing Ethernet frames, managing routing and ARP tables, and generating ICMP messages for error handling.
It models real-world routing behavior, including checksum validation, TTL management, and forwarding logic.

Language: C
Focus: Low-level networking, ARP and ICMP protocols, routing tables, binary search optimization


Features

Core Functionality

  • Packet processing loop
    • Receives and parses Ethernet frames
    • Handles IP and ARP packets separately
  • Routing
    • Reads and sorts routing tables using merge sort
    • Implements binary search to find the best route match
    • Decrements TTL and recomputes IP checksums before forwarding
  • ARP Table
    • Parses entries from arp_table.txt
    • Looks up MAC addresses for next hops
    • Adds new entries dynamically upon receiving ARP replies
  • ICMP Handling
    • Sends ICMP Echo Reply, Time Exceeded, and Destination Unreachable packets
    • Automatically swaps headers and recomputes checksums
  • Error Checking
    • Verifies Ethernet frame length and IP checksum validity
    • Ignores packets not addressed to the router or broadcast

Protocol Support

  • Ethernet II (MAC addressing, Ethertype filtering)
  • IPv4 (header parsing, TTL, checksum)
  • ARP (request/reply handling and caching)
  • ICMP (echo, unreachable, time exceeded)

Learning Outcomes

  • Implemented layer-2 and layer-3 networking logic from scratch
  • Gained practical understanding of ARP resolution, ICMP messaging, and routing
  • Applied checksum computation, TTL management, and packet encapsulation
  • Practiced binary search and merge sort optimizations for routing performance

About

Software implementation of an IPv4 router in C, featuring packet forwarding, ARP handling, and ICMP error messaging using binary search and merge-sorted routing tables

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published