Skip to content

IPv4 Subnet Calculator built with C and x86-64 Assembly, demonstrating low-level TCP/IP subnetting and systems programming principles.

License

Notifications You must be signed in to change notification settings

orgito1015/ipv4-subnet-calculator-c-asm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IPv4 Subnet Calculator (C + Assembly)

A practical IPv4 subnet calculator for TCP/IP v4 addressing exercises.

This project uses a hybrid approach:

  • C: parsing IPv4 / subnet masks, validation, menu UI, printing.
  • x86-64 Assembly (GAS via GCC): core bitwise math for:
    • Network ID
    • Broadcast ID
    • First/Last usable host
    • Usable host count

Features (Assignment Coverage)

A) Given IP + Subnet Mask

Prints:

  • Network_ID
  • Broadcast_ID

B) Given Network_ID + Subnet Mask

Prints:

  • IP_first (first usable)
  • IP_last (last usable)
  • Nr_Hostesh (usable hosts)

C) Given Network_ID + Subnet Mask + number of subnets

Generates subnets and prints for each subnet:

  • Subnet_ID
  • Broadcast_ID
  • IP_first
  • IP_last
  • Nr_Hostesh

D) Extras

  • IPv4 → binary conversion
  • IPv4 address type (private/public/loopback/multicast/broadcast/reserved)
  • Subnet membership check
  • Batch processing from file
  • Complete network information display

Features Overview

Core Subnet Calculations

  • Network ID and Broadcast ID calculation
  • First/Last usable host determination
  • Usable host count
  • Subnet generation

Input Flexibility

  • Dotted decimal notation (255.255.255.0)
  • CIDR notation (/24)
  • Interactive and command-line modes
  • Batch processing from file

Utility Features

  • Binary representation of IPv4
  • IP address classification
  • Network membership checking
  • Comprehensive network info display

Quality Assurance

  • Comprehensive test suite
  • Assembly-optimized calculations
  • Input validation
  • Error handling

Build

Linux (recommended)

make
./ipv4_calc

Requirements: gcc and standard build tools (no NASM needed).

Clean

make clean

Usage

Interactive Mode

The program is interactive by default. You can input:

  • IPv4 address: 192.168.1.10
  • Subnet mask: 255.255.255.0 or CIDR: /24
./ipv4_calc

Command-Line Mode

You can also use the calculator in non-interactive mode:

# Show help
./ipv4_calc --help

# Task A: Calculate Network and Broadcast IDs
./ipv4_calc -a 192.168.1.10 /24

# Task B: Calculate host range and count
./ipv4_calc -b 192.168.1.0 255.255.255.0

# Task C: Generate subnets
./ipv4_calc -c 192.168.1.0 /24 4

# Convert IP to binary
./ipv4_calc -bin 192.168.1.1

# Show IP address type
./ipv4_calc -type 10.0.0.1

# Check if IP belongs to network
./ipv4_calc -check 192.168.1.50 192.168.1.0 /24

# Show complete network information
./ipv4_calc -info 192.168.1.0 /24

Batch Processing Mode

Process multiple commands from a file:

# Run batch commands from file
./ipv4_calc -f examples/batch_commands.txt

Example batch file format:

# Comments start with #
TYPE 10.0.0.1
BINARY 192.168.1.1
TASK_A 192.168.1.10 /24
TASK_B 192.168.1.0 /24
TASK_C 192.168.1.0 /24 4

Testing

The project includes a comprehensive test suite:

# Run all tests
make test

# Tests cover:
# - IPv4 address parsing
# - Subnet mask validation
# - Assembly function correctness
# - Edge cases and boundary conditions

Medium article (by Orgito)


License

MIT (feel free to change).

About

IPv4 Subnet Calculator built with C and x86-64 Assembly, demonstrating low-level TCP/IP subnetting and systems programming principles.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 2

  •  
  •