psockets: Projects with the POSIX Sockets API

A collection of small C networking tools built on POSIX sockets.

Posted by Jaime Arrocha on Tuesday, November 3, 2026

Intro

psockets is a collection of small networking tools I wrote in C while learning the POSIX Sockets API. I still reach for several of them during day-to-day debugging. Each tool sits in its own directory and compiles on any Linux machine with gcc. They're learning projects first: the core functionality works, but expect rough edges.

What's inside

  • pscan: a TCP port scanner. It tries the three-way handshake (connect()) against a port range and reports which ports accept the connection.
  • psniff: a packet sniffer built on raw sockets. It captures frames off the wire and decodes the Ethernet, IP and TCP/UDP headers. The internals are covered in Coding Your Own Network Sniffer.
  • tcp_server: a minimal TCP server you can talk to with telnet. It's a good starting point for the socket() → bind() → listen() → accept() sequence; see TCP Sockets Server.
  • get_http: fetches a web page over raw sockets, with DNS resolution and support for both IPv4 and IPv6. See Capturing Websites With Sockets and HTTP.
  • host_resolver: a small helper that resolves hostnames to addresses with getaddrinfo().

A related multi-threaded web server project is covered in Implementing a Prethreaded Web Server.

Why bother?

Tools like nmap, tcpdump and curl already do all of this, and do it better. Writing your own versions is still one of the fastest ways to understand what sits beneath them: byte ordering, struct sockaddr casting, blocking versus non-blocking I/O, and how the kernel hands packets to user space. If you're starting with network programming, clone the repository, read a tool's source end to end, then change it.

git clone https://github.com/jarrocha/psockets.git
cd psockets/tcp_server
make

Source: github.com/jarrocha/psockets