v0.1.1 - Bug Fix, no longer showing local PIDs for remote target checks
This commit is contained in:
parent
70a2a6d5fd
commit
bbf130abe7
4 changed files with 30 additions and 4 deletions
8
debian/changelog
vendored
8
debian/changelog
vendored
|
|
@ -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 <marky611@gmail.com> Mon, 21 Sep 2026 09:00:00 +0000
|
||||
|
||||
hurd-socket-stat (0.1) unstable; urgency=low
|
||||
|
||||
* Initial release.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
20
hss.c
20
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
2
hss.h
2
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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue