This repository serves as a collection of small networking utilities implemented in C, primarily as an exercise to understand and apply concepts from Chapter 11: Network Programming of Computer Systems: A Programmer's Perspective (CS:APP).
It's a study-focused project for exploring various network programming paradigms.
dd2hex/hex2dd: Utilities to convert between dotted-decimal IP addresses and their hexadecimal representations.hostinfo: A simple tool to retrieve host information (IP addresses, canonical names) usinggetaddrinfo.- Echo Client (
myechoclient.c): A basic TCP client that sends messages typed by the user to an echo server and prints the server's response.evilclient.c: A modified echo client used for testing the robustness of servers by sending partial messages (without newlines).
- Echo Servers: Various implementations demonstrating different concurrency models:
- Iterative (
myechoserver.c): Handles one client at a time. - Process-based (
myechoserver_fork.c): Spawns a new process (fork()) for each client. - Thread-based (
myechoserver_pthread.c): Spawns a new POSIX thread (pthread_create()) for each client. - Event-driven (
myechoserver_select.c): Uses I/O multiplexing (select()) to handle multiple clients concurrently in a single process. - Worker Pool (
myechoserver_workers.c): Employs a fixed number of worker threads and a queue (mysemqueue.c/h) to distribute client connections.
- Iterative (
- Networking Library (
mynetlib.c/h): A custom library providing wrappers for common socket functions and a buffered I/O reader.
$ cd src
$ make clean
$ make
./dd2hex 127.0.0.1
# Output: 0x7f000001./hex2dd 0x7f000001
# Output: 127.0.0.1./hostinfo google.com
./hostinfo -n 8.8.8.8Start any echo server (e.g., iterative, fork, pthread, select, workers) on a chosen port.
# In one terminal, run a server (e.g., iterative)
./myechoserver 8000
# In another terminal, run the client
./myechoclient localhost 8000Then type messages in the client terminal and press Enter. The server will echo them back.
- Developed and tested on Linux.
makeutility.gccC compiler