KaisarCode

netl.c

netl.c - Network Listener

netl.c is a small C library and CLI for registering named TCP or UDP listeners that dispatch each incoming connection or datagram to a shell command.


CLI

Examples

Register a TCP listener on port 8080:

netl proxy 127.0.0.1:8080 cat

Start the registered listener:

netl proxy

List all registrations:

netl --list

List one registration:

netl proxy --list

Remove a registration:

netl proxy --delete

Parameters

Command/FlagDescription
<name> <addr>[:port] <cmd>Register or replace a listener. TCP by default.
<name> <addr>[:port] --udp <cmd>Register a UDP listener.
<name> -d, <name> --deleteRemove a listener if it exists.
<name> -l, <name> --listList one listener if it exists.
-l, --listList all listeners as name<TAB>addr:port.
<name>Start the registered listener.
-h, --helpShow help and usage.
-v, --versionShow version.

Public API

#include "netl.h"

kc_netl_t *ctx = kc_netl_open();

kc_netl_update(ctx, "proxy", "127.0.0.1", 8080, KC_NETL_TCP, "cat");
kc_netl_list(ctx, "proxy");
kc_netl_exec(ctx, "proxy");
kc_netl_delete(ctx, "proxy");

kc_netl_close(ctx);

Lifecycle

  • kc_netl_open() - resolves metadata state and returns a context owned by the caller.
  • kc_netl_update() - registers or replaces a named listener.
  • kc_netl_exec() - starts the registered listener. Blocking on success, never returns.
  • kc_netl_list() - lists all registrations or one named registration.
  • kc_netl_delete() - removes a named registration.
  • kc_netl_path() - returns the resolved metadata directory for diagnostics.
  • kc_netl_close() - releases the context.

Notes

  • kc_netl_exec is blocking. The caller is responsible for forking if background operation is needed.
  • kc_netl_update does not require elevated privileges.
  • Registration metadata is stored under ~/.local/share/netl/ on Linux and %APPDATA%\netl\ on Windows.

Build

Compiled artifacts are generated under bin/{arch}/{platform}/ for the host architecture running the build.

make clean && make

Multiarch Builds

The project is prepared to build artifacts for multiple architectures under bin/{arch}/{platform}/. A plain make builds only the current host architecture, while the targets below build the full matrix or a specific target.

make all
make x86_64/linux
make x86_64/windows
make i686/linux
make i686/windows
make aarch64/linux
make aarch64/android
make armv7/linux
make armv7/android
make armv7hf/linux
make riscv64/linux
make powerpc64le/linux
make mips/linux
make mipsel/linux
make mips64el/linux
make s390x/linux
make loongarch64/linux

Beta Notice

This is a beta project tested only on Debian x86_64. It was created out of a personal need for these libraries, but no guarantees are provided regarding its stability or future support. You are free to test it, use it, and modify it as you please.

If you'd like to reach out, you can send an email to [email protected]. Please note that I do not accept pull requests; the goal is to avoid long-term dependency on platforms like GitHub, and I do not maintain fixed infrastructure to guarantee long-term stability for these projects.


Repo

You can download the repository and read the most up-to-date documentation directly from its official source.

GitHub: kaisarcode/netl.c

License

GPLv3

This project is distributed under the GNU General Public License version 3 (GPLv3).