Skip to content

kaisarcode/netl.c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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/Flag Description
<name> <addr>[:port] <cmd> Register or replace a listener. TCP by default.
<name> <addr>[:port] --udp <cmd> Register a UDP listener.
<name> -d, <name> --delete Remove a listener if it exists.
<name> -l, <name> --list List one listener if it exists.
-l, --list List all listeners as name<TAB>addr:port.
<name> Start the registered listener.
-h, --help Show help and usage.
-v, --version Show 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

License

GPLv3

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

About

Network Listener

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors