nc package icon
icedcoffee/nc
Public
wasmer run icedcoffee/nc

nc — netcat for WASIX

The traditional netcat 1.10 (Debian's netcat-traditional), built for WASIX. TCP and UDP, connect and listen, with stdio shovelled through the socket.

wasmer run icedcoffee/nc -- example.com 80
printf 'GET / HTTP/1.0\r\nHost: example.com\r\n\r\n' | wasmer run icedcoffee/nc -- example.com 80
wasmer run icedcoffee/nc -- -l -p 9000

What is in the package

nc with -l listen, -p port, -u UDP, -v verbose, -n numeric only, -s source address, -p/-r port handling, -o hex-dump of traffic, -z zero-I/O mode, -w timeout, -i interval, and the port-range syntax (8080-8090).

Verified

$ printf 'GET / HTTP/1.0\r\nHost: example.com\r\n\r\n' | nc -w 5 example.com 80
HTTP/1.1 200 OK …              # 891 bytes: real response, headers and body
$ nc -h
[v1.10] connect to somewhere: nc [-options] hostname port[s] [ports] ...

Name resolution works (the runtime's DNS), and the socket is a real TCP connection — the response above came from the network.

Two platform notes

  • The module is asyncified. netcat longjmps out of its SIGALRM handler, and on WASIX longjmp is stack_checkpoint, which the runtime drives through the module's asyncify exports. Without instrumentation every run exits 45 before it prints anything.

  • -w and -z wait for a SIGALRM that never arrives, so those modes hang rather than timing out or exiting. A port check is better expressed with this package's neighbour:

    timeout 5 nc -z host 80 && echo open
    

    icedcoffee/timeout forks the child, so it stops the scan even though netcat's own timer never fires.

Building

One C file plus a three-line compat.c supplying res_init() (netcat calls it for its verbose banner; WASIX has no resolver API). Compiled directly:

clang --target=wasm32-wasi --sysroot=$SYSROOT ... netcat.c compat.c -o nc.wasm
wasm-opt --asyncify --enable-threads --enable-bulk-memory nc.wasm -o nc.wasm

169 KiB before asyncify, 470 KiB after. The K&R-era source needs -Wno-int-conversion -Wno-implicit-int -Wno-deprecated-non-prototype to build under a modern clang.

License: GPL-2.0-or-later, as upstream.

netcat (traditional, 1.10) for WASIX - TCP and UDP connect, listen, transfer


Github