Skip to content
Chethan Yadav
Work

Engineering/2024/Active

quickcmd

A simple command line tool to run commands quickly, made with C.

C

Overview

quickcmd is a tiny interactive shell written in C: it runs a read-eval loop that accepts one built-in command per line and executes a matching function. It's a small systems-programming exercise more than a production tool — the interesting part is that its two "real" commands are implemented twice, once against POSIX networking APIs and once against the Windows IP Helper API, selected at compile time with #ifdef _WIN32 guards.

Key Features

  • Interactive loop — prompts with Enter the Command: and reads input via scanf until you type exit
  • ipaddr — lists local network adapter names and IPv4 addresses; uses getifaddrs/inet_ntop on Linux/macOS and GetAdaptersInfo from the Windows IP Helper API (iphlpapi) on Windows
  • hostname — prints the machine's hostname via gethostname(), wrapped in WSAStartup/WSACleanup on Windows
  • help — lists the available commands
  • Cross-platform build — the same main.c / cmd_functions.c compile on both platforms; the Windows build links ws2_32 and iphlpapi

Installation

git clone https://github.com/chethanyadav456/quickcmd.git
cd quickcmd

A C compiler (GCC) is required. On Windows, the project's docs point to MinGW for GCC.

Build and run with the provided scripts, which compile with gcc and immediately launch the resulting binary:

# Linux / macOS
sh run.sh
 
# Windows
run.cmd

run.sh runs gcc -Wall -Wextra -g -o outputs/quickcmd main.c cmd_functions.c; run.cmd runs the Windows equivalent linking -liphlpapi -lws2_32.

Usage

Enter the Command: help
Available commands:
  ipaddr - Display the IP address
  help   - Show this help message
  hostname   - Display the hostname
  exit   - Exit the program

Any input that doesn't match a known command prints Invalid Command! Type "help" for more commands.

View on GitHub ↗