How libvnc/x11vnc works
Project type and purpose
• This is x11vnc, a native C-based VNC server that allows remote control of an existing X11 display.
• It provides screen capture (via Xlib/XDamage/Xrandr), input injection (via uinput or XTest), optional SSL/TLS support, mDNS/Avahi discovery, and a minimal local “console” GUI.
File structure
• Top level:
• src/ – core C modules for screen capture, encoding, network, input, SSL, X11-specific backends (macOS, Linux framebuffer)
• misc/ – assorted helper scripts, sample client wrappers, alternate viewers (Enhanced TightVNC viewer for Windows/macOS)
• doc/ – FAQ, options, SSL portal guide, Sunray and other protocol notes
• configure.ac, Makefile.am, autogen.sh – autotools build
• Key modules in src/:
• x11vnc.c (main loop, RFB protocol)
• xdamage.c, xrandr.c, xinerama.c (incremental update detection)
• sslhelper.c, sslcmds.c (TLS handshake and encryption)
• connections.c (manage client sockets)
• userinput.c, uinput.c (keyboard/mouse injection)
• avahi.c (mDNS service advertisement)
• gui.c (local curses or simple ASCII console UI)
(minimal) README and docs
• Although the top-level README is a placeholder, the doc/ directory and man page (x11vnc.1) describe architecture: capture → encode → transmit → input injection.
Components
a. Main components:
1. Client Viewer(s) (e.g. standard VNC viewer or Enhanced TightVNC viewer)
2. Network Stack (TCP sockets, optional SSL/TLS layer)
3. x11vnc Core Server
– X11 Interface (Xlib, XDamage, Xrandr, Xinerama)
– Framebuffer Capture Engine
– RFB Encoder (raw, tight, hextile, turbojpeg)
– Connection Manager
– Input Injection Handler (uinput or XTest)
– Configuration/UI Module (gui.c)
4. Dependencies / Extensions
– Avahi/mDNS Discovery
– SSL/TLS library (OpenSSL)
– Operating-system backends (Linux framebuffer, macOS CG)
b. Relationships and interactions:
– Viewer ↔ Network Stack: RFB handshake, pixel data, input events
– Network Stack ↔ SSL Module (optional): encapsulate RFB in TLS
– Server Core ↔ X11 Interface: capture screen updates, monitor damage events
– Server Core ↔ Encoder: compress and packetize raw pixels
– Server Core ↔ Connection Manager: spawn per-client thread, track state
– Server Core ↔ Input Injection: receive events, post to X server or uinput driver
– Server Core ↔ Avahi: publish & remove mDNS service on startup/exit
c. Architectural patterns / design principles:
– Modular C code with clear separation: capture, encode, network, UI, input
– Plugin-style backends for different OS and features (SSL, Avahi, Linux FB)
– Event-driven loop with multi-threaded or multiplexed I/O for multiple clients
d. Key technologies / libraries:
– Xlib, XDamage, Xrandr, Xinerama, XTest
– libavahi-client (mDNS)
– OpenSSL (optional)
– Linux uinput (/dev/uinput)
– pthreads or select()/poll() for concurrency
– autotools for build/configuration