Skip to content

feliposz/networking-practice-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

Network Utilities (CS:APP Chapter 11)

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.

Utilities & Concepts Explored

  • 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) using getaddrinfo.
  • 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.
  • Networking Library (mynetlib.c/h): A custom library providing wrappers for common socket functions and a buffered I/O reader.

Building

$ cd src
$ make clean
$ make

Usage Examples

dd2hex

./dd2hex 127.0.0.1
# Output: 0x7f000001

hex2dd

./hex2dd 0x7f000001
# Output: 127.0.0.1

hostinfo

./hostinfo google.com
./hostinfo -n 8.8.8.8

Echo Server & Client

Start 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 8000

Then type messages in the client terminal and press Enter. The server will echo them back.

Requirements

  • Developed and tested on Linux.
  • make utility.
  • gcc C compiler