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
Prints:
Network_IDBroadcast_ID
Prints:
IP_first(first usable)IP_last(last usable)Nr_Hostesh(usable hosts)
Generates subnets and prints for each subnet:
Subnet_IDBroadcast_IDIP_firstIP_lastNr_Hostesh
- IPv4 → binary conversion
- IPv4 address type (private/public/loopback/multicast/broadcast/reserved)
- Subnet membership check
- Batch processing from file
- Complete network information display
✅ 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
make
./ipv4_calcRequirements:
gccand standard build tools (no NASM needed).
make cleanThe program is interactive by default. You can input:
- IPv4 address:
192.168.1.10 - Subnet mask:
255.255.255.0or CIDR:/24
./ipv4_calcYou 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 /24Process multiple commands from a file:
# Run batch commands from file
./ipv4_calc -f examples/batch_commands.txtExample 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
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 conditionsMIT (feel free to change).