From bbf130abe7345542540324615bc71add6b7a008b Mon Sep 17 00:00:00 2001 From: mrkmntal Date: Mon, 21 Sep 2026 09:29:16 -0400 Subject: [PATCH] v0.1.1 - Bug Fix, no longer showing local PIDs for remote target checks --- debian/changelog | 8 ++++++++ docs/hss_find_pids.md | 4 ++++ hss.c | 20 +++++++++++++++++--- hss.h | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 59aee1f..46c5329 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +hurd-socket-stat (0.1.1) unstable; urgency=low + + * Fix: skip process lookup for remote targets to avoid showing local PIDs + for remote ports. Use "n/a" placeholder instead. + * Add is_local_target() helper; guard getproc() and hss_find_pids(). + + -- Mark Robillard Jr Mon, 21 Sep 2026 09:00:00 +0000 + hurd-socket-stat (0.1) unstable; urgency=low * Initial release. diff --git a/docs/hss_find_pids.md b/docs/hss_find_pids.md index a1a1539..271a6ab 100644 --- a/docs/hss_find_pids.md +++ b/docs/hss_find_pids.md @@ -2,6 +2,10 @@ **Source:** `hss-proc.h:27` +> **Note:** This function only runs when the target is local (`localhost`, +> `127.0.0.1`, or one of the machine's own IPs). For remote targets, `hss` +> skips process lookup entirely and reports `users:(("n/a",pid=0))`. + Finds the process(es) that own a given listening port, using heuristic command-line matching against the Mach proc server. diff --git a/hss.c b/hss.c index cebbfa4..0b62acb 100755 --- a/hss.c +++ b/hss.c @@ -19,6 +19,13 @@ static void print_help(void) { "processes by inspecting the Mach proc server.\n", APP_NAME); } +static int is_local_target(const char *target, char (*ips)[INET_ADDRSTRLEN], int nips) { + if (!strcmp(target, "localhost") || !strcmp(target, "127.0.0.1")) return 1; + for (int i = 0; i < nips; i++) + if (!strcmp(target, ips[i])) return 1; + return 0; +} + int main(int argc, char *argv[]) { const char *target = (argc > 1) ? argv[1] : "localhost"; @@ -64,13 +71,17 @@ int main(int argc, char *argv[]) { /* getproc() returns a Mach port handle to the Hurd process server — a * userspace translator, not a kernel syscall. Used below to enumerate * every running process. */ - process_t proc_server = getproc(); + int local = is_local_target(target, eth_ips, num_eth_ips); + process_t proc_server = local ? getproc() : MACH_PORT_NULL; - if (proc_server == MACH_PORT_NULL) { + if (local && proc_server == MACH_PORT_NULL) { fprintf(stderr, "%s: Error fetching Hurd proc server port via getproc()\n", APP_NAME); return 1; } + if (!local) + fprintf(stderr, "%s: process lookup only available for local targets\n", APP_NAME); + printf("%-8s %-12s %-30s %s\n", "Netid", "State", "Local Address:Port", "Process"); /* For each candidate: attempt a non-blocking TCP connect. If it succeeds, @@ -85,7 +96,10 @@ int main(int argc, char *argv[]) { continue; } - hss_find_pids(proc_server, ports[i].port, proc_status, sizeof(proc_status), proc_limit); + if (local && proc_server != MACH_PORT_NULL) + hss_find_pids(proc_server, ports[i].port, proc_status, sizeof(proc_status), proc_limit); + else + snprintf(proc_status, sizeof(proc_status), "users:((\"n/a\",pid=0))"); printf("%-8s %-12s %-30s %s\n", "tcp", "LISTEN", local_addr, proc_status); } diff --git a/hss.h b/hss.h index 075ada7..8881f3b 100644 --- a/hss.h +++ b/hss.h @@ -2,7 +2,7 @@ #define HSS_H #define APP_NAME "hss" -#define APP_VERSION "0.1" +#define APP_VERSION "0.1.1" #include "hss-ports.h" #include "hss-probe.h"