Skip to content

About

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).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

C Socket Networking Suite

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.


Key Features

1. LIFX Smart Bulb Controller CLI (lifx_control)

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 from 0.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.

2. HTTP/0.9 File Server (http_server)

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_REUSEADDR to prevent socket bind errors during rapid restarts.

Building the Project

The project includes a platform-aware Makefile that compiles the binaries for both Linux/macOS and Windows environments.

To compile both targets, run:

make

This will create the bin/ directory and compile the executables:

  • bin/lifx_control
  • bin/http_server

To clean up build artifacts and binaries:

make clean

Usage

1. Controlling LIFX Bulbs

The controller expects a command, the bulb's IP address, and any optional configuration parameters.

Query Bulb Status

./bin/lifx_control query <IP_ADDRESS>

Output Example:

Name: Living Room Bulb
Location: Hallway
Hue: 120
Saturation: 0.75
Brightness: 0.60

Set Bulb Color

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.5

Invert Bulb Brightness

Query 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

2. HTTP/0.9 File Server

To launch the file server:

./bin/http_server

Once running, you can connect to the server on port 8080 from another terminal session.

Testing with netcat (nc):

nc -C localhost 8080
GET /README.md

Testing with curl:

curl -0 http://localhost:8080/README.md

Protocol Specifications Implemented

  • LIFX UDP Protocol: Packets are built by packing the custom lx_protocol_header_t structure. 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 /path terminated by \r\n. Responses return raw file contents without HTTP headers, and the connection is closed by the server immediately after transmission.

About

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).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages