Skip to content

POSIX Platform Examples

Niki Mardari edited this page Apr 2, 2026 · 5 revisions

Supported Systems

  • Linux
  • macOS
  • Other POSIX-compliant systems

Development Environment

These examples were developed on macOS and rely on standard POSIX APIs.

Tools useful for debugging:

  • nc
  • netcat
  • tcpdump

POSIX TCP Client Example (client.c):

Purpose

Demonstrates how to:

  • Create a TCP socket
  • Connect to a remote HTTP server
  • Send an HTTP/1.1 request
  • Receive and print the response

High-level Flow

  1. Convert IPv4 string to network address
  2. Create TCP socket
  3. Connect to remote server
  4. Send HTTP request
  5. Receive response
  6. Close socket

POSIX DNS Resolution Utility (get-ip.c):

Purpose

Command-line utility to resolve a hostname into IPv4 addresses using getaddrinfo()

Why this exists

  • Demonstrates modern DNS resolution
  • Shows linked-list iteration of addrinfo results
  • Introduces non-blocking connect with timeout

Concepts Demonstrated

  • getaddrinfo()
  • inet_ntop()
  • non-blocking sockets
  • poll()