A C networking suite featuring a unified LIFX Smart Bulb Controller (UDP Client) and a secure, compliance-hardened HTTP/0.9 File Server (TCP Server).
Built using standard C and the Berkeley Sockets API, this project demonstrates network protocol implementation, packet structuring, UDP reliability mechanisms (timeouts and retries), and basic TCP server security.
A command-line tool designed to discover, query, and modify the state of LIFX smart bulbs on a local area network using the custom LIFX UDP protocol.
- Status Query: Retrieve bulb labels, locations, and color states (Hue, Saturation, Brightness).
-
Color Configuration: Directly update bulb states with custom HSB (Hue, Saturation, Brightness) values, standardizing color scales (e.g., Hue from
0-360, and Saturation/Brightness from0.0-1.0). -
Brightness Inversion: Automatically fetch the current state, invert the brightness value (
$1.0 - \text{current}$ ), and update the bulb. -
Reliable Networking: Implements low-level UDP retry-loops with custom timeouts (
SO_RCVTIMEO) and packet validation to handle potential UDP packet drops.
A lightweight TCP file server that listens on port 8080 and implements the subset of the HTTP/0.9 protocol.
- Continuous Listening: Listens on all interfaces and processes successive client connections continuously.
- Resource Streaming: Streams any local text files requested via
GET /filename. - Formatting Restraints: Automatically restricts line length to a maximum of 80 characters and terminates all lines with standard
CRLF(\r\n). - Security Hardening: Sanitizes filenames and guards against path traversal attacks (preventing the use of
..or access to parent directories). - Socket Options: Configured with
SO_REUSEADDRto prevent socket bind errors during rapid restarts.
The project includes a platform-aware Makefile that compiles the binaries for both Linux/macOS and Windows environments.
To compile both targets, run:
makeThis will create the bin/ directory and compile the executables:
bin/lifx_controlbin/http_server
To clean up build artifacts and binaries:
make cleanThe controller expects a command, the bulb's IP address, and any optional configuration parameters.
./bin/lifx_control query <IP_ADDRESS>Output Example:
Name: Living Room Bulb
Location: Hallway
Hue: 120
Saturation: 0.75
Brightness: 0.60
Set the bulb to a specific Hue (0-360), Saturation (0.0-1.0), and Brightness (0.0-1.0):
./bin/lifx_control set <IP_ADDRESS> 180 0.8 0.5Query the current brightness level, invert it, and apply it back:
./bin/lifx_control invert <IP_ADDRESS>Output Example:
Hue: 120
Saturation: 0.75
Brightness: 0.60
Setting brightness to 0.40
To launch the file server:
./bin/http_serverOnce running, you can connect to the server on port 8080 from another terminal session.
nc -C localhost 8080
GET /README.mdcurl -0 http://localhost:8080/README.md- LIFX UDP Protocol: Packets are built by packing the custom
lx_protocol_header_tstructure. Big/little-endian conversions are mapped correctly to match the protocol specification. The client requests ACK frames (ack_required = 1) or State frames (res_required = 1) based on the operation. - HTTP/0.9 Subset: Simple single-line requests
GET /pathterminated by\r\n. Responses return raw file contents without HTTP headers, and the connection is closed by the server immediately after transmission.